Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 8cd65f6

Browse files
update and fix issues
1 parent 49b2f85 commit 8cd65f6

File tree

10 files changed

+54
-67
lines changed

10 files changed

+54
-67
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,3 @@ updates:
44
directory: "/"
55
schedule:
66
interval: daily
7-
open-pull-requests-limit: 10
8-
ignore:
9-
- dependency-name: org.springframework.boot:spring-boot-gradle-plugin
10-
versions:
11-
- 2.4.2
12-
- 2.4.3
13-
- 2.4.4
14-
- dependency-name: org.webjars:bootstrap
15-
versions:
16-
- 4.6.0
17-
- dependency-name: org.webjars:jquery
18-
versions:
19-
- 3.5.1

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.4.5'
2+
id 'org.springframework.boot' version '2.5.2'
33
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
44
id 'java'
55
id 'jacoco'
@@ -28,8 +28,9 @@ dependencies {
2828
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
2929
implementation 'org.springframework.boot:spring-boot-starter-validation'
3030
implementation 'org.springframework.boot:spring-boot-starter-web'
31-
implementation 'org.webjars:bootstrap:3.3.7'
32-
implementation 'org.webjars:jquery:2.2.4'
31+
implementation 'org.webjars:webjars-locator-core'
32+
implementation 'org.webjars:bootstrap:4.6.0-1'
33+
implementation 'org.webjars:jquery:3.6.0'
3334
compileOnly 'org.projectlombok:lombok'
3435
developmentOnly 'org.springframework.boot:spring-boot-devtools'
3536
runtimeOnly 'com.h2database:h2'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/com/example/DemoApplication.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import org.springframework.boot.builder.SpringApplicationBuilder;
6-
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
75

86
@SpringBootApplication
9-
public class DemoApplication extends SpringBootServletInitializer {
10-
11-
@Override
12-
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
13-
return application.sources(DemoApplication.class);
14-
}
7+
public class DemoApplication {
158

169
public static void main(String[] args) {
1710
SpringApplication.run(DemoApplication.class, args);

src/main/java/com/example/web/config/WebMvcConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.web.config;
22

33
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
45
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
56
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
67

@@ -15,4 +16,13 @@ public void addViewControllers(ViewControllerRegistry registry)
1516
registry.addRedirectViewController("/", "/home");
1617
}
1718

19+
@Override
20+
public void addCorsMappings(CorsRegistry registry) {
21+
registry.addMapping("/admin/**")
22+
.allowedMethods("*")
23+
.allowedHeaders("*")
24+
.allowedOriginPatterns("*")
25+
.allowCredentials(true);
26+
}
27+
1828
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
spring.jpa.show-sql=true
22
spring.jpa.database=h2
33
spring.jpa.open-in-view=false
4+
spring.jpa.defer-datasource-initialization=true
45

56
logging.level.com.example=debug
67
logging.level.org.springframework.security=info

src/main/resources/templates/layout/common-layout.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
content="width=device-width, initial-scale=1, maximum-scale=1" />
1313
<!-- Bootstrap core CSS/JS -->
1414
<link
15-
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
16-
th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"
15+
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
1716
rel="stylesheet" media="screen" />
1817
<!--[if lt IE 9]>
1918
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
@@ -100,11 +99,9 @@
10099
<!-- script references -->
101100
<!--Caution: Include jquery before bootstrap js :D -->
102101
<script
103-
src="http://cdn.jsdelivr.net/webjars/jquery/2.2.4/jquery.min.js"
104-
th:src="@{/webjars/jquery/2.2.4/jquery.min.js}"></script>
102+
th:src="@{/webjars/jquery/jquery.min.js}"></script>
105103
<script type="text/javascript"
106-
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
107-
th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
104+
th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
108105
<script src="../../../js/custom-scripts.js"
109106
th:src="@{/js/custom-scripts.js}"></script>
110107

src/main/resources/templates/login.html

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
<!-- Bootstrap core CSS/JS -->
1313
<link
14-
href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7/css/bootstrap.min.css"
15-
th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"
14+
th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"
1615
rel="stylesheet" media="screen" />
1716

1817

@@ -21,18 +20,10 @@
2120
th:href="@{/css/signin-layout.css}" rel="stylesheet" />
2221

2322
<!--Caution: Include jquery before bootstrap js :D -->
24-
<script src="http://cdn.jsdelivr.net/webjars/jquery/2.2.4/jquery.min.js"
25-
th:src="@{/webjars/jquery/2.2.4/jquery.min.js}"></script>
23+
<script th:src="@{/webjars/jquery/jquery.min.js}"></script>
2624
<script type="text/javascript"
27-
src="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7/js/bootstrap.min.js"
28-
th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
25+
th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
2926

30-
31-
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
32-
<!--[if lt IE 9]>
33-
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
34-
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
35-
<![endif]-->
3627
</head>
3728

3829
<body>

src/test/java/com/example/DemoApplicationTests.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
package com.example;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
5-
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
6-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
7-
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
8-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
9-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
10-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
11-
12-
import java.util.Arrays;
13-
import java.util.Collections;
14-
import java.util.List;
15-
import java.util.Map;
16-
import java.util.regex.Matcher;
17-
import java.util.regex.Pattern;
18-
193
import org.junit.jupiter.api.BeforeAll;
204
import org.junit.jupiter.api.Test;
215
import org.junit.jupiter.api.TestInstance;
@@ -40,6 +24,22 @@
4024
import org.springframework.util.MultiValueMap;
4125
import org.springframework.web.context.WebApplicationContext;
4226

27+
import java.util.Arrays;
28+
import java.util.Collections;
29+
import java.util.List;
30+
import java.util.Map;
31+
import java.util.regex.Matcher;
32+
import java.util.regex.Pattern;
33+
34+
import static org.assertj.core.api.Assertions.assertThat;
35+
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
36+
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
37+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
38+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
39+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
40+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
41+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
42+
4343
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
4444
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4545
public class DemoApplicationTests {
@@ -95,11 +95,11 @@ public void testLoginMvc() throws Exception {
9595
}
9696

9797
@Test
98-
public void testLogin() throws Exception {
98+
public void testLogin() {
9999
HttpHeaders headers = getHeaders();
100100
headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
101101
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
102-
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
102+
MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
103103
form.set("j_username", "admin");
104104
form.set("j_password", getPassword());
105105
form.set("remember-me", "true");
@@ -138,10 +138,10 @@ public void testDenied() throws Exception {
138138
}
139139

140140
@Test
141-
public void testManagementProtected() throws Exception {
141+
public void testManagementProtected() {
142142
ResponseEntity<String> entity = this.testRestTemplate.getForEntity("/actuator/beans",
143143
String.class);
144-
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
144+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
145145
}
146146

147147
@Test
@@ -182,7 +182,7 @@ public void testManagementUnauthorizedAccess() throws Exception {
182182
@Test
183183
public void testCss() throws Exception {
184184
ResponseEntity<String> entity = this.testRestTemplate
185-
.getForEntity("/webjars/bootstrap/3.3.6/css/bootstrap.min.css", String.class);
185+
.getForEntity("/webjars/bootstrap/css/bootstrap.min.css", String.class);
186186
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
187187
assertThat(entity.getBody()).contains("body");
188188
}
@@ -253,7 +253,7 @@ public void testMetrics() throws Exception {
253253
}
254254

255255
@Test
256-
public void testEnv() throws Exception {
256+
public void testEnv() {
257257
@SuppressWarnings("rawtypes")
258258
ResponseEntity<Map> entity = this.testRestTemplate
259259
.withBasicAuth("admin", getPassword()).getForEntity("/actuator/env", Map.class);
@@ -264,7 +264,7 @@ public void testEnv() throws Exception {
264264
}
265265

266266
@Test
267-
public void testHealth() throws Exception {
267+
public void testHealth() {
268268
ResponseEntity<String> entity = this.testRestTemplate.getForEntity("/actuator/health",
269269
String.class);
270270
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -273,7 +273,7 @@ public void testHealth() throws Exception {
273273
}
274274

275275
@Test
276-
public void testSecureHealth() throws Exception {
276+
public void testSecureHealth() {
277277
ResponseEntity<String> entity = this.testRestTemplate
278278
.withBasicAuth("admin", getPassword())
279279
.getForEntity("/actuator/health", String.class);

src/test/java/com/example/web/controller/UserControllerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.junit.jupiter.api.Test;
1515
import org.springframework.beans.factory.annotation.Autowired;
16+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1617
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
1718
import org.springframework.boot.test.mock.mockito.MockBean;
1819
import org.springframework.http.MediaType;
@@ -24,8 +25,11 @@
2425
import com.example.web.service.UserService;
2526
import com.fasterxml.jackson.databind.ObjectMapper;
2627

28+
import javax.sql.DataSource;
29+
2730
@WebMvcTest(controllers = UserController.class)
2831
@WithMockUser
32+
@AutoConfigureMockMvc(addFilters = false)
2933
public class UserControllerTest
3034
{
3135
@Autowired
@@ -37,6 +41,9 @@ public class UserControllerTest
3741
@MockBean
3842
UserService userService;
3943

44+
@MockBean
45+
DataSource dataSource;
46+
4047
@Test
4148
public void testGetUserList() throws Exception
4249
{

0 commit comments

Comments
 (0)