Skip to content

Commit c539a8c

Browse files
committed
URL PATH of Actions - Controller Methods Refactoring
1 parent 8d07f7c commit c539a8c

20 files changed

+250
-170
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.woehlke.simpleworklist;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.boot.web.server.LocalServerPort;
9+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
10+
import org.springframework.security.core.context.SecurityContextHolder;
11+
import org.springframework.test.context.event.annotation.AfterTestClass;
12+
import org.springframework.test.context.event.annotation.BeforeTestClass;
13+
import org.springframework.test.web.servlet.MockMvc;
14+
import org.springframework.web.context.WebApplicationContext;
15+
import org.woehlke.simpleworklist.config.UserAccountTestDataService;
16+
17+
import java.net.URL;
18+
19+
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
20+
21+
@Slf4j
22+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
23+
public class SmokeTests {
24+
25+
@Autowired
26+
ServletWebServerApplicationContext server;
27+
28+
@LocalServerPort
29+
int port;
30+
31+
protected URL base;
32+
33+
@Autowired
34+
protected WebApplicationContext wac;
35+
36+
protected MockMvc mockMvc;
37+
38+
@Autowired
39+
private UserAccountTestDataService userAccountTestDataService;
40+
41+
@BeforeEach
42+
public void setUp() throws Exception {
43+
log.info(" @BeforeEach setUp()");
44+
this.base = new URL("http://localhost:" + port + "/");
45+
this.mockMvc = webAppContextSetup(wac).build();
46+
userAccountTestDataService.setUp();
47+
}
48+
49+
@BeforeTestClass
50+
public void runBeforeTestClass() throws Exception {
51+
log.info(" @BeforeTestClass runBeforeTestClass");
52+
}
53+
54+
@AfterTestClass
55+
public void runAfterTestClass() {
56+
log.info(" @AfterTestClass clearContext");
57+
SecurityContextHolder.clearContext();
58+
}
59+
60+
@Test
61+
public void testF001ServerStarts(){
62+
log.info("testF001ServerStarts");
63+
}
64+
65+
@Test
66+
public void testF002HomePageRendered(){
67+
log.info("testF002HomePageRendered");
68+
}
69+
70+
@Test
71+
public void testF003Registration(){
72+
log.info("testF003Registration");
73+
}
74+
75+
@Test
76+
public void testF004PasswordRecovery(){
77+
log.info("testF004PasswordRecovery");
78+
}
79+
80+
@Test
81+
public void testF005Login(){
82+
log.info("testF005Login");
83+
}
84+
85+
@Test
86+
public void testF006PageAfterFirstSuccessfulLogin(){
87+
log.info("testF006PageAfterFirstSuccessfulLogins");
88+
}
89+
90+
@Test
91+
public void testF007AddFirstNewTask(){
92+
log.info("testF007AddFirstNewTask");
93+
}
94+
95+
@Test
96+
public void testF008AddFirstNewProject(){
97+
log.info("testF008AddFirstNewProject");
98+
}
99+
}

