Skip to content

Commit 8ea1fa5

Browse files
committed
Spring Boot 4対応。とりあえずコンパイルが通った
1 parent cb6746d commit 8ea1fa5

File tree

178 files changed

+976
-670
lines changed

Some content is hidden

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

178 files changed

+976
-670
lines changed

accesslog-standard-output-example/src/main/java/com/example/AccessLogCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example;
22

3-
import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory;
3+
import org.springframework.boot.tomcat.ConfigurableTomcatWebServerFactory;
44
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
55
import org.springframework.context.annotation.Configuration;
66

aop-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<artifactId>spring-boot-starter</artifactId>
1717
</dependency>
1818
<dependency>
19-
<groupId>org.springframework.boot</groupId>
20-
<artifactId>spring-boot-starter-aop</artifactId>
19+
<groupId>org.aspectj</groupId>
20+
<artifactId>aspectjweaver</artifactId>
2121
</dependency>
2222
<dependency>
2323
<groupId>org.springframework.boot</groupId>

aop-logging-simple-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</dependency>
1919
<dependency>
2020
<groupId>org.springframework.boot</groupId>
21-
<artifactId>spring-boot-starter-aop</artifactId>
21+
<artifactId>spring-boot-starter-aspectj</artifactId>
2222
</dependency>
2323
</dependencies>
2424

25-
</project>
25+
</project>

api-example/src/main/java/com/example/error/MyErrorController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.util.Map;
44

5-
import org.springframework.boot.web.servlet.error.ErrorAttributes;
6-
import org.springframework.boot.web.servlet.error.ErrorController;
5+
import org.springframework.boot.webmvc.error.ErrorAttributes;
6+
import org.springframework.boot.webmvc.error.ErrorController;
77
import org.springframework.web.bind.annotation.RequestMapping;
88
import org.springframework.web.bind.annotation.RestController;
99
import org.springframework.web.context.request.WebRequest;

api-example/src/test/java/com/example/controller/SongControllerMockMvcTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,29 @@
88
import java.nio.charset.StandardCharsets;
99
import java.util.Locale;
1010

11+
import org.junit.jupiter.api.BeforeEach;
1112
import org.junit.jupiter.api.Test;
1213
import org.skyscreamer.jsonassert.JSONAssert;
1314
import org.springframework.beans.factory.annotation.Autowired;
14-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1515
import org.springframework.boot.test.context.SpringBootTest;
1616
import org.springframework.http.MediaType;
1717
import org.springframework.test.web.servlet.MockMvc;
18+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
19+
import org.springframework.web.context.WebApplicationContext;
1820

