FluxAndMonoTest.java
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.krunal.reactive.fluxmonoplayground;
import com.krunal.reactive.model.Student;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
public class FluxAndMonoTest {
@Test
public void fluxTest() {
Flux<String> stringFlux = Flux.just("Spring", "Spring Boot", "Reactive Spring")
.concatWith(Flux.error(new RuntimeException("Run Time Error")))
.concatWith(Flux.just("krunal"));
stringFlux.subscribe(System.out::println, (e) -> System.err.println(e));
}
@Test
public void fluxTestElementWithoutError(){
Flux<String> stringFlux = Flux.just("Spring", "Spring Boot", "Reactive Spring")
.log();
StepVerifier.create(stringFlux)
.expectNext("Spring")
.expectNext("Spring Boot")
.expectNext("Reactive Spring");
//.verifyComplete();
}
@Test
public void fluxTestElementWithError(){
Flux<String> stringFlux = Flux.just("Spring", "Spring Boot", "Reactive Spring")
.concatWith(Flux.error(new RuntimeException("Run Time Error")))
.log();
StepVerifier.create(stringFlux)
.expectNext("Spring")
.expectNext("Spring Boot")
.expectNext("Reactive Spring")
.expectError(RuntimeException.class)
.verify();
}
@Test
public void fluxTestElementCountWithError(){
Flux<String> stringFlux = Flux.just("Spring", "Spring Boot", "Reactive Spring")
.concatWith(Flux.error(new RuntimeException("Run Time Error")))
.log();
StepVerifier.create(stringFlux)
.expectNextCount(3)
.expectError(RuntimeException.class)
.verify();
}
@Test
public void fluxTestElementWithErrorVeriation(){
Flux<String> stringFlux = Flux.just("Spring", "Spring Boot", "Reactive Spring")
.concatWith(Flux.error(new RuntimeException("Run Time Error")))
.log();
StepVerifier.create(stringFlux)
.expectNext("Spring", "Spring Boot", "Reactive Spring")
.expectError(RuntimeException.class)
.verify();
}
@Test
public void monoTest(){
Mono<String> stringMono= Mono.just("Spring");
StepVerifier.create(stringMono.log())
.expectNext("Spring")
.verifyComplete();
}
@Test
public void monoTestError(){
StepVerifier.create(Mono.error(new RuntimeException("Exception Occurred")).log())
.expectError(RuntimeException.class)
.verify();
}
}