<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
Der Maven Build sollte immer noch funktionieren.<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>>
<java.version>11</java.version>
</properties>
Der Maven Build sollte immer noch funktionieren.<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
Die Unit Tests ergeben einen Kompiliationsfehler.Öffnen Sie die Test Datei JumpstartApplicationJpaTests.java und entfernen Sie die fehlerhaften import Statements.Entfernen Sie die @RunWith(SpringRunner.class) Annotationen.Importieren Sie die Annotation @Test und die assert Anweisungen neu mit den Jupiter Klassen:
package ch.std.jumpstart;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import ch.std.jumpstart.dto.CityDTO;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class JumpstartApplicationJpaTests {
...
}
Öffnen Sie die Test Datei JumpstartApplicationTests.java und korrigieren Sie die Fehler wie folgt:
package ch.std.jumpstart;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import ch.std.jumpstart.rest.CityAutoCompleteController;
@ExtendWith(SpringExtension.class)
@WebMvcTest(CityAutoCompleteController.class)
@ActiveProfiles("test")
public class JumpstartApplicationTests {
@Autowired
private MockMvc mvc;
@Test
public void contextLoads() {
}
@Test
public void testCityAutoCompleteController() throws Exception {
MvcResult mvcResult = mvc.perform(get("/rest/auto/cities?value=Bern").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();
String expected = "[Bern]";
String actual = mvcResult.getResponse().getContentAsString();
JSONAssert.assertEquals(expected, actual, false);
}
}
Der Maven Build sollte wieder funktionieren und die Migration ist abgeschlossen.Die migrierte Anwendung finden Sie hier migriert.zip