Skip to content

Commit e50d355

Browse files
authored
Upgrade to Spring Boot 4 (#183)
Upgrade to Spring Boot 4, address breaking changes: - rest docs tests needed to be migrated to mockmvc - jackson is updated with breaking api changes Resolves gardenlinux/glvd#203
1 parent 5db4b2e commit e50d355

File tree

6 files changed

+346
-419
lines changed

6 files changed

+346
-419
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ updates:
44
directory: '/'
55
schedule:
66
interval: 'weekly'
7-
ignore:
8-
- dependency-name: "*"
9-
update-types: ["version-update:semver-major"]
107

118
- package-ecosystem: 'github-actions'
129
directory: '/'

build.gradle

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.5.9'
3+
id 'org.springframework.boot' version '4.0.1'
44
id 'io.spring.dependency-management' version '1.1.7'
55
id 'org.asciidoctor.jvm.convert' version '4.0.5'
66
}
@@ -17,42 +17,48 @@ repositories {
1717
}
1818

1919
ext {
20-
set('snippetsDir', file("build/generated-snippets"))
20+
set('snippetsDir', file('build/generated-snippets'))
2121
}
2222

2323
configurations {
2424
asciidoctorExtensions
2525
}
2626

27+
asciidoctorj {
28+
version = '3.0.0'
29+
}
30+
2731
dependencies {
2832
asciidoctorExtensions 'org.springframework.restdocs:spring-restdocs-asciidoctor'
2933
implementation 'org.springframework.boot:spring-boot-starter-actuator'
3034
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
3135
implementation 'org.springframework.boot:spring-boot-starter-web'
32-
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.15'
36+
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
3337
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
3438
implementation 'org.commonmark:commonmark:0.27.0'
39+
implementation 'org.apache.commons:commons-lang3:3.20.0'
3540
runtimeOnly 'org.postgresql:postgresql'
3641
testImplementation 'org.springframework.boot:spring-boot-starter-test'
37-
testImplementation 'org.springframework.restdocs:spring-restdocs-restassured'
38-
testImplementation 'io.rest-assured:rest-assured:5.5.6'
39-
testImplementation 'org.junit.jupiter:junit-jupiter:6.0.1'
42+
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
43+
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
44+
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
4045
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
4146
}
4247

4348
tasks.named('test') {
44-
outputs.dir snippetsDir
4549
useJUnitPlatform()
50+
outputs.dir snippetsDir
4651
}
4752

