Skip to content

Commit 795b258

Browse files
committed
chore: clean codes
1 parent 3b3a5e8 commit 795b258

File tree

61 files changed

+1260
-1984
lines changed

Some content is hidden

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

61 files changed

+1260
-1984
lines changed

.github/workflows/boot-data-mongo-gridfs.yml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
java-version: '17'
2929
distribution: 'adopt'
3030
cache: 'maven'
31+
- name: Start up databases via Docker Compose
32+
run: |
33+
docker-compose up -d mongodb
34+
sleep 5
35+
docker ps -a
3136
- name: Build with Maven
3237
run: |
3338
cd boot-data-mongo-gridfs

.github/workflows/boot-exception-handler.yml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
java-version: '17'
2929
distribution: 'adopt'
3030
cache: 'maven'
31+
- name: Start up databases via Docker Compose
32+
run: |
33+
docker-compose up -d mongodb
34+
sleep 5
35+
docker ps -a
3136
- name: Build with Maven
3237
run: |
3338
cd boot-exception-handler

.github/workflows/multipart-data-mongo.yml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
java-version: '17'
2929
distribution: 'adopt'
3030
cache: 'maven'
31+
- name: Start up databases via Docker Compose
32+
run: |
33+
docker-compose up -d mongodb
34+
sleep 5
35+
docker ps -a
3136
- name: Build with Maven
3237
run: |
3338
cd multipart-data-mongo

.github/workflows/war.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Build with Maven
3232
run: |
3333
cd war
34-
mvn -B package --file pom.xml
34+
mvn -B clean verify --file pom.xml -Pintegration

boot-data-mongo-gridfs/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
<groupId>org.springframework.boot</groupId>
3939
<artifactId>spring-boot-starter-test</artifactId>
4040
<scope>test</scope>
41-
<exclusions>
42-
<exclusion>
43-
<groupId>org.junit.vintage</groupId>
44-
<artifactId>:junit-vintage-engine</artifactId>
45-
</exclusion>
46-
</exclusions>
4741
</dependency>
4842
<dependency>
4943
<groupId>de.flapdoodle.embed</groupId>

boot-data-mongo-gridfs/src/test/java/com/example/demo/DemoApplicationTests.java

+14-22
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@
44
import lombok.extern.slf4j.Slf4j;
55
import org.junit.jupiter.api.BeforeEach;
66
import org.junit.jupiter.api.Test;
7-
import org.springframework.beans.factory.annotation.Autowired;
8-
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
97
import org.springframework.boot.test.context.SpringBootTest;
108
import org.springframework.boot.web.server.LocalServerPort;
119
import org.springframework.core.io.ClassPathResource;
1210
import org.springframework.http.HttpEntity;
13-
import org.springframework.http.HttpStatus;
1411
import org.springframework.http.client.MultipartBodyBuilder;
1512
import org.springframework.test.web.reactive.server.WebTestClient;
1613
import org.springframework.util.MultiValueMap;
17-
import org.springframework.web.reactive.function.BodyExtractors;
18-
import org.springframework.web.reactive.function.client.ClientResponse;
19-
import org.springframework.web.reactive.function.client.WebClient;
20-
import reactor.core.publisher.Mono;
21-
import reactor.test.StepVerifier;
2214

2315
import java.io.IOException;
2416
import java.util.Map;
2517

26-
import static org.hibernate.validator.internal.util.Contracts.assertNotNull;
27-
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
2820

