1
+ package org .soujava .demos .mongodb .document ;
2
+
3
+ import jakarta .inject .Inject ;
4
+ import org .assertj .core .api .SoftAssertions ;
5
+ import org .eclipse .jnosql .databases .mongodb .mapping .MongoDBTemplate ;
6
+ import org .eclipse .jnosql .mapping .Database ;
7
+ import org .eclipse .jnosql .mapping .core .Converters ;
8
+ import org .eclipse .jnosql .mapping .document .DocumentTemplate ;
9
+ import org .eclipse .jnosql .mapping .document .spi .DocumentExtension ;
10
+ import org .eclipse .jnosql .mapping .reflection .Reflections ;
11
+ import org .eclipse .jnosql .mapping .reflection .spi .ReflectionEntityMetadataExtension ;
12
+ import org .eclipse .jnosql .mapping .semistructured .EntityConverter ;
13
+ import org .jboss .weld .junit5 .auto .AddExtensions ;
14
+ import org .jboss .weld .junit5 .auto .AddPackages ;
15
+ import org .jboss .weld .junit5 .auto .EnableAutoWeld ;
16
+ import org .junit .jupiter .api .AfterEach ;
17
+ import org .junit .jupiter .api .BeforeEach ;
18
+ import org .junit .jupiter .api .Test ;
19
+
20
+ import java .util .List ;
21
+
22
+
23
+ @ EnableAutoWeld
24
+ @ AddPackages (value = {Database .class , EntityConverter .class , DocumentTemplate .class , MongoDBTemplate .class })
25
+ @ AddPackages (Room .class )
26
+ @ AddPackages (ManagerSupplier .class )
27
+ @ AddPackages (MongoDBTemplate .class )
28
+ @ AddPackages (Reflections .class )
29
+ @ AddPackages (Converters .class )
30
+ @ AddExtensions ({ReflectionEntityMetadataExtension .class , DocumentExtension .class })
31
+ class RoomServiceTest {
32
+
33
+ @ Inject
34
+ private RoomRepository repository ;
35
+
36
+ @ BeforeEach
37
+ void setUP () {
38
+
39
+ Room vipRoom1 = new RoomBuilder ()
40
+ .roomNumber (101 )
41
+ .type (RoomType .VIP_SUITE )
42
+ .status (RoomStatus .AVAILABLE )
43
+ .cleanStatus (CleanStatus .CLEAN )
44
+ .smokingAllowed (false )
45
+ .build ();
46
+
47
+ Room vipRoom2 = new RoomBuilder ()
48
+ .roomNumber (102 )
49
+ .type (RoomType .VIP_SUITE )
50
+ .status (RoomStatus .AVAILABLE )
51
+ .cleanStatus (CleanStatus .CLEAN )
52
+ .smokingAllowed (true )
53
+ .build ();
54
+
55
+ Room standardRoom1 = new RoomBuilder ()
56
+ .roomNumber (201 )
57
+ .type (RoomType .STANDARD )
58
+ .status (RoomStatus .AVAILABLE )
59
+ .cleanStatus (CleanStatus .CLEAN )
60
+ .smokingAllowed (false )
61
+ .build ();
62
+
63
+ Room standardRoom2 = new RoomBuilder ()
64
+ .roomNumber (202 )
65
+ .type (RoomType .DELUXE )
66
+ .status (RoomStatus .AVAILABLE )
67
+ .cleanStatus (CleanStatus .CLEAN )
68
+ .smokingAllowed (false )
69
+ .build ();
70
+
71
+ Room dirtyReservedRoom = new RoomBuilder ()
72
+ .roomNumber (301 )
73
+ .type (RoomType .DELUXE )
74
+ .status (RoomStatus .RESERVED )
75
+ .cleanStatus (CleanStatus .DIRTY )
76
+ .smokingAllowed (false )
77
+ .build ();
78
+
79
+ Room dirtySuiteRoom = new RoomBuilder ()
80
+ .roomNumber (302 )
81
+ .type (RoomType .SUITE )
82
+ .status (RoomStatus .UNDER_MAINTENANCE )
83
+ .cleanStatus (CleanStatus .INSPECTION_NEEDED )
84
+ .smokingAllowed (false )
85
+ .build ();
86
+
87
+ Room smokingAllowedRoom = new RoomBuilder ()
88
+ .roomNumber (401 )
89
+ .type (RoomType .STANDARD )
90
+ .status (RoomStatus .AVAILABLE )
91
+ .cleanStatus (CleanStatus .CLEAN )
92
+ .smokingAllowed (true )
93
+ .build ();
94
+
95
+ repository .save (List .of (
96
+ vipRoom1 , vipRoom2 ,
97
+ standardRoom1 , standardRoom2 ,
98
+ dirtyReservedRoom , dirtySuiteRoom ,
99
+ smokingAllowedRoom
100
+ ));
101
+
102
+ }
103
+
104
+ @ AfterEach
105
+ void cleanUp () {
106
+ repository .deleteBy ();
107
+ }
108
+
109
+ @ Test
110
+ void shouldFindRoomReadyToGuest () {
111
+ List <Room > rooms = this .repository .findAvailableStandardRooms ();
112
+ SoftAssertions .assertSoftly (softly -> {
113
+ softly .assertThat (rooms ).hasSize (3 );
114
+ softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
115
+ softly .assertThat (rooms ).allMatch (room -> !room .isUnderMaintenance ());
116
+ });
117
+ }
118
+
119
+ @ Test
120
+ void shouldFindVipRoomsReadyForGuests () {
121
+ List <Room > rooms = this .repository .findVipRoomsReadyForGuests ();
122
+ SoftAssertions .assertSoftly (softly -> {
123
+ softly .assertThat (rooms ).hasSize (2 );
124
+ softly .assertThat (rooms ).allMatch (room -> room .getType ().equals (RoomType .VIP_SUITE ));
125
+ softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
126
+ softly .assertThat (rooms ).allMatch (room -> !room .isUnderMaintenance ());
127
+ });
128
+ }
129
+
130
+ @ Test
131
+ void shouldFindAvailableSmokingRooms () {
132
+ List <Room > rooms = this .repository .findAvailableSmokingRooms ();
133
+ SoftAssertions .assertSoftly (softly -> {
134
+ softly .assertThat (rooms ).hasSize (2 );
135
+ softly .assertThat (rooms ).allMatch (room -> room .isSmokingAllowed ());
136
+ softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
137
+ });
138
+ }
139
+
140
+ @ Test
141
+ void shouldFindRoomsNeedingCleaning () {
142
+ List <Room > rooms = this .repository .findRoomsNeedingCleaning ();
143
+ SoftAssertions .assertSoftly (softly -> {
144
+ softly .assertThat (rooms ).hasSize (2 );
145
+ softly .assertThat (rooms ).allMatch (room -> !room .getCleanStatus ().equals (CleanStatus .CLEAN ));
146
+ softly .assertThat (rooms ).allMatch (room -> !room .getStatus ().equals (RoomStatus .OUT_OF_SERVICE ));
147
+ });
148
+ }
149
+ }
0 commit comments