11package org .woehlke .simpleworklist ;
22
33import lombok .extern .slf4j .Slf4j ;
4+ import org .junit .AfterClass ;
5+ import org .junit .BeforeClass ;
6+ import org .junit .jupiter .api .BeforeEach ;
47import 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 ;
511import org .springframework .boot .test .context .SpringBootTest ;
12+ import org .springframework .boot .test .web .client .TestRestTemplate ;
613import org .springframework .boot .web .server .LocalServerPort ;
714import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
815import org .springframework .security .core .Authentication ;
916import org .springframework .security .core .context .SecurityContextHolder ;
1017import org .springframework .security .core .userdetails .UserDetails ;
11- import org .springframework .test .context .ContextConfiguration ;
1218import org .springframework .test .context .event .annotation .AfterTestClass ;
1319import org .springframework .test .context .event .annotation .BeforeTestClass ;
1420import org .springframework .test .web .servlet .MockMvc ;
2430import org .woehlke .simpleworklist .user .login .UserAccountLoginSuccessService ;
2531
2632
33+ import java .net .URL ;
34+
2735import 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})
3848public 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