Skip to content

Commit 348a348

Browse files
committed
work: Unit Tests and Integration Tests
1 parent 3b8220e commit 348a348

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2210
-6
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,91 @@
11
package org.woehlke.java.simpleworklist.domain;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.jupiter.api.*;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
7+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.web.server.LocalServerPort;
11+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
12+
import org.springframework.context.annotation.Import;
13+
import org.springframework.security.core.context.SecurityContextHolder;
14+
import org.springframework.test.web.servlet.MockMvc;
15+
import org.woehlke.java.simpleworklist.SimpleworklistApplication;
16+
import org.woehlke.java.simpleworklist.config.SimpleworklistProperties;
17+
import org.woehlke.java.simpleworklist.config.UserAccountTestDataService;
18+
import org.woehlke.java.simpleworklist.config.WebMvcConfig;
19+
import org.woehlke.java.simpleworklist.config.WebSecurityConfig;
20+
21+
import java.net.URL;
22+
23+
@Slf4j
24+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
25+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
26+
@AutoConfigureMockMvc
27+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
28+
@Import(SimpleworklistApplication.class)
29+
@ImportAutoConfiguration({
30+
WebMvcConfig.class,
31+
WebSecurityConfig.class
32+
})
33+
@EnableConfigurationProperties({
34+
SimpleworklistProperties.class
35+
})
336
public class ApplicationErrorControllerIT {
37+
38+
@Autowired
39+
private ServletWebServerApplicationContext server;
40+
41+
@Autowired
42+
private MockMvc mockMvc;
43+
44+
@SuppressWarnings("deprecation")
45+
@LocalServerPort
46+
private int port;
47+
48+
@Autowired
49+
private UserAccountTestDataService userAccountTestDataService;
50+
51+
private final String eyecatcherH1 = "##################################################################";
52+
private final String eyecatcherH2 = "------------------------------------------------------------------";
53+
private final String eyecatcherH3 = "******************************************************************";
54+
55+
@BeforeEach
56+
public void setUp() throws Exception {
57+
log.info(eyecatcherH1);
58+
log.info(" @BeforeEach setUp()");
59+
log.info(eyecatcherH2);
60+
61+
//userAccountTestDataService.setUp();
62+
log.info(eyecatcherH1);
63+
}
64+
65+
@BeforeAll
66+
public void runBeforeTestClass() throws Exception {
67+
log.info(eyecatcherH1);
68+
log.info(" @BeforeTestClass runBeforeTestClass");
69+
log.info(eyecatcherH2);
70+
URL base = new URL("http://localhost:" + port + "/");
71+
log.info(" Server URL: " + base.toString());
72+
log.info(eyecatcherH2);
73+
userAccountTestDataService.setUp();
74+
log.info(eyecatcherH2);
75+
log.info(" @BeforeTestClass runBeforeTestClass");
76+
log.info(eyecatcherH1);
77+
}
78+
79+
@AfterAll
80+
public void runAfterTestClass() throws Exception {
81+
log.info(eyecatcherH1);
82+
log.info(" @AfterTestClass clearContext");
83+
log.info(eyecatcherH2);
84+
URL base = new URL("http://localhost:" + port + "/");
85+
log.info(" Server URL: " + base.toString());
86+
log.info(eyecatcherH2);
87+
SecurityContextHolder.clearContext();
88+
log.info(eyecatcherH1);
89+
}
90+
491
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,90 @@
11
package org.woehlke.java.simpleworklist.domain;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.jupiter.api.*;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
7+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.web.server.LocalServerPort;
11+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
12+
import org.springframework.context.annotation.Import;
13+
import org.springframework.security.core.context.SecurityContextHolder;
14+
import org.springframework.test.web.servlet.MockMvc;
15+
import org.woehlke.java.simpleworklist.SimpleworklistApplication;
16+
import org.woehlke.java.simpleworklist.config.SimpleworklistProperties;
17+
import org.woehlke.java.simpleworklist.config.UserAccountTestDataService;
18+
import org.woehlke.java.simpleworklist.config.WebMvcConfig;
19+
import org.woehlke.java.simpleworklist.config.WebSecurityConfig;
20+
21+
import java.net.URL;
22+
23+
@Slf4j
24+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
25+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
26+
@AutoConfigureMockMvc
27+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
28+
@Import(SimpleworklistApplication.class)
29+
@ImportAutoConfiguration({
30+
WebMvcConfig.class,
31+
WebSecurityConfig.class
32+
})
33+
@EnableConfigurationProperties({
34+
SimpleworklistProperties.class
35+
})
336
public class ContextControllerIT {
37+
@Autowired
38+
private ServletWebServerApplicationContext server;
39+
40+
@Autowired
41+
private MockMvc mockMvc;
42+
43+
@SuppressWarnings("deprecation")
44+
@LocalServerPort
45+
private int port;
46+
47+
@Autowired
48+
private UserAccountTestDataService userAccountTestDataService;
49+
50+
private final String eyecatcherH1 = "##################################################################";
51+
private final String eyecatcherH2 = "------------------------------------------------------------------";
52+
private final String eyecatcherH3 = "******************************************************************";
53+
54+
@BeforeEach
55+
public void setUp() throws Exception {
56+
log.info(eyecatcherH1);
57+
log.info(" @BeforeEach setUp()");
58+
log.info(eyecatcherH2);
59+
60+
//userAccountTestDataService.setUp();
61+
log.info(eyecatcherH1);
62+
}
63+
64+
@BeforeAll
65+
public void runBeforeTestClass() throws Exception {
66+
log.info(eyecatcherH1);
67+
log.info(" @BeforeTestClass runBeforeTestClass");
68+
log.info(eyecatcherH2);
69+
URL base = new URL("http://localhost:" + port + "/");
70+
log.info(" Server URL: " + base.toString());
71+
log.info(eyecatcherH2);
72+
userAccountTestDataService.setUp();
73+
log.info(eyecatcherH2);
74+
log.info(" @BeforeTestClass runBeforeTestClass");
75+
log.info(eyecatcherH1);
76+
}
77+
78+
@AfterAll
79+
public void runAfterTestClass() throws Exception {
80+
log.info(eyecatcherH1);
81+
log.info(" @AfterTestClass clearContext");
82+
log.info(eyecatcherH2);
83+
URL base = new URL("http://localhost:" + port + "/");
84+
log.info(" Server URL: " + base.toString());
85+
log.info(eyecatcherH2);
86+
SecurityContextHolder.clearContext();
87+
log.info(eyecatcherH1);
88+
}
89+
490
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,90 @@
11
package org.woehlke.java.simpleworklist.domain;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.jupiter.api.*;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
7+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.web.server.LocalServerPort;
11+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
12+
import org.springframework.context.annotation.Import;
13+
import org.springframework.security.core.context.SecurityContextHolder;
14+
import org.springframework.test.web.servlet.MockMvc;
15+
import org.woehlke.java.simpleworklist.SimpleworklistApplication;
16+
import org.woehlke.java.simpleworklist.config.SimpleworklistProperties;
17+
import org.woehlke.java.simpleworklist.config.UserAccountTestDataService;
18+
import org.woehlke.java.simpleworklist.config.WebMvcConfig;
19+
import org.woehlke.java.simpleworklist.config.WebSecurityConfig;
20+
21+
import java.net.URL;
22+
23+
@Slf4j
24+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
25+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
26+
@AutoConfigureMockMvc
27+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
28+
@Import(SimpleworklistApplication.class)
29+
@ImportAutoConfiguration({
30+
WebMvcConfig.class,
31+
WebSecurityConfig.class
32+
})
33+
@EnableConfigurationProperties({
34+
SimpleworklistProperties.class
35+
})
336
public class PagesControllerIT {
37+
@Autowired
38+
private ServletWebServerApplicationContext server;
39+
40+
@Autowired
41+
private MockMvc mockMvc;
42+
43+
@SuppressWarnings("deprecation")
44+
@LocalServerPort
45+
private int port;
46+
47+
@Autowired
48+
private UserAccountTestDataService userAccountTestDataService;
49+
50+
private final String eyecatcherH1 = "##################################################################";
51+
private final String eyecatcherH2 = "------------------------------------------------------------------";
52+
private final String eyecatcherH3 = "******************************************************************";
53+
54+
@BeforeEach
55+
public void setUp() throws Exception {
56+
log.info(eyecatcherH1);
57+
log.info(" @BeforeEach setUp()");
58+
log.info(eyecatcherH2);
59+
60+
//userAccountTestDataService.setUp();
61+
log.info(eyecatcherH1);
62+
}
63+
64+
@BeforeAll
65+
public void runBeforeTestClass() throws Exception {
66+
log.info(eyecatcherH1);
67+
log.info(" @BeforeTestClass runBeforeTestClass");
68+
log.info(eyecatcherH2);
69+
URL base = new URL("http://localhost:" + port + "/");
70+
log.info(" Server URL: " + base.toString());
71+
log.info(eyecatcherH2);
72+
userAccountTestDataService.setUp();
73+
log.info(eyecatcherH2);
74+
log.info(" @BeforeTestClass runBeforeTestClass");
75+
log.info(eyecatcherH1);
76+
}
77+
78+
@AfterAll
79+
public void runAfterTestClass() throws Exception {
80+
log.info(eyecatcherH1);
81+
log.info(" @AfterTestClass clearContext");
82+
log.info(eyecatcherH2);
83+
URL base = new URL("http://localhost:" + port + "/");
84+
log.info(" Server URL: " + base.toString());
85+
log.info(eyecatcherH2);
86+
SecurityContextHolder.clearContext();
87+
log.info(eyecatcherH1);
88+
}
89+
490
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,90 @@
11
package org.woehlke.java.simpleworklist.domain;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.jupiter.api.*;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
7+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.web.server.LocalServerPort;
11+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
12+
import org.springframework.context.annotation.Import;
13+
import org.springframework.security.core.context.SecurityContextHolder;
14+
import org.springframework.test.web.servlet.MockMvc;
15+
import org.woehlke.java.simpleworklist.SimpleworklistApplication;
16+
import org.woehlke.java.simpleworklist.config.SimpleworklistProperties;
17+
import org.woehlke.java.simpleworklist.config.UserAccountTestDataService;
18+
import org.woehlke.java.simpleworklist.config.WebMvcConfig;
19+
import org.woehlke.java.simpleworklist.config.WebSecurityConfig;
20+
21+
import java.net.URL;
22+
23+
@Slf4j
24+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
25+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
26+
@AutoConfigureMockMvc
27+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
28+
@Import(SimpleworklistApplication.class)
29+
@ImportAutoConfiguration({
30+
WebMvcConfig.class,
31+
WebSecurityConfig.class
32+
})
33+
@EnableConfigurationProperties({
34+
SimpleworklistProperties.class
35+
})
336
public class ProjectControllerIT {
37+
@Autowired
38+
private ServletWebServerApplicationContext server;
39+
40+
@Autowired
41+
private MockMvc mockMvc;
42+
43+
@SuppressWarnings("deprecation")
44+
@LocalServerPort
45+
private int port;
46+
47+
@Autowired
48+
private UserAccountTestDataService userAccountTestDataService;
49+
50+
private final String eyecatcherH1 = "##################################################################";
51+
private final String eyecatcherH2 = "------------------------------------------------------------------";
52+
private final String eyecatcherH3 = "******************************************************************";
53+
54+
@BeforeEach
55+
public void setUp() throws Exception {
56+
log.info(eyecatcherH1);
57+
log.info(" @BeforeEach setUp()");
58+
log.info(eyecatcherH2);
59+
60+
//userAccountTestDataService.setUp();
61+
log.info(eyecatcherH1);
62+
}
63+
64+
@BeforeAll
65+
public void runBeforeTestClass() throws Exception {
66+
log.info(eyecatcherH1);
67+
log.info(" @BeforeTestClass runBeforeTestClass");
68+
log.info(eyecatcherH2);
69+
URL base = new URL("http://localhost:" + port + "/");
70+
log.info(" Server URL: " + base.toString());
71+
log.info(eyecatcherH2);
72+
userAccountTestDataService.setUp();
73+
log.info(eyecatcherH2);
74+
log.info(" @BeforeTestClass runBeforeTestClass");
75+
log.info(eyecatcherH1);
76+
}
77+
78+
@AfterAll
79+
public void runAfterTestClass() throws Exception {
80+
log.info(eyecatcherH1);
81+
log.info(" @AfterTestClass clearContext");
82+
log.info(eyecatcherH2);
83+
URL base = new URL("http://localhost:" + port + "/");
84+
log.info(" Server URL: " + base.toString());
85+
log.info(eyecatcherH2);
86+
SecurityContextHolder.clearContext();
87+
log.info(eyecatcherH1);
88+
}
89+
490
}

0 commit comments

Comments
 (0)