Skip to content

Commit 6946092

Browse files
committed
Fixed #126
1 parent 9e245d9 commit 6946092

File tree

2 files changed

+136
-19
lines changed

2 files changed

+136
-19
lines changed

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

Lines changed: 135 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package org.woehlke.simpleworklist;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.Before;
45
import org.junit.jupiter.api.*;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
78
import org.springframework.boot.test.context.SpringBootTest;
89
import org.springframework.boot.web.server.LocalServerPort;
910
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
1011
import org.springframework.security.core.context.SecurityContextHolder;
12+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
13+
import org.springframework.security.test.context.support.WithMockUser;
1114
import org.springframework.test.web.servlet.MockMvc;
12-
import org.woehlke.simpleworklist.config.FunctionalRequirements;
15+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
16+
import org.springframework.web.context.WebApplicationContext;
1317
import org.woehlke.simpleworklist.config.UserAccountTestDataService;
1418

1519
import java.net.URL;
1620

1721
import static org.hamcrest.Matchers.containsString;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1823
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
1925
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2026
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
2127
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -31,14 +37,14 @@ public class SmokeTests {
3137
@Autowired
3238
private ServletWebServerApplicationContext server;
3339

40+
@Autowired
41+
private MockMvc mockMvc;
42+
3443
@LocalServerPort
3544
private int port;
3645

3746
protected URL base;
3847

39-
@Autowired
40-
private MockMvc mockMvc;
41-
4248
@Autowired
4349
private UserAccountTestDataService userAccountTestDataService;
4450

@@ -52,8 +58,7 @@ public void setUp() throws Exception {
5258
log.info(eyecatcherH1);
5359
log.info(" @BeforeEach setUp()");
5460
log.info(eyecatcherH2);
55-
this.base = new URL("http://localhost:" + port + "/");
56-
log.info(" Server URL: "+this.base.toString());
61+
5762
//userAccountTestDataService.setUp();
5863
log.info(eyecatcherH1);
5964
}
@@ -73,10 +78,13 @@ public void runBeforeTestClass() throws Exception {
7378
}
7479

7580
@AfterAll
76-
public void runAfterTestClass() {
81+
public void runAfterTestClass() throws Exception {
7782
log.info(eyecatcherH1);
7883
log.info(" @AfterTestClass clearContext");
7984
log.info(eyecatcherH2);
85+
this.base = new URL("http://localhost:" + port + "/");
86+
log.info(" Server URL: "+this.base.toString());
87+
log.info(eyecatcherH2);
8088
SecurityContextHolder.clearContext();
8189
log.info(eyecatcherH1);
8290
}
@@ -85,10 +93,11 @@ public void runAfterTestClass() {
8593
@DisplayName(F001)
8694
@Order(1)
8795
@Test
88-
public void testF001ServerStarts(){
96+
public void testF001ServerStarts() throws Exception{
8997
log.info(eyecatcherH1);
9098
log.info("testF001ServerStarts");
9199
log.info(eyecatcherH2);
100+
this.base = new URL("http://localhost:" + port + "/");
92101
log.info("Server URL: "+this.base.toString());
93102
assertTrue(true);
94103
log.info(eyecatcherH2);
@@ -101,11 +110,15 @@ public void testF002HomePageRendered() throws Exception {
101110
log.info(eyecatcherH1);
102111
log.info("testF002HomePageRendered");
103112
log.info(eyecatcherH2);
113+
this.base = new URL("http://localhost:" + port);
114+
log.info("Server URL: "+this.base.toString());
104115
this.mockMvc.perform(get( this.base.toString() ))
105116
.andDo(print())
106117
.andExpect(status().is3xxRedirection())
107-
.andExpect(redirectedUrl(this.base+"user/login"));
108-
this.mockMvc.perform(get( this.base+"user/login" ))
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()))
109122
.andDo(print())
110123
.andExpect(status().isOk())
111124
.andExpect(content().string(containsString("SimpleWorklist")));
@@ -148,6 +161,7 @@ public void testF006PageAfterFirstSuccessfulLogin(){
148161
log.info(eyecatcherH2);
149162
}
150163

164+
@WithMockUser(username="test01@test.de")
151165
@DisplayName(F007)
152166
@Order(7)
153167
@Test
@@ -157,6 +171,7 @@ public void testF007AddFirstNewTaskToInbox(){
157171
log.info(eyecatcherH2);
158172
}
159173

174+
@WithMockUser(username="test01@test.de")
160175
@DisplayName(F008)
161176
@Order(8)
162177
@Test
@@ -166,6 +181,7 @@ public void testF008AddAnotherNewTaskToInbox(){
166181
log.info(eyecatcherH2);
167182
}
168183

184+
@WithMockUser(username="test01@test.de")
169185
@DisplayName(F009)
170186
@Order(9)
171187
@Test
@@ -175,6 +191,7 @@ public void testF009AddTaskToProjectRoot(){
175191
log.info(eyecatcherH2);
176192
}
177193

194+
@WithMockUser(username="test01@test.de")
178195
@DisplayName(F010)
179196
@Order(10)
180197
@Test
@@ -184,6 +201,7 @@ public void testF010AddSubProjectToProjectRoot(){
184201
log.info(eyecatcherH2);
185202
}
186203

204+
@WithMockUser(username="test01@test.de")
187205
@DisplayName(F011)
188206
@Order(11)
189207
@Test
@@ -193,6 +211,7 @@ public void testF011SetFocusOfTask(){
193211
log.info(eyecatcherH2);
194212
}
195213

214+
@WithMockUser(username="test01@test.de")
196215
@DisplayName(F012)
197216
@Order(12)
198217
@Test
@@ -202,87 +221,179 @@ public void testF012UnSetFocusOfTask(){
202221
log.info(eyecatcherH2);
203222
}
204223

224+
@WithMockUser(username="test01@test.de")
205225
@DisplayName(F013)
206226
@Order(13)
207227
@Test
208-
public void testF013ShowTaskstateInbox(){
228+
public void testF013ShowTaskstateInbox() throws Exception {
209229
log.info(eyecatcherH1);
210230
log.info("testF013ShowTaskstateInbox");
211231
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());
235+
assertNotNull(this.mockMvc);
236+
try {
237+
this.mockMvc.perform(get(this.base.toString()))
238+
.andDo(print())
239+
.andExpect(status().isOk());
240+
//.andExpect(content().string(containsString("SimpleWorklist")));
241+
} catch (UsernameNotFoundException e) {
242+
log.error("UsernameNotFoundException: "+e.getLocalizedMessage());
243+
} catch (NullPointerException npe){
244+
log.error("NullPointerException: "+npe.getLocalizedMessage());
245+
for(StackTraceElement e:npe.getStackTrace()){
246+
log.error(e.getClassName()+"."+e.getMethodName()+"in: "+e.getFileName()+" line: "+e.getLineNumber());
247+
}
248+
}
249+
log.info(eyecatcherH2);
212250
}
213251

252+
@WithMockUser(username="test01@test.de")
214253
@DisplayName(F014)
215254
@Order(14)
216255
@Test
217-
public void testF014ShowTaskstateToday(){
256+
public void testF014ShowTaskstateToday() throws Exception {
218257
log.info(eyecatcherH1);
219258
log.info("testF014ShowTaskstateToday");
220259
log.info(eyecatcherH2);
260+
this.base = new URL("http://localhost:" + port + "/taskstate/today");
261+
log.info("Server URL: "+this.base.toString());
262+
assertNotNull(this.mockMvc);
263+
this.mockMvc.perform(get(this.base.toString()))
264+
.andDo(print())
265+
.andExpect(status().isOk());
266+
//.andExpect(content().string(containsString("SimpleWorklist")));
267+
log.info(eyecatcherH2);
221268
}
222269

270+
@WithMockUser(username="test01@test.de")
223271
@DisplayName(F015)
224272
@Order(15)
225273
@Test
226-
public void testF015ShowTaskstateNext(){
274+
public void testF015ShowTaskstateNext() throws Exception {
227275
log.info(eyecatcherH1);
228276
log.info("testF015ShowTaskstateNext");
229277
log.info(eyecatcherH2);
278+
this.base = new URL("http://localhost:" + port + "/taskstate/next");
279+
log.info("Server URL: "+this.base.toString());
280+
assertNotNull(this.mockMvc);
281+
this.mockMvc.perform(get(this.base.toString()))
282+
.andDo(print())
283+
.andExpect(status().isOk());
284+
//.andExpect(content().string(containsString("SimpleWorklist")));
285+
log.info(eyecatcherH2);
230286
}
231287

288+
@WithMockUser(username="test01@test.de")
232289
@DisplayName(F016)
233290
@Order(16)
234291
@Test
235-
public void testF016ShowTaskstateWaiting(){
292+
public void testF016ShowTaskstateWaiting() throws Exception {
236293
log.info(eyecatcherH1);
237294
log.info("testF016ShowTaskstateWaiting");
238295
log.info(eyecatcherH2);
296+
this.base = new URL("http://localhost:" + port + "/taskstate/waiting");
297+
log.info("Server URL: "+this.base.toString());
298+
assertNotNull(this.mockMvc);
299+
this.mockMvc.perform(get(this.base.toString()))
300+
.andDo(print())
301+
.andExpect(status().isOk());
302+
//.andExpect(content().string(containsString("SimpleWorklist")));
303+
log.info(eyecatcherH2);
239304
}
240305

306+
@WithMockUser(username="test01@test.de")
241307
@DisplayName(F017)
242308
@Order(17)
243309
@Test
244-
public void testF017ShowTaskstateScheduled(){
310+
public void testF017ShowTaskstateScheduled() throws Exception {
245311
log.info(eyecatcherH1);
246312
log.info("testF017ShowTaskstateScheduled");
247313
log.info(eyecatcherH2);
314+
this.base = new URL("http://localhost:" + port + "/taskstate/scheduled");
315+
log.info("Server URL: "+this.base.toString());
316+
assertNotNull(this.mockMvc);
317+
this.mockMvc.perform(get(this.base.toString()))
318+
.andDo(print())
319+
.andExpect(status().isOk());
320+
//.andExpect(content().string(containsString("SimpleWorklist")));
321+
log.info(eyecatcherH2);
248322
}
249323

324+
@WithMockUser(username="test01@test.de")
250325
@DisplayName(F018)
251326
@Order(18)
252327
@Test
253-
public void testF018ShowTaskstateSomeday(){
328+
public void testF018ShowTaskstateSomeday() throws Exception {
254329
log.info(eyecatcherH1);
255330
log.info("testF018ShowTaskstateSomeday");
256331
log.info(eyecatcherH2);
332+
this.base = new URL("http://localhost:" + port + "/taskstate/someday");
333+
log.info("Server URL: "+this.base.toString());
334+
assertNotNull(this.mockMvc);
335+
this.mockMvc.perform(get(this.base.toString()))
336+
.andDo(print())
337+
.andExpect(status().isOk());
338+
//.andExpect(content().string(containsString("SimpleWorklist")));
339+
log.info(eyecatcherH2);
257340
}
258341

342+
@WithMockUser(username="test01@test.de")
259343
@DisplayName(F019)
260344
@Order(19)
261345
@Test
262-
public void testF019ShowTaskstateFocus(){
346+
public void testF019ShowTaskstateFocus() throws Exception {
263347
log.info(eyecatcherH1);
264348
log.info("testF019ShowTaskstateFocus");
265349
log.info(eyecatcherH2);
350+
this.base = new URL("http://localhost:" + port + "/taskstate/focus");
351+
log.info("Server URL: "+this.base.toString());
352+
assertNotNull(this.mockMvc);
353+
this.mockMvc.perform(get(this.base.toString()))
354+
.andDo(print())
355+
.andExpect(status().isOk());
356+
//.andExpect(content().string(containsString("SimpleWorklist")));
357+
log.info(eyecatcherH2);
266358
}
267359

360+
@WithMockUser(username="test01@test.de")
268361
@DisplayName(F020)
269362
@Order(20)
270363
@Test
271-
public void testF020ShowTaskstateCompleted(){
364+
public void testF020ShowTaskstateCompleted() throws Exception {
272365
log.info(eyecatcherH1);
273366
log.info("testF020ShowTaskstateCompleted");
274367
log.info(eyecatcherH2);
368+
this.base = new URL("http://localhost:" + port + "/taskstate/completed");
369+
log.info("Server URL: "+this.base.toString());
370+
assertNotNull(this.mockMvc);
371+
this.mockMvc.perform(get(this.base.toString()))
372+
.andDo(print())
373+
.andExpect(status().isOk());
374+
//.andExpect(content().string(containsString("SimpleWorklist")));
375+
log.info(eyecatcherH2);
275376
}
276377

378+
@WithMockUser(username="test01@test.de")
277379
@DisplayName(F021)
278380
@Order(21)
279381
@Test
280-
public void testF021ShowTaskstateTrash(){
382+
public void testF021ShowTaskstateTrash() throws Exception {
281383
log.info(eyecatcherH1);
282384
log.info("testF021ShowTaskstateTrash");
283385
log.info(eyecatcherH2);
386+
this.base = new URL("http://localhost:" + port + "/taskstate/trash");
387+
log.info("Server URL: "+this.base.toString());
388+
assertNotNull(this.mockMvc);
389+
this.mockMvc.perform(get(this.base.toString()))
390+
.andDo(print())
391+
.andExpect(status().isOk());
392+
//.andExpect(content().string(containsString("SimpleWorklist")));
393+
log.info(eyecatcherH2);
284394
}
285395

396+
@WithMockUser(username="test01@test.de")
286397
@DisplayName(F022)
287398
@Order(22)
288399
@Test
@@ -292,6 +403,7 @@ public void testF022TaskEdit(){
292403
log.info(eyecatcherH2);
293404
}
294405

406+
@WithMockUser(username="test01@test.de")
295407
@DisplayName(F023)
296408
@Order(23)
297409
@Test
@@ -301,6 +413,7 @@ public void testF023TaskEditFormChangeTaskstateViaDropDown(){
301413
log.info(eyecatcherH2);
302414
}
303415

416+
@WithMockUser(username="test01@test.de")
304417
@DisplayName(F024)
305418
@Order(24)
306419
@Test
@@ -310,6 +423,7 @@ public void testF024TaskComplete(){
310423
log.info(eyecatcherH2);
311424
}
312425

426+
@WithMockUser(username="test01@test.de")
313427
@DisplayName(F025)
314428
@Order(25)
315429
@Test
@@ -319,6 +433,7 @@ public void testF025TaskIncomplete(){
319433
log.info(eyecatcherH2);
320434
}
321435

436+
@WithMockUser(username="test01@test.de")
322437
@DisplayName(F026)
323438
@Order(26)
324439
@Test
@@ -328,6 +443,7 @@ public void testF026TaskDelete(){
328443
log.info(eyecatcherH2);
329444
}
330445

446+
@WithMockUser(username="test01@test.de")
331447
@DisplayName(F027)
332448
@Order(27)
333449
@Test

src/test/java/org/woehlke/simpleworklist/config/UserAccountTestDataServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void setUp() {
6868
Context persistedContextPrivate = contextService.createNewContext(newContextPrivate, testUser[i]);
6969
Context persistedContextWork = contextService.createNewContext(newContextWork, testUser[i]);
7070
testUser[i].setDefaultContext(persistedContextPrivate);
71+
persisted = userAccountService.saveAndFlush(testUser[i]);
7172
}
7273
}
7374
}

0 commit comments

Comments
 (0)