Skip to content

Commit aa10b0a

Browse files
committed
Added mongo-docker/docker-compose.yml
1 parent 796ac66 commit aa10b0a

File tree

20 files changed

+548
-7
lines changed

20 files changed

+548
-7
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ Temporary Items
6767
hs_err_pid*
6868

6969
#Auto-import
70-
*.iml
70+
*.iml
71+
/mongo-docker/.mongo-volume/
72+
/code_examples/

mongo-docker/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Mongo docker image
2-
version: '3.1'
2+
version: '3.7'
33

44
services:
55
mongo:
66
image: 'mongo:4.4.0-rc8-bionic'
77
restart: on-failure
88
ports:
99
- 27017:27017
10+
volumes:
11+
- ./.mongo-volume:/data/db
1012
environment:
1113
MONGO_INITDB_ROOT_USERNAME: root
1214
MONGO_INITDB_ROOT_PASSWORD: root@123

pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
<modules>
1818
<module>project-reactor</module>
19+
<module>webflux-00-controller-approach</module>
20+
<module>webflux-01-functional-approach</module>
21+
<module>webflux-03-mongo-rest-controller-approach</module>
22+
<module>webflux-02-mongo-rest-functional-approach</module>
1923
</modules>
2024

21-
2225
<properties>
2326
<java.version>11</java.version>
2427
</properties>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1. To run the application
2+
```shell script
3+
mvn spring-boot:run
4+
```
5+
6+
2. Visit the below urls in a browser:
7+
```
8+
http://localhost:8080/hello/mono
9+
```
10+
11+
```
12+
http://localhost:8080/hello/flux
13+
```
14+
3. If needed, change the app-server #port in `src/main/resources/application.yml`

webflux-00-controller-approach/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212
<modelVersion>4.0.0</modelVersion>
1313
<artifactId>webflux-00-controller-approach</artifactId>
14-
<description>First WebFlux project in Spring boot</description>
14+
<description>Annotation approach WebFlux project in Spring boot</description>
1515

1616
<dependencies>
1717
<dependency>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
server:
2-
port: 8080
2+
port: 8080
3+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,50 @@
11
package c.jbd.webflux.resources;
22

3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
6+
import org.springframework.http.MediaType;
7+
import org.springframework.test.web.reactive.server.WebTestClient;
8+
import reactor.core.publisher.Flux;
9+
import reactor.test.StepVerifier;
10+
11+
//@SpringJUnitConfig(AppConfig.class)
12+
@WebFluxTest
313
public class CorrectTestController {
14+
@Autowired
15+
private WebTestClient webTestClient;
16+
17+
private final String TEST_MESSAGE = "Welcome to JstoBigdata.com";
18+
19+
@Test
20+
public void testMonoEndpoint() {
21+
Flux<String> msg$ = webTestClient.get()
22+
.uri("/hello/mono")
23+
.exchange()
24+
.expectStatus().isOk()
25+
.returnResult(String.class).getResponseBody()
26+
.log();
27+
28+
msg$.subscribe(System.out::println);
29+
30+
StepVerifier.create(msg$)
31+
.expectNext(TEST_MESSAGE)
32+
.verifyComplete();
33+
//.expectComplete(); - do not use
34+
}
35+
36+
@Test
37+
public void testFluxEndpoint() {
38+
Flux<String> msg$ = webTestClient.get()
39+
.uri("/hello/flux")
40+
.accept(MediaType.APPLICATION_STREAM_JSON)
41+
.exchange()
42+
.expectStatus().isOk()
43+
.returnResult(String.class).getResponseBody()
44+
.log();
45+
46+
StepVerifier.create(msg$)
47+
.expectNext(TEST_MESSAGE)
48+
.verifyComplete();
49+
}
450
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
package c.jbd.webflux.resources;
22

3+
import org.junit.jupiter.api.BeforeAll;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.web.reactive.function.client.WebClient;
7+
import reactor.core.publisher.Flux;
8+
import reactor.core.publisher.Mono;
9+
import reactor.test.StepVerifier;
10+
311
public class TestHelloController {
12+
13+
private static WebClient webClient;
14+
15+
@BeforeAll
16+
private static void setWebClient() {
17+
webClient = WebClient.create("http://localhost:8080");
18+
}
19+
20+
@Test
21+
public void testMonoEndpoint() {
22+
Mono<String> msg$ = webClient.get()
23+
.uri("/hello/mono")
24+
.retrieve()
25+
.bodyToMono(String.class).log();
26+
27+
StepVerifier.create(msg$)
28+
.expectNext("Welcome to JstoBigdata.com")
29+
.expectComplete();
30+
}
31+
32+
@Test
33+
public void testFluxEndpoint() {
34+
Flux<String> msg$ = webClient.get()
35+
.uri("/hello/flux")
36+
.accept(MediaType.APPLICATION_STREAM_JSON)
37+
.retrieve()
38+
.bodyToFlux(String.class);
39+
40+
StepVerifier.create(msg$)
41+
.expectNext("Welcome to JstoBigdata.com")
42+
.verifyComplete();
43+
}
444
}

webflux-01-functional-approach/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,38 @@
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>webflux-01-functional-approach</artifactId>
13+
<description>Functional approach in WebFlux endpoints</description>
1314

15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter-webflux</artifactId>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-test</artifactId>
24+
<scope>test</scope>
25+
<exclusions>
26+
<exclusion>
27+
<groupId>org.junit.vintage</groupId>
28+
<artifactId>junit-vintage-engine</artifactId>
29+
</exclusion>
30+
</exclusions>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>io.projectreactor</groupId>
35+
<artifactId>reactor-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-devtools</artifactId>
42+
<optional>true</optional>
43+
<scope>runtime</scope>
44+
</dependency>
45+
</dependencies>
1446

1547
</project>

webflux-01-functional-approach/src/main/java/c/jbd/webflux/FunctionalAppConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
@SpringBootApplication
77
public class FunctionalAppConfig {
88
public static void main(String[] args) {
9-
SpringApplication.run(AppConfig.class, args);
9+
SpringApplication.run(FunctionalAppConfig.class, args);
1010
}
1111
}

0 commit comments

Comments
 (0)