compile functional test (#1788)
This commit is contained in:
parent
30df1541a1
commit
e72744dbd0
@ -4,8 +4,18 @@ import org.junit.AfterClass;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.boot.web.server.WebServer;
|
import org.springframework.boot.web.server.WebServer;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
|
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
|
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||||
|
import static org.springframework.web.reactive.function.BodyInserters.fromResource;
|
||||||
|
|
||||||
|
|
||||||
public class FunctionalWebApplicationIntegrationTest {
|
public class FunctionalWebApplicationIntegrationTest {
|
||||||
|
|
||||||
private static WebTestClient client;
|
private static WebTestClient client;
|
||||||
@ -49,7 +59,7 @@ public class FunctionalWebApplicationIntegrationTest {
|
|||||||
.isEqualTo("helloworld");
|
.isEqualTo("helloworld");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @Test
|
@Test
|
||||||
public void givenLoginForm_whenPostValidToken_thenSuccess() throws Exception {
|
public void givenLoginForm_whenPostValidToken_thenSuccess() throws Exception {
|
||||||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(1);
|
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(1);
|
||||||
formData.add("user", "baeldung");
|
formData.add("user", "baeldung");
|
||||||
@ -59,15 +69,17 @@ public class FunctionalWebApplicationIntegrationTest {
|
|||||||
.post()
|
.post()
|
||||||
.uri("/login")
|
.uri("/login")
|
||||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
.exchange(BodyInserters.fromFormData(formData))
|
.body(BodyInserters.fromFormData(formData))
|
||||||
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectBody(String.class)
|
.expectBody(String.class)
|
||||||
.value()
|
.returnResult()
|
||||||
.isEqualTo("welcome back!");
|
.getResponseBody()
|
||||||
}*/
|
.equals("welcome back!");
|
||||||
|
}
|
||||||
|
|
||||||
/* @Test
|
@Test
|
||||||
public void givenLoginForm_whenRequestWithInvalidToken_thenFail() throws Exception {
|
public void givenLoginForm_whenRequestWithInvalidToken_thenFail() throws Exception {
|
||||||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(2);
|
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(2);
|
||||||
formData.add("user", "baeldung");
|
formData.add("user", "baeldung");
|
||||||
@ -77,27 +89,30 @@ public class FunctionalWebApplicationIntegrationTest {
|
|||||||
.post()
|
.post()
|
||||||
.uri("/login")
|
.uri("/login")
|
||||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
.exchange(BodyInserters.fromFormData(formData))
|
.body(BodyInserters.fromFormData(formData))
|
||||||
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isBadRequest();
|
.isBadRequest();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
/* @Test
|
@Test
|
||||||
public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception {
|
public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception {
|
||||||
Resource resource = new ClassPathResource("/baeldung-weekly.png");
|
Resource resource = new ClassPathResource("/baeldung-weekly.png");
|
||||||
client
|
client
|
||||||
.post()
|
.post()
|
||||||
.uri("/upload")
|
.uri("/upload")
|
||||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||||
.exchange(fromResource(resource))
|
.body(fromResource(resource))
|
||||||
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectBody(String.class)
|
.expectBody(String.class)
|
||||||
.value()
|
.returnResult()
|
||||||
.isEqualTo(String.valueOf(resource.contentLength()));
|
.getResponseBody()
|
||||||
|
.equals(String.valueOf(resource.contentLength()));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
/* @Test
|
@Test
|
||||||
public void givenActors_whenAddActor_thenAdded() throws Exception {
|
public void givenActors_whenAddActor_thenAdded() throws Exception {
|
||||||
client
|
client
|
||||||
.get()
|
.get()
|
||||||
@ -105,14 +120,14 @@ public class FunctionalWebApplicationIntegrationTest {
|
|||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectBody(Actor.class)
|
.expectBodyList(Actor.class)
|
||||||
.list()
|
|
||||||
.hasSize(2);
|
.hasSize(2);
|
||||||
|
|
||||||
client
|
client
|
||||||
.post()
|
.post()
|
||||||
.uri("/actor")
|
.uri("/actor")
|
||||||
.exchange(fromObject(new Actor("Clint", "Eastwood")))
|
.body(fromObject(new Actor("Clint", "Eastwood")))
|
||||||
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk();
|
.isOk();
|
||||||
|
|
||||||
@ -122,10 +137,9 @@ public class FunctionalWebApplicationIntegrationTest {
|
|||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectBody(Actor.class)
|
.expectBodyList(Actor.class)
|
||||||
.list()
|
|
||||||
.hasSize(3);
|
.hasSize(3);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResources_whenAccess_thenGot() throws Exception {
|
public void givenResources_whenAccess_thenGot() throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user