Skip to content

Commit 5703335

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

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@
362362
<dependency>
363363
<groupId>org.springframework.boot</groupId>
364364
<artifactId>spring-boot-starter-test</artifactId>
365+
<scope>test</scope>
366+
<exclusions>
367+
<exclusion>
368+
<groupId>org.junit.vintage</groupId>
369+
<artifactId>junit-vintage-engine</artifactId>
370+
</exclusion>
371+
</exclusions>
365372
</dependency>
366373
<dependency>
367374
<groupId>org.springframework.security</groupId>

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

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package org.woehlke.simpleworklist;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.AfterClass;
5+
import org.junit.BeforeClass;
6+
import org.junit.jupiter.api.BeforeEach;
47
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
9+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
10+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
511
import org.springframework.boot.test.context.SpringBootTest;
12+
import org.springframework.boot.test.web.client.TestRestTemplate;
613
import org.springframework.boot.web.server.LocalServerPort;
714
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
815
import org.springframework.security.core.Authentication;
916
import org.springframework.security.core.context.SecurityContextHolder;
1017
import org.springframework.security.core.userdetails.UserDetails;
11-
import org.springframework.test.context.ContextConfiguration;
1218
import org.springframework.test.context.event.annotation.AfterTestClass;
1319
import org.springframework.test.context.event.annotation.BeforeTestClass;
1420
import org.springframework.test.web.servlet.MockMvc;
@@ -24,33 +30,40 @@
2430
import org.woehlke.simpleworklist.user.login.UserAccountLoginSuccessService;
2531

2632

33+
import java.net.URL;
34+
2735
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
2836

2937

3038
@Slf4j
39+
@AutoConfigureMockMvc
3140
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
32-
@ContextConfiguration(classes={
33-
SimpleworklistApplication.class,
41+
@ImportAutoConfiguration({
3442
WebMvcConfig.class,
35-
WebSecurityConfig.class,
43+
WebSecurityConfig.class
44+
})
45+
@EnableConfigurationProperties({
3646
ApplicationProperties.class
3747
})
3848
public abstract class AbstractTest {
3949

40-
@Autowired
41-
protected WebApplicationContext wac;
42-
4350
@LocalServerPort
44-
int randomServerPort;
51+
protected int port;
52+
53+
protected URL base;
4554

4655
@Autowired
4756
protected ApplicationProperties applicationProperties;
4857

58+
@Autowired
59+
protected WebApplicationContext wac;
4960

5061
protected MockMvc mockMvc;
5162

52-
@BeforeTestClass
53-
public void setup() throws Exception {
63+
@BeforeEach
64+
public void setUp() throws Exception {
65+
log.info(" @BeforeEach ");
66+
this.base = new URL("http://localhost:" + port + "/");
5467
this.mockMvc = webAppContextSetup(wac).build();
5568
for (UserAccount u : testUser) {
5669
UserAccount a = userAccountService.findByUserEmail(u.getUserEmail());
@@ -60,26 +73,17 @@ public void setup() throws Exception {
6073
}
6174
}
6275

76+
@BeforeTestClass
77+
public void setupClass() throws Exception {
78+
log.info(" @BeforeTestClass ");
79+
}
80+
6381
@AfterTestClass
6482
public void clearContext() {
83+
log.info(" @AfterTestClass ");
6584
SecurityContextHolder.clearContext();
6685
}
6786

68-
@Autowired
69-
protected TestHelperService testHelperService;
70-
71-
@Autowired
72-
protected UserAccountService userAccountService;
73-
74-
@Autowired
75-
protected UserAccountSecurityService userAccountSecurityService;
76-
77-
@Autowired
78-
protected UserAccountAccessService userAccountAccessService;
79-
80-
@Autowired
81-
protected UserAccountLoginSuccessService userAccountLoginSuccessService;
82-
8387
protected static String[] emails = {"test01@test.de", "test02@test.de", "test03@test.de"};
8488
protected static String[] passwords = {"test01pwd", "test02pwd", "test03pwd"};
8589
protected static String[] fullnames = {"test01 Name", "test02 Name", "test03 Name"};
@@ -112,4 +116,19 @@ protected void deleteAll(){
112116
testHelperService.deleteUserAccount();
113117
}
114118

119+
@Autowired
120+
protected TestHelperService testHelperService;
121+
122+
@Autowired
123+
protected UserAccountService userAccountService;
124+
125+
@Autowired
126+
protected UserAccountSecurityService userAccountSecurityService;
127+
128+
@Autowired
129+
protected UserAccountAccessService userAccountAccessService;
130+
131+
@Autowired
132+
protected UserAccountLoginSuccessService userAccountLoginSuccessService;
133+
115134
}

0 commit comments

Comments
 (0)