Skip to content

Commit 1d44d0b

Browse files
committed
Fixed #126
1 parent 6946092 commit 1d44d0b

File tree

2 files changed

+58
-48
lines changed

2 files changed

+58
-48
lines changed

src/test/java/org/woehlke/simpleworklist/SmokeTests.java

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@
44
import org.junit.Before;
55
import org.junit.jupiter.api.*;
66
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
8+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
79
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
810
import org.springframework.boot.test.context.SpringBootTest;
911
import org.springframework.boot.web.server.LocalServerPort;
1012
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
13+
import org.springframework.context.annotation.Import;
1114
import org.springframework.security.core.context.SecurityContextHolder;
1215
import org.springframework.security.core.userdetails.UsernameNotFoundException;
1316
import org.springframework.security.test.context.support.WithMockUser;
1417
import org.springframework.test.web.servlet.MockMvc;
18+
import org.springframework.test.web.servlet.ResultActions;
19+
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
1520
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
1621
import org.springframework.web.context.WebApplicationContext;
22+
import org.woehlke.simpleworklist.config.ApplicationProperties;
1723
import org.woehlke.simpleworklist.config.UserAccountTestDataService;
24+
import org.woehlke.simpleworklist.config.di.WebMvcConfig;
25+
import org.woehlke.simpleworklist.config.di.WebSecurityConfig;
1826

1927
import java.net.URL;
2028

