Skip to content

Commit c7ee03c

Browse files
authored
Merge pull request #9 from lfir/feat/spring-boot4
Update to Spring Boot 4
2 parents 6f7a7b4 + 41ce38d commit c7ee03c

11 files changed

Lines changed: 68 additions & 64 deletions

File tree

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.5.6</version>
8+
<version>4.0.0</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>cf.maybelambda</groupId>
1212
<artifactId>http-validator</artifactId>
13-
<version>3.0.2</version>
13+
<version>3.0.3</version>
1414
<name>http-validator</name>
1515
<description>Retrieves target HTTP resources and responses, validates them and notifies about their current status.</description>
1616

@@ -27,21 +27,21 @@
2727
</dependency>
2828
<dependency>
2929
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-test</artifactId>
30+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
3131
<scope>test</scope>
3232
</dependency>
3333
<!-- https://mvnrepository.com/artifact/org.springframework.restdocs/spring-restdocs-mockmvc -->
3434
<dependency>
3535
<groupId>org.springframework.restdocs</groupId>
3636
<artifactId>spring-restdocs-mockmvc</artifactId>
37-
<version>3.0.5</version>
37+
<version>4.0.0</version>
3838
<scope>test</scope>
3939
</dependency>
4040
<!-- https://mvnrepository.com/artifact/com.mailgun/mailgun-java -->
4141
<dependency>
4242
<groupId>com.mailgun</groupId>
4343
<artifactId>mailgun-java</artifactId>
44-
<version>2.1.0</version>
44+
<version>2.1.1</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>io.jsonwebtoken</groupId>
@@ -78,7 +78,7 @@
7878
<plugin>
7979
<groupId>org.jacoco</groupId>
8080
<artifactId>jacoco-maven-plugin</artifactId>
81-
<version>0.8.13</version>
81+
<version>0.8.14</version>
8282
<executions>
8383
<execution>
8484
<id>default-prepare-agent</id>

src/main/java/cf/maybelambda/httpvalidator/springboot/model/ValidationTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cf.maybelambda.httpvalidator.springboot.model;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
3+
import tools.jackson.databind.JsonNode;
44

55
import javax.swing.text.html.FormSubmitEvent.MethodType;
66
import java.util.List;

src/main/java/cf/maybelambda/httpvalidator/springboot/persistence/XMLValidationTaskDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cf.maybelambda.httpvalidator.springboot.persistence;
22

33
import cf.maybelambda.httpvalidator.springboot.model.ValidationTask;
4-
import com.fasterxml.jackson.databind.JsonNode;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
64
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
86
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +13,8 @@
1513
import org.w3c.dom.Node;
1614
import org.w3c.dom.NodeList;
1715
import org.xml.sax.SAXException;
16+
import tools.jackson.databind.JsonNode;
17+
import tools.jackson.databind.ObjectMapper;
1818

1919
import javax.management.modelmbean.XMLParseException;
2020
import javax.swing.text.html.FormSubmitEvent.MethodType;

src/main/java/cf/maybelambda/httpvalidator/springboot/service/ValidationService.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import cf.maybelambda.httpvalidator.springboot.model.ValidationTask;
44
import cf.maybelambda.httpvalidator.springboot.persistence.XMLValidationTaskDao;
55
import cf.maybelambda.httpvalidator.springboot.util.HttpSendOutcomeWrapper;
6-
import com.fasterxml.jackson.core.JsonProcessingException;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
86
import org.slf4j.Logger;
97
import org.slf4j.LoggerFactory;
108
import org.springframework.beans.factory.annotation.Autowired;
119
import org.springframework.core.env.Environment;
1210
import org.springframework.scheduling.annotation.Scheduled;
1311
import org.springframework.scheduling.support.CronExpression;
1412
import org.springframework.stereotype.Service;
13+
import tools.jackson.core.JacksonException;
14+
import tools.jackson.databind.ObjectMapper;
1515

