Skip to content

Commit e72744d

Browse files
lor6pivovarit
authored andcommitted
compile functional test (eugenp#1788)
1 parent 30df154 commit e72744d

1 file changed

Lines changed: 34 additions & 20 deletions

File tree

‎spring-5/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java‎

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
import org.junit.BeforeClass;
55
import org.junit.Test;
66
import org.springframework.boot.web.server.WebServer;
7+
import org.springframework.core.io.ClassPathResource;
8+
import org.springframework.core.io.Resource;
9+
import org.springframework.http.MediaType;
710
import org.springframework.test.web.reactive.server.WebTestClient;
811

12+
import org.springframework.util.LinkedMultiValueMap;
13+
import org.springframework.util.MultiValueMap;
14+
import org.springframework.web.reactive.function.BodyInserters;
15+
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
16+
import static org.springframework.web.reactive.function.BodyInserters.fromResource;
17+
18+
919
public class FunctionalWebApplicationIntegrationTest {
1020

1121
private static WebTestClient client;
@@ -49,7 +59,7 @@ public void givenIndexFilter_whenRequestRoot_thenRewrittenToTest() throws Except
4959
.isEqualTo("helloworld");
5060
}
5161

52-
/* @Test
62+
@Test
5363
public void givenLoginForm_whenPostValidToken_thenSuccess() throws Exception {
5464
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(1);
5565
formData.add("user", "baeldung");
@@ -59,15 +69,17 @@ public void givenLoginForm_whenPostValidToken_thenSuccess() throws Exception {
5969
.post()
6070
.uri("/login")
6171
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
62-
.exchange(BodyInserters.fromFormData(formData))
72+
.body(BodyInserters.fromFormData(formData))
73+
.exchange()
6374
.expectStatus()
6475
.isOk()
6576
.expectBody(String.class)
66-
.value()
67-
.isEqualTo("welcome back!");
68-
}*/
77+
.returnResult()
78+
.getResponseBody()
79+
.equals("welcome back!");
80+
}
6981

70-
/* @Test
82+
@Test
7183
public void givenLoginForm_whenRequestWithInvalidToken_thenFail() throws Exception {
7284
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(2);
7385
formData.add("user", "baeldung");
@@ -77,42 +89,45 @@ public void givenLoginForm_whenRequestWithInvalidToken_thenFail() throws Excepti
7789
.post()
7890
.uri("/login")
7991
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
80-
.exchange(BodyInserters.fromFormData(formData))
92+
.body(BodyInserters.fromFormData(formData))
93+
.exchange()
8194
.expectStatus()
8295
.isBadRequest();
8396
}
84-
*/
85-
/* @Test
97+
98+
@Test
8699
public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception {
87100
Resource resource = new ClassPathResource("/baeldung-weekly.png");
88101
client
89102
.post()
90103
.uri("/upload")
91104
.contentType(MediaType.MULTIPART_FORM_DATA)
92-
.exchange(fromResource(resource))
105+
.body(fromResource(resource))
106+
.exchange()
93107
.expectStatus()
94108
.isOk()
95109
.expectBody(String.class)
96-
.value()
97-
.isEqualTo(String.valueOf(resource.contentLength()));
110+
.returnResult()
111+
.getResponseBody()
112+
.equals(String.valueOf(resource.contentLength()));
98113
}
99-
*/
100-
/* @Test
114+
115+
@Test
101116
public void givenActors_whenAddActor_thenAdded() throws Exception {
102117
client
103118
.get()
104119
.uri("/actor")
105120
.exchange()
106121
.expectStatus()
107122
.isOk()
108-
.expectBody(Actor.class)
109-
.list()
123+
.expectBodyList(Actor.class)
110124
.hasSize(2);
111125

112126
client
113127
.post()
114128
.uri("/actor")
115-
.exchange(fromObject(new Actor("Clint", "Eastwood")))
129+
.body(fromObject(new Actor("Clint", "Eastwood")))
130+
.exchange()
116131
.expectStatus()
117132
.isOk();
118133

@@ -122,10 +137,9 @@ public void givenActors_whenAddActor_thenAdded() throws Exception {
122137
.exchange()
123138
.expectStatus()
124139
.isOk()
125-
.expectBody(Actor.class)
126-
.list()
140+
.expectBodyList(Actor.class)
127141
.hasSize(3);
128-
}*/
142+
}
129143

130144
@Test
131145
public void givenResources_whenAccess_thenGot() throws Exception {

0 commit comments

Comments
 (0)