4853
tasks.named('asciidoctor') {
49-
configurations "asciidoctorExtensions"
54+
configurations 'asciidoctorExtensions'
5055
inputs.dir snippetsDir
5156
dependsOn test
5257
}
53-
bootJar {
58+
59+
tasks.named('bootJar') {
5460
dependsOn asciidoctor
55-
from("${asciidoctor.outputDir}/html5") {
61+
from("${asciidoctor.outputDir}") {
5662
into 'static/docs'
5763
}
5864
}

src/main/java/io/gardenlinux/glvd/db/NvdCveDataAttributeConverter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package io.gardenlinux.glvd.db;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
53
import jakarta.persistence.AttributeConverter;
64
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
6+
import tools.jackson.core.JacksonException;
7+
import tools.jackson.databind.json.JsonMapper;
88

99
public class NvdCveDataAttributeConverter implements AttributeConverter<NvdCve.Data, String> {
10-
private static final ObjectMapper objectMapper = new ObjectMapper();
10+
private static final JsonMapper objectMapper = new JsonMapper();
1111
Logger logger = LoggerFactory.getLogger(NvdCveDataAttributeConverter.class);
1212

1313
@Override
1414
public String convertToDatabaseColumn(NvdCve.Data attribute) {
1515
try {
1616
return objectMapper.writeValueAsString(attribute);
17-
} catch (JsonProcessingException jpe) {
17+
} catch (JacksonException jpe) {
1818
logger.warn("Cannot convert CVE Data into JSON");
1919
return null;
2020
}
@@ -24,7 +24,7 @@ public String convertToDatabaseColumn(NvdCve.Data attribute) {
2424
public NvdCve.Data convertToEntityAttribute(String dbData) {
2525
try {
2626
return objectMapper.readValue(dbData, NvdCve.Data.class);
27-
} catch (JsonProcessingException e) {
27+
} catch (JacksonException e) {
2828
logger.warn("Cannot convert JSON into CVE Data {}", dbData);
2929
return null;
3030
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
spring.application.name=glvd
22
spring.datasource.url=jdbc:postgresql://localhost:5432/glvd
3+
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
34
spring.datasource.username=glvd
45
spring.datasource.password=glvd
56
spring.sql.init.mode=never
67
jakarta.persistence.query.timeout=5000
78
server.error.whitelabel.enabled=false
89
management.endpoints.access.default=none
9-
management.endpoint.health.access=read-only
10+
management.endpoint.health.access=read-only
Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
11
package io.gardenlinux.glvd;
22

3-
import io.restassured.RestAssured;
4-
import io.restassured.builder.RequestSpecBuilder;
5-
import io.restassured.specification.RequestSpecification;
6-
import org.apache.http.HttpStatus;
73
import org.junit.jupiter.api.BeforeEach;
84
import org.junit.jupiter.api.Test;
9-
import org.junit.jupiter.api.extension.ExtendWith;
105
import org.junit.jupiter.params.ParameterizedTest;
116
import org.junit.jupiter.params.provider.ValueSource;
7+
import org.springframework.beans.factory.annotation.Autowired;
128
import org.springframework.boot.test.context.SpringBootTest;
13-
import org.springframework.boot.test.web.server.LocalServerPort;
14-
import org.springframework.test.context.junit.jupiter.SpringExtension;
9+
import org.springframework.test.web.servlet.MockMvc;
10+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
11+
import org.springframework.web.context.WebApplicationContext;
1512

16-
import static io.restassured.RestAssured.given;
1713
import static org.hamcrest.Matchers.is;
14+
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
16+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1817

19-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
20-
@ExtendWith({SpringExtension.class})
21-
public class ActuatorEndpointTests {
18+
@SpringBootTest
19+
class ActuatorEndpointTests {
2220

23-
@LocalServerPort
24-
private Integer port;
21+
@Autowired
22+
private WebApplicationContext context;
2523

26-
private RequestSpecification spec;
24+
private MockMvc mockMvc;
2725

28-
@BeforeEach
29-
void setUp() {
30-
this.spec = new RequestSpecBuilder().build();
31-
32-
RestAssured.baseURI = "http://localhost:" + port;
33-
}
26+
@BeforeEach
27+
public void setUp() {
28+
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
29+
}
3430

3531
// We want to use actuator for k8s liveness and readiness probes
36-
@Test
37-
public void shouldReturnHealth() {
38-
given(this.spec).accept("application/json")
39-
.when().port(this.port).get("/actuator/health")
40-
.then().statusCode(HttpStatus.SC_OK)
41-
.body("status", is("UP"));
42-
}
32+
@Test
33+
void shouldReturnHealth() throws Exception {
34+
this.mockMvc.perform(get("/actuator/health"))
35+
.andExpect(status().isOk())
36+
.andExpect(jsonPath("status", is("UP")));
37+
}
4338

4439
@ParameterizedTest
4540
@ValueSource(strings = {"prometheus", "metrics", "env", "heapdump", "beans", "loggers", "mappings", "shutdown"})
46-
public void shouldNotReturnSensitiveEndpoints(String endpoint) {
47-
given(this.spec).accept("application/json")
48-
.when().port(this.port).get("/actuator/" + endpoint)
49-
.then().statusCode(HttpStatus.SC_NOT_FOUND)
50-
.body("path", is("/actuator/" + endpoint));
41+
public void shouldNotReturnSensitiveEndpoints(String endpoint) throws Exception {
42+
this.mockMvc.perform(get("/actuator/" + endpoint))
43+
.andExpect(status().isNotFound())
44+
.andExpect(status().reason("No static resource actuator/" + endpoint + "."));
5145
}
5246

5347
}

0 commit comments

Comments
 (0)