Skip to content

Commit 754c660

Browse files
committed
URL PATH of Actions - Controller Methods Refactoring
1 parent e353525 commit 754c660

File tree

10 files changed

+184
-165
lines changed

10 files changed

+184
-165
lines changed

run.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ function runDev() {
66
./mvnw
77
}
88

9+
function runTest() {
10+
./mvnw -B clean dependency:list install --file pom.xml
11+
}
12+
913
function runGithubTestBuild() {
1014
./mvnw -B -DskipTests clean dependency:list install --file pom.xml
1115
}
@@ -27,10 +31,11 @@ function runHerokuLocal() {
2731
}
2832

2933
function main() {
30-
runGithubTestBuild
34+
#runGithubTestBuild
3135
#setupHeroku
32-
runHerokuLocal
36+
#runHerokuLocal
3337
#runDev
38+
runTest
3439
}
3540

3641
main

src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public UserPasswordRecoveryController(UserAccountService userAccountService, Use
3939
* @param model
4040
* @return a Formular for entering the email-adress.
4141
*/
42-
@RequestMapping(path = "/", method = RequestMethod.GET)
42+
@RequestMapping(method = RequestMethod.GET)
4343
public final String passwordForgottenForm(Model model) {
4444
UserRegistrationForm userRegistrationForm = new UserRegistrationForm();
4545
model.addAttribute("userRegistrationForm", userRegistrationForm);
@@ -54,7 +54,7 @@ public final String passwordForgottenForm(Model model) {
5454
* @param model
5555
* @return info page if without errors or formular again displaying error messages.
5656
*/
57-
@RequestMapping(path = "/", method = RequestMethod.POST)
57+
@RequestMapping(method = RequestMethod.POST)
5858
public final String passwordForgottenPost(
5959
@Valid UserRegistrationForm userRegistrationForm,
6060
BindingResult result,
Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package org.woehlke.simpleworklist;
22

3-
import org.junit.After;
4-
import org.junit.Before;
5-
import org.junit.runner.RunWith;
3+
import lombok.extern.slf4j.Slf4j;
64
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.boot.web.server.LocalServerPort;
77
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
88
import org.springframework.security.core.Authentication;
99
import org.springframework.security.core.context.SecurityContextHolder;
1010
import org.springframework.security.core.userdetails.UserDetails;
1111
import org.springframework.test.context.ContextConfiguration;
12-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13-
import org.springframework.test.context.web.WebAppConfiguration;
12+
import org.springframework.test.context.event.annotation.AfterTestClass;
13+
import org.springframework.test.context.event.annotation.BeforeTestClass;
1414
import org.springframework.test.web.servlet.MockMvc;
1515
import org.springframework.web.context.WebApplicationContext;
1616
import org.woehlke.simpleworklist.config.ApplicationProperties;
17+
import org.woehlke.simpleworklist.config.di.WebMvcConfig;
18+
import org.woehlke.simpleworklist.config.di.WebSecurityConfig;
1719
import org.woehlke.simpleworklist.helper.TestHelperService;
1820
import org.woehlke.simpleworklist.user.account.UserAccount;
1921
import org.woehlke.simpleworklist.user.account.UserAccountService;
@@ -25,19 +27,44 @@
2527
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
2628

2729

28-
@WebAppConfiguration
29-
@RunWith(SpringJUnit4ClassRunner.class)
30-
@ContextConfiguration(classes={SimpleworklistApplication.class})
30+
@Slf4j
31+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
32+
@ContextConfiguration(classes={
33+
SimpleworklistApplication.class,
34+
WebMvcConfig.class,
35+
WebSecurityConfig.class,
36+
ApplicationProperties.class
37+
})
3138
public abstract class AbstractTest {
3239

3340
@Autowired
3441
protected WebApplicationContext wac;
3542

36-
protected MockMvc mockMvc;
43+
@LocalServerPort
44+
int randomServerPort;
3745

3846
@Autowired
3947
protected ApplicationProperties applicationProperties;
4048

49+
50+
protected MockMvc mockMvc;
51+
52+
@BeforeTestClass
53+
public void setup() throws Exception {
54+
this.mockMvc = webAppContextSetup(wac).build();
55+
for (UserAccount u : testUser) {
56+
UserAccount a = userAccountService.findByUserEmail(u.getUserEmail());
57+
if (a == null) {
58+
userAccountService.saveAndFlush(u);
59+
}
60+
}
61+
}
62+
63+
@AfterTestClass
64+
public void clearContext() {
65+
SecurityContextHolder.clearContext();
66+
}
67+
4168
@Autowired
4269
protected TestHelperService testHelperService;
4370

@@ -53,15 +80,15 @@ public abstract class AbstractTest {
5380
@Autowired
5481
protected UserAccountLoginSuccessService userAccountLoginSuccessService;
5582

56-
protected static String emails[] = {"test01@test.de", "test02@test.de", "test03@test.de"};
57-
protected static String passwords[] = {"test01pwd", "test02pwd", "test03pwd"};
58-
protected static String fullnames[] = {"test01 Name", "test02 Name", "test03 Name"};
83+
protected static String[] emails = {"test01@test.de", "test02@test.de", "test03@test.de"};
84+
protected static String[] passwords = {"test01pwd", "test02pwd", "test03pwd"};
85+
protected static String[] fullnames = {"test01 Name", "test02 Name", "test03 Name"};
5986

6087
protected static String username_email = "undefined@test.de";
6188
protected static String password = "ASDFG";
6289
protected static String full_name = "UNDEFINED_NAME";
6390

64-
protected static UserAccount testUser[] = new UserAccount[emails.length];
91+
protected static UserAccount[] testUser = new UserAccount[emails.length];
6592

6693
static {
6794
for (int i = 0; i < testUser.length; i++) {
@@ -85,19 +112,4 @@ protected void deleteAll(){
85112
testHelperService.deleteUserAccount();
86113
}
87114

88-
@Before
89-
public void setup() throws Exception {
90-
this.mockMvc = webAppContextSetup(wac).build();
91-
for (UserAccount u : testUser) {
92-
UserAccount a = userAccountService.findByUserEmail(u.getUserEmail());
93-
if (a == null) {
94-
userAccountService.saveAndFlush(u);
95-
}
96-
}
97-
}
98-
99-
@After
100-
public void clearContext() {
101-
SecurityContextHolder.clearContext();
102-
}
103115
}

src/test/java/org/woehlke/simpleworklist/user/UserDetailsBeanTest.java

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package org.woehlke.simpleworklist.user;
22

33

4-
import org.junit.Assert;
5-
import org.junit.Test;
4+
5+
import org.junit.jupiter.api.Test;
66
import org.springframework.security.core.GrantedAuthority;
77
import org.woehlke.simpleworklist.user.account.UserAccount;
8-
import org.woehlke.simpleworklist.user.UserDetailsBean;
98

109
import java.util.Collection;
1110

11+
import static org.junit.jupiter.api.Assertions.*;
12+
1213

1314
public class UserDetailsBeanTest {
1415

@@ -17,20 +18,20 @@ public void testGetAuthorities(){
1718
UserAccount account = new UserAccount();
1819
UserDetailsBean b = new UserDetailsBean(account);
1920
Collection<? extends GrantedAuthority> c = b.getAuthorities();
20-
Assert.assertTrue(c.size()==1);
21+
assertTrue(c.size()==1);
2122
for(GrantedAuthority authority:c){
22-
Assert.assertTrue(authority.getAuthority().compareTo("ROLE_USER")==0);
23+
assertTrue(authority.getAuthority().compareTo("ROLE_USER")==0);
2324
}
2425
}
2526

2627
@Test
2728
public void testDefaultBooleans(){
2829
UserAccount account = new UserAccount();
2930
UserDetailsBean b = new UserDetailsBean(account);
30-
Assert.assertTrue(b.isAccountNonExpired());
31-
Assert.assertTrue(b.isAccountNonLocked());
32-
Assert.assertTrue(b.isCredentialsNonExpired());
33-
Assert.assertTrue(b.isEnabled());
31+
assertTrue(b.isAccountNonExpired());
32+
assertTrue(b.isAccountNonLocked());
33+
assertTrue(b.isCredentialsNonExpired());
34+
assertTrue(b.isEnabled());
3435
}
3536

3637
@Test
@@ -82,34 +83,34 @@ public void testHashCodeAndEquals(){
8283
UserDetailsBean b8 = new UserDetailsBean(account8);
8384
UserDetailsBean b9 = new UserDetailsBean(account9);
8485

85-
Assert.assertEquals(b1.hashCode(),b2.hashCode());
86-
Assert.assertTrue(b1.hashCode()!=b3.hashCode());
87-
Assert.assertTrue(b1.hashCode()!=b4.hashCode());
88-
Assert.assertTrue(b1.hashCode()!=b5.hashCode());
89-
Assert.assertTrue(b1.hashCode()!=b6.hashCode());
90-
Assert.assertTrue(b1.hashCode()!=b7.hashCode());
91-
Assert.assertTrue(b1.hashCode()!=b8.hashCode());
92-
Assert.assertTrue(b1.hashCode()!=b9.hashCode());
93-
94-
Assert.assertTrue(b1.equals(b1));
95-
Assert.assertTrue(b1.equals(b2));
96-
97-
Assert.assertFalse(b1.equals(null));
98-
Assert.assertFalse(b1.equals(account1));
99-
Assert.assertFalse(b1.equals(b3));
100-
Assert.assertFalse(b1.equals(b4));
101-
Assert.assertFalse(b1.equals(b5));
102-
Assert.assertFalse(b1.equals(b6));
103-
Assert.assertFalse(b1.equals(b7));
104-
Assert.assertFalse(b1.equals(b8));
105-
Assert.assertFalse(b1.equals(b9));
106-
107-
Assert.assertFalse(b3.equals(b1));
108-
Assert.assertFalse(b4.equals(b1));
109-
Assert.assertFalse(b5.equals(b1));
110-
Assert.assertFalse(b6.equals(b1));
111-
Assert.assertFalse(b7.equals(b1));
112-
Assert.assertFalse(b8.equals(b1));
113-
Assert.assertFalse(b9.equals(b1));
86+
assertEquals(b1.hashCode(),b2.hashCode());
87+
assertTrue(b1.hashCode()!=b3.hashCode());
88+
assertTrue(b1.hashCode()!=b4.hashCode());
89+
assertTrue(b1.hashCode()!=b5.hashCode());
90+
assertTrue(b1.hashCode()!=b6.hashCode());
91+
assertTrue(b1.hashCode()!=b7.hashCode());
92+
assertTrue(b1.hashCode()!=b8.hashCode());
93+
assertTrue(b1.hashCode()!=b9.hashCode());
94+
95+
assertTrue(b1.equals(b1));
96+
assertTrue(b1.equals(b2));
97+
98+
assertFalse(b1.equals(null));
99+
assertFalse(b1.equals(account1));
100+
assertFalse(b1.equals(b3));
101+
assertFalse(b1.equals(b4));
102+
assertFalse(b1.equals(b5));
103+
assertFalse(b1.equals(b6));
104+
assertFalse(b1.equals(b7));
105+
assertFalse(b1.equals(b8));
106+
assertFalse(b1.equals(b9));
107+
108+
assertFalse(b3.equals(b1));
109+
assertFalse(b4.equals(b1));
110+
assertFalse(b5.equals(b1));
111+
assertFalse(b6.equals(b1));
112+
assertFalse(b7.equals(b1));
113+
assertFalse(b8.equals(b1));
114+
assertFalse(b9.equals(b1));
114115
}
115116
}

src/test/java/org/woehlke/simpleworklist/user/account/UserAccountFormTest.java renamed to src/test/java/org/woehlke/simpleworklist/user/account/UserAccountPasswordEncodedTest.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package org.woehlke.simpleworklist.user.account;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.security.crypto.password.PasswordEncoder;
56
import org.woehlke.simpleworklist.AbstractTest;
67

78
import org.springframework.beans.factory.annotation.Autowired;
8-
import org.woehlke.simpleworklist.user.account.UserAccountForm;
99

10+
import static org.junit.jupiter.api.Assertions.assertFalse;
11+
import static org.junit.jupiter.api.Assertions.assertTrue;
1012

11-
public class UserAccountFormTest extends AbstractTest {
1213

14+
public class UserAccountPasswordEncodedTest extends AbstractTest {
1315

1416
@Autowired
15-
private org.springframework.security.crypto.password.PasswordEncoder encoder;
17+
private PasswordEncoder encoder;
18+
19+
@Test
20+
public void testEncoderIsWired(){
21+
assertTrue(encoder != null);
22+
}
1623

1724
/**
1825
* This Test is obsolete now due to changed encoder from MD5 to BCrypt (20.02.2016).
@@ -25,7 +32,7 @@ public void testGetUserPasswordEncoded(){
2532
u.setUserPassword("pwd01_ASDFGHJKLMOP_22");
2633
u.setUserPasswordConfirmation("pwd01_ASDFGHJKLMOP_22");
2734
String encodedPassword = encoder.encode(u.getUserPassword());
28-
Assert.assertTrue(encodedPassword.compareTo(encoder.encode(u.getUserPassword()))==0);
35+
assertTrue(encodedPassword.compareTo(encoder.encode(u.getUserPassword()))==0);
2936
}
3037

3138
@Test
@@ -35,8 +42,8 @@ public void testPasswordsAreTheSame(){
3542
u.setUserFullname("some_name");
3643
u.setUserPassword("pwd01_ASDFGHJKLMOP_22");
3744
u.setUserPasswordConfirmation("pwd01_ASDFGHJKLMOP_22");
38-
Assert.assertTrue(u.passwordsAreTheSame());
45+
assertTrue(u.passwordsAreTheSame());
3946
u.setUserPasswordConfirmation("pwd01_ASDFGHJKLMOP_23");
40-
Assert.assertFalse(u.passwordsAreTheSame());
47+
assertFalse(u.passwordsAreTheSame());
4148
}
4249
}

0 commit comments

Comments
 (0)