2921
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
3022
@Slf4j
@@ -38,8 +30,8 @@ public class DemoApplicationTests {
3830
@BeforeEach
3931
public void setup() {
4032
this.client = WebTestClient.bindToServer()
41-
.baseUrl("http://localhost:" + this.port)
42-
.build();
33+
.baseUrl("http://localhost:" + this.port)
34+
.build();
4335
}
4436

4537
private MultiValueMap<String, HttpEntity<?>> generateBody() {
@@ -51,12 +43,12 @@ private MultiValueMap<String, HttpEntity<?>> generateBody() {
5143
@Test
5244
public void testUpload() throws IOException {
5345
byte[] result = client
54-
.post()
55-
.uri("/multipart")
56-
.bodyValue(generateBody())
57-
.exchange()
58-
.expectStatus().isOk()
59-
.expectBody().returnResult().getResponseBody();
46+
.post()
47+
.uri("/multipart")
48+
.bodyValue(generateBody())
49+
.exchange()
50+
.expectStatus().isOk()
51+
.expectBody().returnResult().getResponseBody();
6052

6153
ObjectMapper objectMapper = new ObjectMapper();
6254
Map bodyMap = objectMapper.readValue(result, Map.class);
@@ -66,10 +58,10 @@ public void testUpload() throws IOException {
6658
assertNotNull(fileId);
6759

6860
client
69-
.get()
70-
.uri("/multipart/{id}", fileId)
71-
.exchange()
72-
.expectStatus().isOk();
61+
.get()
62+
.uri("/multipart/{id}", fileId)
63+
.exchange()
64+
.expectStatus().isOk();
7365

7466
}
7567

boot-exception-handler/pom.xml

-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
<groupId>org.springframework.boot</groupId>
3030
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
3131
</dependency>
32-
<dependency>
33-
<groupId>org.springframework.boot</groupId>
34-
<artifactId>spring-boot-starter-security</artifactId>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.springframework.security</groupId>
38-
<artifactId>spring-security-web</artifactId>
39-
</dependency>
4032

4133
<dependency>
4234
<groupId>org.springframework.boot</groupId>

boot-exception-handler/src/main/java/com/example/demo/DemoApplication.java

+27-55
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,26 @@
11
package com.example.demo;
22

3-
import java.time.LocalDateTime;
4-
5-
import com.fasterxml.jackson.core.JsonProcessingException;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
7-
import lombok.AllArgsConstructor;
8-
import lombok.Builder;
9-
import lombok.Data;
10-
import lombok.NoArgsConstructor;
11-
import lombok.ToString;
3+
import lombok.*;
124
import lombok.extern.slf4j.Slf4j;
135
import org.springframework.boot.CommandLineRunner;
146
import org.springframework.boot.SpringApplication;
157
import org.springframework.boot.autoconfigure.SpringBootApplication;
16-
import org.springframework.context.annotation.Bean;
178
import org.springframework.core.annotation.Order;
18-
import org.springframework.core.io.buffer.DataBuffer;
19-
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
209
import org.springframework.data.annotation.CreatedDate;
2110
import org.springframework.data.annotation.Id;
2211
import org.springframework.data.mongodb.config.EnableMongoAuditing;
2312
import org.springframework.data.mongodb.core.mapping.Document;
2413
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
25-
import org.springframework.http.HttpMethod;
2614
import org.springframework.http.HttpStatus;
27-
import org.springframework.http.MediaType;
28-
import org.springframework.security.authorization.AuthorizationDecision;
29-
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
30-
import org.springframework.security.config.web.server.ServerHttpSecurity;
31-
import org.springframework.security.core.Authentication;
32-
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
33-
import org.springframework.security.core.userdetails.User;
34-
import org.springframework.security.core.userdetails.UserDetails;
35-
import org.springframework.security.web.server.SecurityWebFilterChain;
36-
import org.springframework.security.web.server.authorization.AuthorizationContext;
3715
import org.springframework.stereotype.Component;
38-
import org.springframework.web.bind.annotation.DeleteMapping;
39-
import org.springframework.web.bind.annotation.GetMapping;
40-
import org.springframework.web.bind.annotation.PathVariable;
41-
import org.springframework.web.bind.annotation.PostMapping;
42-
import org.springframework.web.bind.annotation.PutMapping;
43-
import org.springframework.web.bind.annotation.RequestBody;
44-
import org.springframework.web.bind.annotation.RequestMapping;
45-
import org.springframework.web.bind.annotation.RestController;
46-
import org.springframework.web.bind.support.WebExchangeBindException;
16+
import org.springframework.web.bind.annotation.*;
4717
import org.springframework.web.server.ServerWebExchange;
4818
import org.springframework.web.server.WebExceptionHandler;
4919
import reactor.core.publisher.Flux;
5020
import reactor.core.publisher.Mono;
5121

22+
import java.time.LocalDateTime;
23+
5224
@SpringBootApplication
5325
@EnableMongoAuditing
5426
public class DemoApplication {
@@ -73,20 +45,20 @@ public DataInitializer(PostRepository posts) {
7345
public void run(String[] args) {
7446
log.info("start data initialization ...");
7547
this.posts
76-
.deleteAll()
77-
.thenMany(
78-
Flux
79-
.just("Post one", "Post two")
80-
.flatMap(
81-
title -> this.posts.save(Post.builder().title(title).content("content of " + title).build())
82-
)
83-
)
84-
.log()
85-
.subscribe(
86-
null,
87-
null,
88-
() -> log.info("done initialization...")
89-
);
48+
.deleteAll()
49+
.thenMany(
50+
Flux
51+
.just("Post one", "Post two")
52+
.flatMap(
53+
title -> this.posts.save(Post.builder().title(title).content("content of " + title).build())
54+
)
55+
)
56+
.log()
57+
.subscribe(
58+
null,
59+
null,
60+
() -> log.info("done initialization...")
61+
);
9062

9163
}
9264

@@ -120,14 +92,14 @@ public Mono<Post> get(@PathVariable("id") String id) {
12092
@PutMapping("/{id}")
12193
public Mono<Post> update(@PathVariable("id") String id, @RequestBody Post post) {
12294
return this.posts.findById(id)
123-
.switchIfEmpty(Mono.error(new PostNotFoundException(id)))
124-
.map(p -> {
125-
p.setTitle(post.getTitle());
126-
p.setContent(post.getContent());
127-
128-
return p;
129-
})
130-
.flatMap(p -> this.posts.save(p));
95+
.switchIfEmpty(Mono.error(new PostNotFoundException(id)))
96+
.map(p -> {
97+
p.setTitle(post.getTitle());
98+
p.setContent(post.getContent());
99+
100+
return p;
101+
})
102+
.flatMap(p -> this.posts.save(p));
131103
}
132104

133105
@DeleteMapping("/{id}")
@@ -139,7 +111,7 @@ public Mono<Void> delete(@PathVariable("id") String id) {
139111

140112
@Component
141113
@Order(-2)
142-
class RestWebExceptionHandler implements WebExceptionHandler{
114+
class RestWebExceptionHandler implements WebExceptionHandler {
143115

144116
@Override
145117
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package com.example.demo;
22

3-
import org.junit.Before;
4-
import org.junit.Test;
5-
import org.junit.runner.RunWith;
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
65
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
86
import org.springframework.boot.test.context.SpringBootTest;
97
import org.springframework.context.ApplicationContext;
10-
import org.springframework.test.context.junit4.SpringRunner;
118
import org.springframework.test.web.reactive.server.WebTestClient;
129

13-
@RunWith(SpringRunner.class)
1410
@SpringBootTest
1511
public class DemoApplicationTests {
1612

@@ -19,17 +15,17 @@ public class DemoApplicationTests {
1915

2016
WebTestClient client;
2117

22-
@Before
23-
public void setup(){
18+
@BeforeEach
19+
public void setup() {
2420
client = WebTestClient.bindToApplicationContext(applicationContext)
25-
.configureClient()
26-
.build();
21+
.configureClient()
22+
.build();
2723
}
2824

2925
@Test
3026
public void getNoneExistedPost_shouldReturn404() {
3127
client.get().uri("/posts/xxxx").exchange()
32-
.expectStatus().isNotFound();
28+
.expectStatus().isNotFound();
3329
}
3430

3531
}

boot-mvc-freemarker/pom.xml

+1-13
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
</properties>
2424

2525
<dependencies>
26-
<dependency>
27-
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
29-
</dependency>
3026
<dependency>
3127
<groupId>org.springframework.boot</groupId>
3228
<artifactId>spring-boot-starter-webflux</artifactId>
@@ -41,15 +37,7 @@
4137
</exclusion>
4238
</exclusions>
4339
</dependency>
44-
45-
<!-- <dependency>
46-
<groupId>org.freemarker</groupId>
47-
<artifactId>freemarker</artifactId>
48-
</dependency>
49-
<dependency>
50-
<groupId>org.springframework</groupId>
51-
<artifactId>spring-context-support</artifactId>
52-
</dependency>-->
40+
5341
<dependency>
5442
<groupId>org.projectlombok</groupId>
5543
<artifactId>lombok</artifactId>

0 commit comments

Comments
 (0)