formatting work
This commit is contained in:
+69
-79
@@ -23,10 +23,9 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
server = new FunctionalWebApplication().start();
|
||||
client = WebTestClient
|
||||
.bindToServer()
|
||||
.baseUrl("http://localhost:" + server.getPort())
|
||||
.build();
|
||||
client = WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + server.getPort())
|
||||
.build();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -36,26 +35,24 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenRouter_whenGetTest_thenGotHelloWorld() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/test")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
client.get()
|
||||
.uri("/test")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenIndexFilter_whenRequestRoot_thenRewrittenToTest() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
client.get()
|
||||
.uri("/")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,16 +61,15 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
formData.add("user", "baeldung");
|
||||
formData.add("token", "you_know_what_to_do");
|
||||
|
||||
client
|
||||
.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("welcome back!");
|
||||
client.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("welcome back!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,70 +78,64 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
formData.add("user", "baeldung");
|
||||
formData.add("token", "try_again");
|
||||
|
||||
client
|
||||
.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isBadRequest();
|
||||
client.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isBadRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception {
|
||||
Resource resource = new ClassPathResource("/baeldung-weekly.png");
|
||||
client
|
||||
.post()
|
||||
.uri("/upload")
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.body(fromResource(resource))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo(String.valueOf(resource.contentLength()));
|
||||
client.post()
|
||||
.uri("/upload")
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.body(fromResource(resource))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo(String.valueOf(resource.contentLength()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenActors_whenAddActor_thenAdded() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(2);
|
||||
client.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(2);
|
||||
|
||||
client
|
||||
.post()
|
||||
.uri("/actor")
|
||||
.body(fromObject(new Actor("Clint", "Eastwood")))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk();
|
||||
client.post()
|
||||
.uri("/actor")
|
||||
.body(fromObject(new Actor("Clint", "Eastwood")))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk();
|
||||
|
||||
client
|
||||
.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(3);
|
||||
client.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResources_whenAccess_thenGot() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/files/hello.txt")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("hello");
|
||||
client.get()
|
||||
.uri("/files/hello.txt")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("hello");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user