src/test/java/org/woehlke/simpleworklist/AbstractTest.java renamed to src/test/java/org/woehlke/simpleworklist/config/AbstractTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.woehlke.simpleworklist;
1+
package org.woehlke.simpleworklist.config;
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.junit.jupiter.api.BeforeEach;

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

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.woehlke.simpleworklist.config;
2+
3+
import org.woehlke.simpleworklist.user.account.UserAccount;
4+
5+
public interface UserAccountTestDataService {
6+
7+
void setUp();
8+
9+
UserAccount getFirstUserAccount();
10+
11+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.woehlke.simpleworklist.config;
2+
3+
import lombok.Getter;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Service;
7+
import org.woehlke.simpleworklist.context.Context;
8+
import org.woehlke.simpleworklist.context.ContextService;
9+
import org.woehlke.simpleworklist.context.NewContextForm;
10+
import org.woehlke.simpleworklist.language.Language;
11+
import org.woehlke.simpleworklist.user.account.UserAccount;
12+
import org.woehlke.simpleworklist.user.account.UserAccountService;
13+
14+
import java.util.Date;
15+
16+
17+
@Slf4j
18+
@Getter
19+
@Service
20+
public class UserAccountTestDataServiceImpl implements UserAccountTestDataService {
21+
22+
private final String[] emails = { "test01@test.de", "test02@test.de", "test03@test.de" };
23+
private final String[] passwords = { "test01pwd", "test02pwd", "test03pwd"};
24+
private final String[] fullnames = { "test01 Name", "test02 Name", "test03 Name"};
25+
26+
private final String username_email = "undefined@test.de";
27+
private final String password = "ASDFG";
28+
private final String full_name = "UNDEFINED_NAME";
29+
30+
private final UserAccount[] testUser;
31+
private final NewContextForm[] newContext;
32+
33+
private final UserAccountService userAccountService;
34+
private final ContextService contextService;
35+
private final ApplicationProperties applicationProperties;
36+
37+
@Autowired
38+
public UserAccountTestDataServiceImpl(
39+
UserAccountService userAccountService,
40+
ContextService contextService,
41+
ApplicationProperties applicationProperties
42+
) {
43+
this.userAccountService = userAccountService;
44+
this.contextService = contextService;
45+
this.applicationProperties = applicationProperties;
46+
Date lastLoginTimestamp = new Date();
47+
testUser = new UserAccount[emails.length];
48+
newContext = new NewContextForm[emails.length];
49+
for (int i = 0; i < testUser.length; i++) {
50+
testUser[i] = new UserAccount();
51+
testUser[i].setUserEmail(emails[i]);
52+
testUser[i].setUserPassword(passwords[i]);
53+
testUser[i].setUserFullname(fullnames[i]);
54+
testUser[i].setDefaultLanguage(Language.EN);
55+
testUser[i].setLastLoginTimestamp(lastLoginTimestamp);
56+
newContext[i] = new NewContextForm("testDe_"+i,"testEn_"+i);
57+
}
58+
}
59+
60+
public void setUp() {
61+
for (int i = 0; i < testUser.length; i++) {
62+
UserAccount a = userAccountService.findByUserEmail(testUser[i].getUserEmail());
63+
if (a == null) {
64+
UserAccount persisted = userAccountService.saveAndFlush(testUser[i]);
65+
testUser[i] = persisted;
66+
NewContextForm newContextPrivate = new NewContextForm("privat"+i,"private"+i);
67+
NewContextForm newContextWork = new NewContextForm("arbeit"+i,"work"+i);
68+
Context persistedContextPrivate = contextService.createNewContext(newContextPrivate, testUser[i]);
69+
Context persistedContextWork = contextService.createNewContext(newContextWork, testUser[i]);
70+
testUser[i].setDefaultContext(persistedContextPrivate);
71+
}
72+
}
73+
}
74+
75+
@Override
76+
public UserAccount getFirstUserAccount() {
77+
return testUser[0];
78+
}
79+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,58 @@
11
package org.woehlke.simpleworklist.testdata;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.boot.web.server.LocalServerPort;
10+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
11+
import org.springframework.test.web.servlet.MockMvc;
12+
import org.springframework.web.context.WebApplicationContext;
13+
import org.woehlke.simpleworklist.config.UserAccountTestDataService;
14+
import org.woehlke.simpleworklist.user.account.UserAccount;
15+
16+
import java.net.URL;
17+
18+
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
19+
20+
@Slf4j
21+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
322
public class TestDataServiceTest {
23+
24+
@Autowired
25+
ServletWebServerApplicationContext server;
26+
27+
@LocalServerPort
28+
int port;
29+
30+
protected URL base;
31+
32+
@Autowired
33+
protected WebApplicationContext wac;
34+
35+
protected MockMvc mockMvc;
36+
37+
@Autowired
38+
private TestDataService testDataService;
39+
40+
@Autowired
41+
private UserAccountTestDataService userAccountTestDataService;
42+
43+
@BeforeEach
44+
public void setUp() throws Exception {
45+
log.info(" @BeforeEach setUp()");
46+
this.base = new URL("http://localhost:" + port + "/");
47+
this.mockMvc = webAppContextSetup(wac).build();
48+
}
49+
50+
@Test
51+
public void createTestCategoryTreeForUserAccountTest(){
52+
log.info("createTestCategoryTreeForUserAccountTest");
53+
userAccountTestDataService.setUp();
54+
UserAccount userAccount = userAccountTestDataService.getFirstUserAccount();
55+
//TODO:
56+
//testDataService.createTestCategoryTreeForUserAccount(userAccount);
57+
}
458
}

src/test/java/org/woehlke/simpleworklist/user/account/UserAccountPasswordEncodedTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.woehlke.simpleworklist.user.account;
22

33

4-
import org.junit.jupiter.api.Test;
54
import org.springframework.security.crypto.password.PasswordEncoder;
6-
import org.woehlke.simpleworklist.AbstractTest;
5+
import org.woehlke.simpleworklist.config.AbstractTest;
76

87
import org.springframework.beans.factory.annotation.Autowired;
98

src/test/java/org/woehlke/simpleworklist/user/account/UserAccountServiceImplTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.woehlke.simpleworklist.user.account;
22

3-
import org.junit.jupiter.api.Test;
43
import org.springframework.beans.factory.annotation.Autowired;
54

65

@@ -9,7 +8,7 @@
98
import org.springframework.security.core.context.SecurityContextHolder;
109
import org.springframework.security.core.userdetails.UserDetails;
1110
import org.springframework.security.core.userdetails.UsernameNotFoundException;
12-
import org.woehlke.simpleworklist.AbstractTest;
11+
import org.woehlke.simpleworklist.config.AbstractTest;
1312
import org.woehlke.simpleworklist.user.resetpassword.UserPasswordRecoveryService;
1413
import org.woehlke.simpleworklist.user.register.UserRegistrationService;
1514
import org.woehlke.simpleworklist.user.login.LoginForm;

src/test/java/org/woehlke/simpleworklist/user/login/UserLoginControllerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
66
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
77

8-
import org.junit.jupiter.api.Test;
9-
import org.woehlke.simpleworklist.AbstractTest;
8+
import org.woehlke.simpleworklist.config.AbstractTest;
109

1110
public class UserLoginControllerTest extends AbstractTest {
1211

src/test/java/org/woehlke/simpleworklist/user/register/UserRegistrationControllerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.woehlke.simpleworklist.user.register;
22

3-
import org.junit.jupiter.api.Test;
4-
import org.woehlke.simpleworklist.AbstractTest;
3+
import org.woehlke.simpleworklist.config.AbstractTest;
54

65
import org.springframework.beans.factory.annotation.Autowired;
76

0 commit comments

Comments
 (0)