2129
import static org.hamcrest.Matchers.containsString;
2230
import static org.junit.jupiter.api.Assertions.assertNotNull;
2331
import static org.junit.jupiter.api.Assertions.assertTrue;
24-
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
2532
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2633
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
2734
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -32,6 +39,7 @@
3239
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3340
@AutoConfigureMockMvc
3441
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
42+
@Import(SimpleworklistApplication.class)
3543
public class SmokeTests {
3644

3745
@Autowired
@@ -43,8 +51,6 @@ public class SmokeTests {
4351
@LocalServerPort
4452
private int port;
4553

46-
protected URL base;
47-
4854
@Autowired
4955
private UserAccountTestDataService userAccountTestDataService;
5056

@@ -68,8 +74,8 @@ public void runBeforeTestClass() throws Exception {
6874
log.info(eyecatcherH1);
6975
log.info(" @BeforeTestClass runBeforeTestClass");
7076
log.info(eyecatcherH2);
71-
this.base = new URL("http://localhost:" + port + "/");
72-
log.info(" Server URL: "+this.base.toString());
77+
URL base = new URL("http://localhost:" + port + "/");
78+
log.info(" Server URL: "+ base.toString());
7379
log.info(eyecatcherH2);
7480
userAccountTestDataService.setUp();
7581
log.info(eyecatcherH2);
@@ -82,8 +88,8 @@ public void runAfterTestClass() throws Exception {
8288
log.info(eyecatcherH1);
8389
log.info(" @AfterTestClass clearContext");
8490
log.info(eyecatcherH2);
85-
this.base = new URL("http://localhost:" + port + "/");
86-
log.info(" Server URL: "+this.base.toString());
91+
URL base = new URL("http://localhost:" + port + "/");
92+
log.info(" Server URL: "+ base.toString());
8793
log.info(eyecatcherH2);
8894
SecurityContextHolder.clearContext();
8995
log.info(eyecatcherH1);
@@ -97,8 +103,8 @@ public void testF001ServerStarts() throws Exception{
97103
log.info(eyecatcherH1);
98104
log.info("testF001ServerStarts");
99105
log.info(eyecatcherH2);
100-
this.base = new URL("http://localhost:" + port + "/");
101-
log.info("Server URL: "+this.base.toString());
106+
URL base = new URL("http://localhost:" + port + "/");
107+
log.info("Server URL: "+ base.toString());
102108
assertTrue(true);
103109
log.info(eyecatcherH2);
104110
}
@@ -110,15 +116,15 @@ public void testF002HomePageRendered() throws Exception {
110116
log.info(eyecatcherH1);
111117
log.info("testF002HomePageRendered");
112118
log.info(eyecatcherH2);
113-
this.base = new URL("http://localhost:" + port);
114-
log.info("Server URL: "+this.base.toString());
115-
this.mockMvc.perform(get( this.base.toString() ))
119+
URL base = new URL("http://localhost:" + port);
120+
URL redirectedUrl = new URL("http://localhost:" + port+ "/user/login");
121+
log.info("Server URL: "+ base.toString());
122+
this.mockMvc.perform(get( base.toString() ))
116123
.andDo(print())
117124
.andExpect(status().is3xxRedirection())
118-
.andExpect(redirectedUrl(this.base+"/user/login"));
119-
this.base = new URL("http://localhost:" + port + "/user/login");
120-
log.info("Server URL: "+this.base.toString());
121-
this.mockMvc.perform(get( this.base.toString()))
125+
.andExpect(redirectedUrl(redirectedUrl.toString()));
126+
log.info("Server URL: "+ redirectedUrl.toString());
127+
this.mockMvc.perform(get(redirectedUrl.toString()))
122128
.andDo(print())
123129
.andExpect(status().isOk())
124130
.andExpect(content().string(containsString("SimpleWorklist")));
@@ -229,13 +235,12 @@ public void testF013ShowTaskstateInbox() throws Exception {
229235
log.info(eyecatcherH1);
230236
log.info("testF013ShowTaskstateInbox");
231237
log.info(eyecatcherH2);
232-
assertNotNull(this.base);
233-
this.base = new URL("http://localhost:" + port + "/taskstate/inbox");
234-
log.info("Server URL: "+this.base.toString());
238+
URL base = new URL("http://localhost:" + port + "/taskstate/inbox");
239+
log.info("Server URL: "+ base.toString());
235240
assertNotNull(this.mockMvc);
236241
try {
237-
this.mockMvc.perform(get(this.base.toString()))
238-
.andDo(print())
242+
this.mockMvc.perform(get(base.toString()))
243+
//.andDo(print())
239244
.andExpect(status().isOk());
240245
//.andExpect(content().string(containsString("SimpleWorklist")));
241246
} catch (UsernameNotFoundException e) {
@@ -257,11 +262,11 @@ public void testF014ShowTaskstateToday() throws Exception {
257262
log.info(eyecatcherH1);
258263
log.info("testF014ShowTaskstateToday");
259264
log.info(eyecatcherH2);
260-
this.base = new URL("http://localhost:" + port + "/taskstate/today");
261-
log.info("Server URL: "+this.base.toString());
265+
URL base = new URL("http://localhost:" + port + "/taskstate/today");
266+
log.info("Server URL: "+ base.toString());
262267
assertNotNull(this.mockMvc);
263-
this.mockMvc.perform(get(this.base.toString()))
264-
.andDo(print())
268+
this.mockMvc.perform(get(base.toString()))
269+
//.andDo(print())
265270
.andExpect(status().isOk());
266271
//.andExpect(content().string(containsString("SimpleWorklist")));
267272
log.info(eyecatcherH2);
@@ -275,12 +280,16 @@ public void testF015ShowTaskstateNext() throws Exception {
275280
log.info(eyecatcherH1);
276281
log.info("testF015ShowTaskstateNext");
277282
log.info(eyecatcherH2);
278-
this.base = new URL("http://localhost:" + port + "/taskstate/next");
279-
log.info("Server URL: "+this.base.toString());
283+
URL base = new URL("http://localhost:" + port + "/taskstate/next");
284+
log.info("Server URL: "+ base.toString());
280285
assertNotNull(this.mockMvc);
281-
this.mockMvc.perform(get(this.base.toString()))
282-
.andDo(print())
283-
.andExpect(status().isOk());
286+
MockHttpServletRequestBuilder a = get(base.toString());
287+
assertNotNull(a);
288+
ResultActions x = this.mockMvc.perform(a);
289+
assertNotNull(x);
290+
ResultActions o = x.andDo(print());
291+
assertNotNull(o);
292+
o.andExpect(status().isOk());
284293
//.andExpect(content().string(containsString("SimpleWorklist")));
285294
log.info(eyecatcherH2);
286295
}
@@ -293,10 +302,10 @@ public void testF016ShowTaskstateWaiting() throws Exception {
293302
log.info(eyecatcherH1);
294303
log.info("testF016ShowTaskstateWaiting");
295304
log.info(eyecatcherH2);
296-
this.base = new URL("http://localhost:" + port + "/taskstate/waiting");
297-
log.info("Server URL: "+this.base.toString());
305+
URL base = new URL("http://localhost:" + port + "/taskstate/waiting");
306+
log.info("Server URL: "+ base.toString());
298307
assertNotNull(this.mockMvc);
299-
this.mockMvc.perform(get(this.base.toString()))
308+
this.mockMvc.perform(get(base.toString()))
300309
.andDo(print())
301310
.andExpect(status().isOk());
302311
//.andExpect(content().string(containsString("SimpleWorklist")));
@@ -311,10 +320,10 @@ public void testF017ShowTaskstateScheduled() throws Exception {
311320
log.info(eyecatcherH1);
312321
log.info("testF017ShowTaskstateScheduled");
313322
log.info(eyecatcherH2);
314-
this.base = new URL("http://localhost:" + port + "/taskstate/scheduled");
315-
log.info("Server URL: "+this.base.toString());
323+
URL base = new URL("http://localhost:" + port + "/taskstate/scheduled");
324+
log.info("Server URL: "+ base.toString());
316325
assertNotNull(this.mockMvc);
317-
this.mockMvc.perform(get(this.base.toString()))
326+
this.mockMvc.perform(get(base.toString()))
318327
.andDo(print())
319328
.andExpect(status().isOk());
320329
//.andExpect(content().string(containsString("SimpleWorklist")));
@@ -329,10 +338,10 @@ public void testF018ShowTaskstateSomeday() throws Exception {
329338
log.info(eyecatcherH1);
330339
log.info("testF018ShowTaskstateSomeday");
331340
log.info(eyecatcherH2);
332-
this.base = new URL("http://localhost:" + port + "/taskstate/someday");
333-
log.info("Server URL: "+this.base.toString());
341+
URL base = new URL("http://localhost:" + port + "/taskstate/someday");
342+
log.info("Server URL: "+base.toString());
334343
assertNotNull(this.mockMvc);
335-
this.mockMvc.perform(get(this.base.toString()))
344+
this.mockMvc.perform(get(base.toString()))
336345
.andDo(print())
337346
.andExpect(status().isOk());
338347
//.andExpect(content().string(containsString("SimpleWorklist")));
@@ -347,10 +356,10 @@ public void testF019ShowTaskstateFocus() throws Exception {
347356
log.info(eyecatcherH1);
348357
log.info("testF019ShowTaskstateFocus");
349358
log.info(eyecatcherH2);
350-
this.base = new URL("http://localhost:" + port + "/taskstate/focus");
351-
log.info("Server URL: "+this.base.toString());
359+
URL base = new URL("http://localhost:" + port + "/taskstate/focus");
360+
log.info("Server URL: "+base.toString());
352361
assertNotNull(this.mockMvc);
353-
this.mockMvc.perform(get(this.base.toString()))
362+
this.mockMvc.perform(get(base.toString()))
354363
.andDo(print())
355364
.andExpect(status().isOk());
356365
//.andExpect(content().string(containsString("SimpleWorklist")));
@@ -365,10 +374,10 @@ public void testF020ShowTaskstateCompleted() throws Exception {
365374
log.info(eyecatcherH1);
366375
log.info("testF020ShowTaskstateCompleted");
367376
log.info(eyecatcherH2);
368-
this.base = new URL("http://localhost:" + port + "/taskstate/completed");
369-
log.info("Server URL: "+this.base.toString());
377+
URL base = new URL("http://localhost:" + port + "/taskstate/completed");
378+
log.info("Server URL: "+base.toString());
370379
assertNotNull(this.mockMvc);
371-
this.mockMvc.perform(get(this.base.toString()))
380+
this.mockMvc.perform(get(base.toString()))
372381
.andDo(print())
373382
.andExpect(status().isOk());
374383
//.andExpect(content().string(containsString("SimpleWorklist")));
@@ -383,10 +392,10 @@ public void testF021ShowTaskstateTrash() throws Exception {
383392
log.info(eyecatcherH1);
384393
log.info("testF021ShowTaskstateTrash");
385394
log.info(eyecatcherH2);
386-
this.base = new URL("http://localhost:" + port + "/taskstate/trash");
387-
log.info("Server URL: "+this.base.toString());
395+
URL base = new URL("http://localhost:" + port + "/taskstate/trash");
396+
log.info("Server URL: "+base.toString());
388397
assertNotNull(this.mockMvc);
389-
this.mockMvc.perform(get(this.base.toString()))
398+
this.mockMvc.perform(get(base.toString()))
390399
.andDo(print())
391400
.andExpect(status().isOk());
392401
//.andExpect(content().string(containsString("SimpleWorklist")));

src/test/resources/logback.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
<appender-ref ref="CONSOLE" />
77
</root>
88
<logger name="org.springframework.web" level="DEBUG"/>
9+
<logger name="org.springframework.test" level="DEBUG"/>
910
</configuration>

0 commit comments

Comments
 (0)