1
1
package pl .desz .todo ;
2
2
3
3
import org .junit .jupiter .api .Test ;
4
+ import org .springframework .beans .factory .annotation .Autowired ;
4
5
import org .springframework .boot .test .context .SpringBootTest ;
5
6
import org .springframework .context .annotation .Import ;
7
+ import pl .desz .todo .model .Todo ;
8
+ import pl .desz .todo .persistence .TodoRepository ;
9
+ import reactor .core .publisher .Mono ;
10
+ import reactor .test .StepVerifier ;
6
11
7
- @ Import (TestcontainersConfiguration .class )
12
+ @ Import (MongoDBContainerConf .class )
8
13
@ SpringBootTest
9
14
class TodoServiceApplicationTests {
10
15
16
+ private static final Long TODO_ID = 1L ;
17
+ private static final String TODO_DESCRIPTION = "DESCRIPTION" ;
18
+
19
+ @ Autowired
20
+ private TodoRepository todoRepository ;
21
+
22
+ @ Test
23
+ void shouldSaveTodo () {
24
+ final Todo todo = new Todo (TODO_ID , TODO_DESCRIPTION );
25
+ final Mono <Todo > todoMono = todoRepository .save (todo );
26
+
27
+ StepVerifier .create (todoMono )
28
+ .expectNext (todo )
29
+ .verifyComplete ();
30
+ }
31
+
32
+ @ Test
33
+ void shouldFindTodoById () {
34
+ final Todo todo = new Todo (TODO_ID , TODO_DESCRIPTION );
35
+ todoRepository .save (todo ).block ();
36
+
37
+ StepVerifier .create (todoRepository .findById (TODO_ID ))
38
+ .expectNextMatches (foundTodo -> foundTodo .getId ().equals (TODO_ID ) && foundTodo .getDescription ().equals (TODO_DESCRIPTION ))
39
+ .verifyComplete ();
40
+ }
41
+
11
42
@ Test
12
- void contextLoads () {
43
+ void shouldUpdateTodo () {
44
+ final Todo todo = new Todo (TODO_ID , TODO_DESCRIPTION );
45
+ todoRepository .save (todo ).block ();
46
+
47
+ final Todo updatedTodo = new Todo (TODO_ID , "Updated" );
48
+ final Mono <Todo > monoUpdatedTodo = todoRepository .save (updatedTodo );
49
+
50
+ StepVerifier .create (monoUpdatedTodo )
51
+ .expectNextMatches (t -> t .getId ().equals (TODO_ID ) && t .getDescription ().equals ("Updated" ))
52
+ .verifyComplete ();
13
53
}
14
54
15
- }
55
+ @ Test
56
+ void shouldDeleteTodo () {
57
+ final Todo todo = new Todo (TODO_ID , TODO_DESCRIPTION );
58
+ todoRepository .save (todo ).block ();
59
+
60
+ StepVerifier .create (todoRepository .deleteById (TODO_ID ))
61
+ .verifyComplete ();
62
+
63
+ StepVerifier .create (todoRepository .findById (TODO_ID ))
64
+ .expectNextCount (0 )
65
+ .verifyComplete ();
66
+ }
67
+ }
0 commit comments