1616
import javax.management.modelmbean.XMLParseException;
1717
import java.io.FileNotFoundException;
@@ -70,8 +70,8 @@ public class ValidationService {
7070
*/
7171
public ValidationService() {
7272
this.client = HttpClient.newBuilder()
73-
.connectTimeout(CONNECT_TIMEOUT_SECONDS)
74-
.followRedirects(HttpClient.Redirect.ALWAYS).build();
73+
.connectTimeout(CONNECT_TIMEOUT_SECONDS)
74+
.followRedirects(HttpClient.Redirect.ALWAYS).build();
7575
}
7676

7777
/**
@@ -82,13 +82,13 @@ public ValidationService() {
8282
*
8383
* @throws FileNotFoundException if the data file is not found
8484
* @throws XMLParseException if there is an error parsing the XML file
85-
* @throws JsonProcessingException when a validation task contains invalid JSON content
85+
* @throws JacksonException when a validation task contains invalid JSON content
8686
* @throws ConnectIOException if there is an error sending notification email
8787
* @throws ExecutionException when an unhandled error occurs while processing the HTTP requests
8888
* @throws InterruptedException when interrupted before completing all the requests
8989
*/
9090
@Scheduled(cron = "${" + RUN_SCHEDULE_PROPERTY + "}")
91-
public void execValidations() throws FileNotFoundException, XMLParseException, JsonProcessingException,
91+
public void execValidations() throws FileNotFoundException, XMLParseException, JacksonException,
9292
ConnectIOException, ExecutionException, InterruptedException {
9393
// Record the start date-time of the validation process
9494
Instant start = Instant.now();
@@ -113,9 +113,9 @@ public void execValidations() throws FileNotFoundException, XMLParseException, J
113113
* @return a list of HttpSendOutcomeWrapper objects containing the responses or exceptions
114114
* @throws ExecutionException when an unhandled error occurs while processing the HTTP requests
115115
* @throws InterruptedException when interrupted before completing all the requests
116-
* @throws JsonProcessingException when a validation task contains invalid JSON content
116+
* @throws JacksonException when a validation task contains invalid JSON content
117117
*/
118-
List<HttpSendOutcomeWrapper> buildAndExecuteRequests(List<ValidationTask> tasks) throws ExecutionException, InterruptedException, JsonProcessingException {
118+
List<HttpSendOutcomeWrapper> buildAndExecuteRequests(List<ValidationTask> tasks) throws ExecutionException, InterruptedException, JacksonException {
119119
// Build HTTP requests from the validation tasks
120120
List<HttpRequest> reqs = new ArrayList<>();
121121
for (ValidationTask task : tasks) {
@@ -134,13 +134,13 @@ List<HttpSendOutcomeWrapper> buildAndExecuteRequests(List<ValidationTask> tasks)
134134
// Send the requests asynchronously and store the responses or exceptions in the results list
135135
// Use the index of each request to store the corresponding response or exception
136136
List<CompletableFuture<Void>> futures = IntStream.range(0, reqs.size())
137-
.mapToObj(i -> client.sendAsync(reqs.get(i), HttpResponse.BodyHandlers.ofString())
138-
.thenAccept(res -> results.set(i, new HttpSendOutcomeWrapper(res)))
139-
.exceptionally(e -> {
140-
results.set(i, new HttpSendOutcomeWrapper(e));
141-
return null;
142-
}))
143-
.toList();
137+
.mapToObj(i -> client.sendAsync(reqs.get(i), HttpResponse.BodyHandlers.ofString())
138+
.thenAccept(res -> results.set(i, new HttpSendOutcomeWrapper(res)))
139+
.exceptionally(e -> {
140+
results.set(i, new HttpSendOutcomeWrapper(e));
141+
return null;
142+
}))
143+
.toList();
144144
// Wait for all requests to complete
145145
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
146146

src/test/java/cf/maybelambda/httpvalidator/springboot/controller/AppConfigurationControllerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import cf.maybelambda.httpvalidator.springboot.persistence.XMLValidationTaskDao;
55
import cf.maybelambda.httpvalidator.springboot.service.JwtAuthenticationService;
66
import cf.maybelambda.httpvalidator.springboot.service.ValidationService;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
87
import org.junit.jupiter.api.BeforeEach;
98
import org.junit.jupiter.api.Test;
109
import org.mockito.MockedStatic;
1110
import org.springframework.beans.factory.annotation.Autowired;
12-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
13-
import org.springframework.boot.test.mock.mockito.MockBean;
11+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
1412
import org.springframework.http.MediaType;
13+
import org.springframework.test.context.bean.override.mockito.MockitoBean;
1514
import org.springframework.test.web.servlet.MockMvc;
15+
import tools.jackson.databind.ObjectMapper;
1616

1717
import javax.management.modelmbean.XMLParseException;
1818
import java.io.IOException;
@@ -41,11 +41,11 @@ public class AppConfigurationControllerTests {
4141
private MockMvc mockMvc;
4242
@Autowired
4343
private ObjectMapper mapper;
44-
@MockBean
44+
@MockitoBean
4545
private ValidationService valServ;
46-
@MockBean
46+
@MockitoBean
4747
private XMLValidationTaskDao dao;
48-
@MockBean
48+
@MockitoBean
4949
private JwtAuthenticationService authServ;
5050
private final Map<String, String> reqBody = new HashMap<>();
5151

src/test/java/cf/maybelambda/httpvalidator/springboot/controller/AppInfoControllerTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import cf.maybelambda.httpvalidator.springboot.service.ValidationService;
88
import org.junit.jupiter.api.Test;
99
import org.springframework.beans.factory.annotation.Autowired;
10-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
11-
import org.springframework.boot.test.mock.mockito.MockBean;
10+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
1211
import org.springframework.http.MediaType;
12+
import org.springframework.test.context.bean.override.mockito.MockitoBean;
1313
import org.springframework.test.web.servlet.MockMvc;
1414

1515
import java.util.HashMap;
@@ -34,15 +34,15 @@
3434
public class AppInfoControllerTests {
3535
@Autowired
3636
private MockMvc mockMvc;
37-
@MockBean
37+
@MockitoBean
3838
private XMLValidationTaskDao dao;
39-
@MockBean
39+
@MockitoBean
4040
private EmailNotificationService mailServ;
41-
@MockBean
41+
@MockitoBean
4242
private ValidationService valServ;
43-
@MockBean
43+
@MockitoBean
4444
private EventListenerService eventServ;
45-
@MockBean
45+
@MockitoBean
4646
private JwtAuthenticationService authServ;
4747

4848
@Test

src/test/java/cf/maybelambda/httpvalidator/springboot/itest/AppConfigurationControllerIntegrationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import cf.maybelambda.httpvalidator.springboot.persistence.XMLValidationTaskDao;
55
import cf.maybelambda.httpvalidator.springboot.service.JwtAuthenticationService;
66
import cf.maybelambda.httpvalidator.springboot.service.ValidationService;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
87
import org.hamcrest.Matchers;
98
import org.junit.jupiter.api.BeforeEach;
109
import org.junit.jupiter.api.Test;
@@ -21,6 +20,7 @@
2120
import org.springframework.test.context.junit.jupiter.SpringExtension;
2221
import org.springframework.test.web.servlet.MockMvc;
2322
import org.springframework.web.context.WebApplicationContext;
23+
import tools.jackson.databind.ObjectMapper;
2424

2525
import java.nio.charset.StandardCharsets;
2626
import java.util.HashMap;
@@ -56,7 +56,7 @@
5656
@ActiveProfiles("test")
5757
@SpringBootTest
5858
public class AppConfigurationControllerIntegrationTests {
59-
public static String UPD_DATAFILE_ERRORS_DESCR = INVALID_DATA_FILE_ERROR_MSG + " or " + UPD_DATA_FILE_ERROR_MSG;
59+
public static final String UPD_DATAFILE_ERRORS_DESCR = INVALID_DATA_FILE_ERROR_MSG + " or " + UPD_DATA_FILE_ERROR_MSG;
6060
private String testsToken;
6161
private MockMvc mockMvc;
6262

@@ -138,12 +138,12 @@ public void canUpdateDataFileWithValidXML() throws Exception {
138138
.andDo(document("{method-name}", REQUEST_HEADERS_SNIPPET));
139139

140140
assertThat(this.dao.isDataFileStatusOk()).isTrue();
141-
assertThat(this.dao.getAll().get(0)).isEqualTo(task);
141+
assertThat(this.dao.getAll().getFirst()).isEqualTo(task);
142142
}
143143

144144
@Test
145145
public void error400WhenUpdateDataFileRequestWithInvalidXML() throws Exception {
146-
ValidationTask task = this.dao.getAll().get(0);
146+
ValidationTask task = this.dao.getAll().getFirst();
147147

148148
String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
149149
+ "<validations>"
@@ -175,6 +175,6 @@ public void error400WhenUpdateDataFileRequestWithInvalidXML() throws Exception {
175175
);
176176

177177
// Verify the original file contents have not been modified
178-
assertThat(this.dao.getAll().get(0)).isEqualTo(task);
178+
assertThat(this.dao.getAll().getFirst()).isEqualTo(task);
179179
}
180180
}

src/test/java/cf/maybelambda/httpvalidator/springboot/itest/AppInfoControllerIntegrationTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ public class AppInfoControllerIntegrationTests {
5151
);
5252
public static final String START_TIME_DESCR = "The start time of the application in a formatted string";
5353
public static final String START_TIME_LR_DESCR = "The start time of the last run in a formatted string";
54-
public static final String DATAFILE_STATUS_DESCR = "`OK`: Data file status is okay, i.e. it "
55-
+ "exists and is readable\n\n`ERROR`: Data file status is not okay";
56-
public static final String CONFIG_STATUS_DESCR = "`OK`: Both mail and validation configurations are okay (run "
57-
+ "schedule, credentials, from and to addresses)\n\n`ERROR`: Either mail or validation configuration is not okay";
54+
public static final String DATAFILE_STATUS_DESCR = """
55+
`OK`: Data file status is okay, i.e. it exists and is readable
56+
57+
`ERROR`: Data file status is not okay""";
58+
public static final String CONFIG_STATUS_DESCR = """
59+
`OK`: Both mail and validation configurations are okay (run schedule, credentials, from and to addresses)
60+
61+
`ERROR`: Either mail or validation configuration is not okay""";
5862
public static final String TIME_ELAPSED_DESCR = "Duration of the last run";
5963
public static final String TASKS_TOTAL_DESCR = "The total number of tasks to be processed in the last run";
6064
public static final String TASKS_OK_DESCR = "The number of tasks with expected results";

src/test/java/cf/maybelambda/httpvalidator/springboot/model/ValidationTaskTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cf.maybelambda.httpvalidator.springboot.model;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.junit.jupiter.api.Test;
4+
import tools.jackson.databind.JsonNode;
55

66
import java.util.List;
77

src/test/java/cf/maybelambda/httpvalidator/springboot/persistence/XMLValidationTaskDaoTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cf.maybelambda.httpvalidator.springboot.persistence;
22

33
import cf.maybelambda.httpvalidator.springboot.model.ValidationTask;
4-
import com.fasterxml.jackson.core.JsonProcessingException;
5-
import com.fasterxml.jackson.databind.JsonNode;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
74
import org.junit.jupiter.api.BeforeEach;
85
import org.junit.jupiter.api.Test;
96
import org.mockito.MockedStatic;
@@ -15,6 +12,9 @@
1512
import org.w3c.dom.Node;
1613
import org.w3c.dom.NodeList;
1714
import org.xml.sax.SAXException;
15+
import tools.jackson.core.JacksonException;
16+
import tools.jackson.databind.JsonNode;
17+
import tools.jackson.databind.ObjectMapper;
1818

1919
import javax.management.modelmbean.XMLParseException;
2020
import javax.xml.parsers.DocumentBuilder;
@@ -127,12 +127,12 @@ void taskDataIsReadWhenWellFormedXMLParsedWithoutErrors() throws Exception {
127127

128128
List<ValidationTask> ans = this.taskDao.getAll();
129129

130-
assertEquals(GET, ans.get(0).reqMethod());
131-
assertEquals(this.url.getTextContent(), ans.get(0).reqURL());
132-
assertEquals(this.header.getTextContent(), ans.get(0).reqHeaders().get(0));
133-
assertEquals(this.mapper.readTree(this.reqbody.getTextContent()), ans.get(0).reqBody());
134-
assertEquals(Integer.parseInt(this.resBodyAttrs.getNamedItem(RES_SC_ATTR).getTextContent()), ans.get(0).validStatusCode());
135-
assertEquals(this.response.getTextContent(), ans.get(0).validBody());
130+
assertEquals(GET, ans.getFirst().reqMethod());
131+
assertEquals(this.url.getTextContent(), ans.getFirst().reqURL());
132+
assertEquals(this.header.getTextContent(), ans.getFirst().reqHeaders().getFirst());
133+
assertEquals(this.mapper.readTree(this.reqbody.getTextContent()), ans.getFirst().reqBody());
134+
assertEquals(Integer.parseInt(this.resBodyAttrs.getNamedItem(RES_SC_ATTR).getTextContent()), ans.getFirst().validStatusCode());
135+
assertEquals(this.response.getTextContent(), ans.getFirst().validBody());
136136
}
137137

138138
@Test
@@ -147,8 +147,8 @@ void xmlAttributesThatCanBeEmptyInDatafileAreParsedOk() throws Exception {
147147

148148
List<ValidationTask> ans = this.taskDao.getAll();
149149

150-
assertThat(ans.get(0).reqHeaders().isEmpty()).isTrue();
151-
assertEquals("", ans.get(0).validBody());
150+
assertThat(ans.getFirst().reqHeaders().isEmpty()).isTrue();
151+
assertEquals("", ans.getFirst().validBody());
152152
}
153153

154154
@Test
@@ -160,7 +160,7 @@ void whenGetAllThrowsSAXExceptionThenErrorIsLogged() throws Exception {
160160
}
161161

162162
@Test
163-
void whenJacksonThrowsJSONExceptionInGetAllThenErrorIsLogged() throws Exception {
163+
void whenJacksonThrowsJSONExceptionInGetAllThenErrorIsLogged() {
164164
// Number of <validation> elements
165165
given(this.nodes.getLength()).willReturn(1);
166166
// 2 child nodes of <validation>: <url> and <reqbody>
@@ -169,7 +169,7 @@ void whenJacksonThrowsJSONExceptionInGetAllThenErrorIsLogged() throws Exception
169169
given(this.childNodes.item(1)).willReturn(this.reqbody);
170170
given(this.reqbody.getNodeName()).willReturn(REQ_BODY_TAG);
171171
given(this.reqbody.getTextContent()).willReturn("");
172-
given(this.mapper.readTree(anyString())).willThrow(JsonProcessingException.class);
172+
given(this.mapper.readTree(anyString())).willThrow(JacksonException.class);
173173

174174
assertThrows(XMLParseException.class, () -> this.taskDao.getAll());
175175
verify(logger).error(anyString(), any(Throwable.class));

0 commit comments

Comments
 (0)