1921
@SpringBootTest
20-
@AutoConfigureMockMvc
2122
public class SongControllerMockMvcTest extends RestControllerTestBase {
2223

23-
@Autowired
2424
MockMvc mvc;
2525

26+
@Autowired
27+
WebApplicationContext wac;
28+
29+
@BeforeEach
30+
void setup() {
31+
mvc = MockMvcBuilders.webAppContextSetup(wac).build();
32+
}
33+
2634
@Test
2735
void testGetList() throws Exception {
2836
mvc.perform(get("/songs"))

api-example/src/test/java/com/example/controller/SongControllerWithRestTemplateTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,42 @@
22

33
import static org.junit.jupiter.api.Assertions.*;
44

5+
import org.junit.jupiter.api.BeforeEach;
56
import org.junit.jupiter.api.Test;
67
import org.skyscreamer.jsonassert.JSONAssert;
7-
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.boot.test.context.SpringBootTest;
99
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10-
import org.springframework.boot.test.web.client.TestRestTemplate;
10+
import org.springframework.boot.test.web.server.LocalServerPort;
1111
import org.springframework.http.HttpStatus;
1212
import org.springframework.http.MediaType;
1313
import org.springframework.http.RequestEntity;
14+
import org.springframework.http.client.ClientHttpResponse;
15+
import org.springframework.web.client.DefaultResponseErrorHandler;
16+
import org.springframework.web.client.RestTemplate;
1417
import org.springframework.web.util.UriComponentsBuilder;
1518

1619
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
1720
public class SongControllerWithRestTemplateTest extends RestControllerTestBase {
1821

19-
@Autowired
20-
TestRestTemplate http;
22+
@LocalServerPort
23+
int port;
24+
25+
RestTemplate http;
26+
27+
@BeforeEach
28+
void setup() {
29+
http = new RestTemplate();
30+
http.setErrorHandler(new DefaultResponseErrorHandler() {
31+
@Override
32+
public boolean hasError(ClientHttpResponse response) {
33+
return false;
34+
}
35+
});
36+
}
2137

2238
@Test
2339
void testGetList() throws Exception {
24-
var request = RequestEntity.get("/songs").build();
40+
var request = RequestEntity.get("http://localhost:" + port + "/songs").build();
2541

2642
var response = http.exchange(request, String.class);
2743

@@ -34,7 +50,7 @@ void testGetList() throws Exception {
3450

3551
@Test
3652
void testGetListWithCriteria() throws Exception {
37-
var uri = UriComponentsBuilder.fromPath("/songs")
53+
var uri = UriComponentsBuilder.fromUriString("http://localhost:" + port + "/songs")
3854
.queryParam("singer", "1")
3955
.build().toUri();
4056

@@ -51,7 +67,7 @@ void testGetListWithCriteria() throws Exception {
5167

5268
@Test
5369
void testGetListWithInvalidCriteria() throws Exception {
54-
var uri = UriComponentsBuilder.fromPath("/songs")
70+
var uri = UriComponentsBuilder.fromUriString("http://localhost:" + port + "/songs")
5571
.queryParam("singer", "0")
5672
.build().toUri();
5773

@@ -68,7 +84,7 @@ void testGetListWithInvalidCriteria() throws Exception {
6884

6985
@Test
7086
void testGetListNoExistsSinger() throws Exception {
71-
var uri = UriComponentsBuilder.fromPath("/songs")
87+
var uri = UriComponentsBuilder.fromUriString("http://localhost:" + port + "/songs")
7288
.queryParam("singer", "999")
7389
.build().toUri();
7490

@@ -85,7 +101,7 @@ void testGetListNoExistsSinger() throws Exception {
85101

86102
@Test
87103
void testCreate() throws Exception {
88-
var request = RequestEntity.post("/songs")
104+
var request = RequestEntity.post("http://localhost:" + port + "/songs")
89105
.contentType(MediaType.APPLICATION_JSON)
90106
.body(read("create.json"));
91107

@@ -100,7 +116,7 @@ void testCreate() throws Exception {
100116

101117
@Test
102118
void testCreateWithoutExpectedId() throws Exception {
103-
var request = RequestEntity.post("/songs")
119+
var request = RequestEntity.post("http://localhost:" + port + "/songs")
104120
.contentType(MediaType.APPLICATION_JSON)
105121
.body(read("create.json"));
106122

api-example/src/test/java/com/example/error/MyErrorControllerTest.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,52 @@
44

55
import java.util.Map;
66

7+
import org.junit.jupiter.api.BeforeEach;
78
import org.junit.jupiter.api.Test;
8-
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.boot.test.context.SpringBootTest;
1010
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11-
import org.springframework.boot.test.web.client.TestRestTemplate;
11+
import org.springframework.boot.test.web.server.LocalServerPort;
1212
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.client.ClientHttpResponse;
14+
import org.springframework.web.client.DefaultResponseErrorHandler;
15+
import org.springframework.web.client.RestTemplate;
1316

1417
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
1518
public class MyErrorControllerTest {
1619

17-
@Autowired
18-
TestRestTemplate http;
20+
@LocalServerPort
21+
int port;
22+
23+
RestTemplate http;
24+
25+
@BeforeEach
26+
void setup() {
27+
http = new RestTemplate();
28+
http.setErrorHandler(new DefaultResponseErrorHandler() {
29+
@Override
30+
public boolean hasError(ClientHttpResponse response) {
31+
return false;
32+
}
33+
});
34+
}
1935

2036
@Test
2137
void notFound() {
22-
var response = http.getForEntity("/no-exists-path", Map.class);
38+
var response = http.getForEntity("http://localhost:" + port + "/no-exists-path", Map.class);
2339
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
2440
assertEquals(Map.of("message", "Not Found"), response.getBody());
2541
}
2642

2743
@Test
2844
void serverError() {
29-
var response = http.getForEntity("/songs/simulate-bug", Map.class);
45+
var response = http.getForEntity("http://localhost:" + port + "/songs/simulate-bug", Map.class);
3046
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
3147
assertEquals(Map.of("message", "Internal Server Error"), response.getBody());
3248
}
3349

3450
@Test
3551
void methodNotAllow() {
36-
var response = http.postForEntity("/songs/simulate-bug", Map.of("data", "dummy"), Map.class);
52+
var response = http.postForEntity("http://localhost:" + port + "/songs/simulate-bug", Map.of("data", "dummy"), Map.class);
3753
assertEquals(HttpStatus.METHOD_NOT_ALLOWED, response.getStatusCode());
3854
assertEquals(Map.of("message", "Method Not Allowed"), response.getBody());
3955
}

api-token-authentication-example/src/test/java/com/example/ApiTokenAuthenticationTest.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,46 @@
44

55
import java.util.Map;
66

7+
import org.junit.jupiter.api.BeforeEach;
78
import org.junit.jupiter.api.Test;
8-
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.boot.test.context.SpringBootTest;
1010
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11-
import org.springframework.boot.test.web.client.TestRestTemplate;
11+
import org.springframework.boot.test.web.server.LocalServerPort;
1212
import org.springframework.http.HttpStatus;
1313
import org.springframework.http.RequestEntity;
14+
import org.springframework.http.client.ClientHttpResponse;
15+
import org.springframework.web.client.DefaultResponseErrorHandler;
16+
import org.springframework.web.client.RestTemplate;
1417

1518
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "example.api-token=0000000000")
1619
public class ApiTokenAuthenticationTest {
1720

18-
@Autowired
19-
TestRestTemplate http;
21+
@LocalServerPort
22+
int port;
23+
24+
RestTemplate http;
25+
26+
@BeforeEach
27+
void setup() {
28+
http = new RestTemplate();
29+
http.setErrorHandler(new DefaultResponseErrorHandler() {
30+
@Override
31+
public boolean hasError(ClientHttpResponse response) {
32+
return false;
33+
}
34+
});
35+
}
2036

2137
@Test
2238
void unauthorized() {
23-
var responseEntity = http.getForEntity("/demo", Map.class);
39+
var responseEntity = http.getForEntity("http://localhost:" + port + "/demo", Map.class);
2440
assertEquals(HttpStatus.FORBIDDEN, responseEntity.getStatusCode());
2541
}
2642

2743
@Test
2844
void ok() {
2945
var token = "0000000000";
30-
var requestEntity = RequestEntity.get("/demo").header("Authorization", "Bearer " + token).build();
46+
var requestEntity = RequestEntity.get("http://localhost:" + port + "/demo").header("Authorization", "Bearer " + token).build();
3147
var responseEntity = http.exchange(requestEntity, Map.class);
3248
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
3349
assertEquals("test", responseEntity.getBody().get("name"));
@@ -36,7 +52,7 @@ void ok() {
3652
@Test
3753
void mistakeApiToken() {
3854
var token = "mistake";
39-
var requestEntity = RequestEntity.get("/demo").header("Authorization", "Bearer " + token).build();
55+
var requestEntity = RequestEntity.get("http://localhost:" + port + "/demo").header("Authorization", "Bearer " + token).build();
4056
var responseEntity = http.exchange(requestEntity, Map.class);
4157
assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode());
4258
}

batch-example/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-batch</artifactId>
1717
</dependency>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-batch-jdbc</artifactId>
21+
</dependency>
1822

1923
<dependency>
2024
<groupId>com.h2database</groupId>

batch-example/src/main/java/com/example/chunk/ChunkExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.example.chunk;
22

3-
import org.springframework.batch.core.Job;
4-
import org.springframework.batch.core.Step;
3+
import org.springframework.batch.core.job.Job;
4+
import org.springframework.batch.core.step.Step;
55
import org.springframework.batch.core.job.builder.JobBuilder;
66
import org.springframework.batch.core.repository.JobRepository;
77
import org.springframework.batch.core.step.builder.StepBuilder;

0 commit comments

Comments
 (0)