5454
5555@ EnableAutoWeld
5656@ AddPackages (value = {Database .class , EntityConverter .class , DocumentTemplate .class , MongoDBTemplate .class })
57- @ AddPackages (Book .class )
57+ @ AddPackages (Magazine .class )
5858@ AddPackages (Reflections .class )
5959@ AddPackages (Converters .class )
6060@ AddExtensions ({EntityMetadataExtension .class ,
@@ -72,14 +72,14 @@ class CustomRepositoryIntegrationTest {
7272
7373 @ Inject
7474 @ Database (DatabaseType .DOCUMENT )
75- BookCustomRepository bookCustomRepository ;
75+ MagazineCustomRepository magazineCustomRepository ;
7676
7777
7878 @ BeforeEach
7979 void cleanUp () {
8080 try (MongoClient mongoClient = INSTANCE .mongoClient ()) {
8181 MongoCollection <Document > collection = mongoClient .getDatabase (DATABASE_NAME )
82- .getCollection (Book .class .getSimpleName ());
82+ .getCollection (Magazine .class .getSimpleName ());
8383 collection .deleteMany (new BsonDocument ());
8484 await ().atMost (Duration .ofSeconds (2 ))
8585 .until (() -> collection .find ().limit (1 ).first () == null );
@@ -88,71 +88,71 @@ void cleanUp() {
8888
8989 @ Test
9090 void shouldSave () {
91- Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
92- assertThat (bookCustomRepository .save (book ))
91+ Magazine magazine = new Magazine (randomUUID ().toString (), "Effective Java" , 1 );
92+ assertThat (magazineCustomRepository .save (magazine ))
9393 .isNotNull ()
94- .isEqualTo (book );
94+ .isEqualTo (magazine );
9595
96- assertThat (bookCustomRepository .getById (book .id ()))
96+ assertThat (magazineCustomRepository .getById (magazine .id ()))
9797 .as ("should return the persisted book" )
98- .hasValue (book );
98+ .hasValue (magazine );
9999
100- Book updated = new Book ( book .id (), book .title () + " updated" , 2 );
100+ Magazine updated = new Magazine ( magazine .id (), magazine .title () + " updated" , 2 );
101101
102- assertThat (bookCustomRepository .save (updated ))
102+ assertThat (magazineCustomRepository .save (updated ))
103103 .isNotNull ()
104- .isNotEqualTo (book );
104+ .isNotEqualTo (magazine );
105105
106- assertThat (bookCustomRepository .getById (book .id ()))
106+ assertThat (magazineCustomRepository .getById (magazine .id ()))
107107 .as ("should return the updated book" )
108108 .hasValue (updated );
109109 }
110110
111111 @ Test
112112 void shouldSaveAllAndFindByIdIn () {
113113
114- List <Book > books = List .of (
115- new Book (randomUUID ().toString (), "Java Persistence Layer" , 1 )
116- , new Book (randomUUID ().toString (), "Effective Java" , 3 )
117- , new Book (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 )
118- , new Book (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 )
114+ List <Magazine > magazines = List .of (
115+ new Magazine (randomUUID ().toString (), "Java Persistence Layer" , 1 )
116+ , new Magazine (randomUUID ().toString (), "Effective Java" , 3 )
117+ , new Magazine (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 )
118+ , new Magazine (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 )
119119 );
120120
121- assertThat (bookCustomRepository .saveAll (books ))
121+ assertThat (magazineCustomRepository .saveAll (magazines ))
122122 .isNotNull ()
123- .containsAll (books );
123+ .containsAll (magazines );
124124
125- assertThat (bookCustomRepository .findByIdIn (books .stream ().map (Book ::id ).toList ()))
125+ assertThat (magazineCustomRepository .findByIdIn (magazines .stream ().map (Magazine ::id ).toList ()))
126126 .as ("should return the persisted books" )
127- .containsAll (books );
127+ .containsAll (magazines );
128128
129129 }
130130
131131 @ Test
132132 void shouldSaveAllAndFindBy () {
133133
134- Book javaPersistenceLayer = new Book (randomUUID ().toString (), "Java Persistence Layer" , 1 );
135- Book effectiveJava = new Book (randomUUID ().toString (), "Effective Java" , 3 );
136- Book jakartaEeCookbook = new Book (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 );
137- Book masteringTheJavaVirtualMachine = new Book (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 );
134+ Magazine javaPersistenceLayer = new Magazine (randomUUID ().toString (), "Java Persistence Layer" , 1 );
135+ Magazine effectiveJava = new Magazine (randomUUID ().toString (), "Effective Java" , 3 );
136+ Magazine jakartaEeCookbook = new Magazine (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 );
137+ Magazine masteringTheJavaVirtualMachine = new Magazine (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 );
138138
139- List <Book > books = List .of (
139+ List <Magazine > magazines = List .of (
140140 javaPersistenceLayer
141141 , effectiveJava
142142 , jakartaEeCookbook
143143 , masteringTheJavaVirtualMachine
144144 );
145145
146- assertThat (bookCustomRepository .saveAll (books ))
146+ assertThat (magazineCustomRepository .saveAll (magazines ))
147147 .isNotNull ()
148- .containsAll (books );
148+ .containsAll (magazines );
149149
150150 PageRequest pageRequest = PageRequest .ofSize (2 );
151- Order <Book > orderByTitleAsc = Order .by (Sort .asc ("title" ));
151+ Order <Magazine > orderByTitleAsc = Order .by (Sort .asc ("title" ));
152152
153- Page <Book > page1 = bookCustomRepository .listAll (pageRequest , orderByTitleAsc );
154- Page <Book > page2 = bookCustomRepository .listAll (page1 .nextPageRequest (), orderByTitleAsc );
155- Page <Book > page3 = bookCustomRepository .listAll (page2 .nextPageRequest (), orderByTitleAsc );
153+ Page <Magazine > page1 = magazineCustomRepository .listAll (pageRequest , orderByTitleAsc );
154+ Page <Magazine > page2 = magazineCustomRepository .listAll (page1 .nextPageRequest (), orderByTitleAsc );
155+ Page <Magazine > page3 = magazineCustomRepository .listAll (page2 .nextPageRequest (), orderByTitleAsc );
156156
157157 assertSoftly (softly -> {
158158
@@ -177,50 +177,50 @@ void shouldSaveAllAndFindBy() {
177177
178178 @ Test
179179 void shouldDelete () {
180- Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
181- assertThat (bookCustomRepository .save (book ))
180+ Magazine magazine = new Magazine (randomUUID ().toString (), "Effective Java" , 1 );
181+ assertThat (magazineCustomRepository .save (magazine ))
182182 .isNotNull ()
183- .isEqualTo (book );
183+ .isEqualTo (magazine );
184184
185- assertThat (bookCustomRepository .getById (book .id ()))
185+ assertThat (magazineCustomRepository .getById (magazine .id ()))
186186 .isNotNull ()
187- .hasValue (book );
187+ .hasValue (magazine );
188188
189- bookCustomRepository .delete (book );
189+ magazineCustomRepository .delete (magazine );
190190
191- assertThat (bookCustomRepository .getById (book .id ()))
191+ assertThat (magazineCustomRepository .getById (magazine .id ()))
192192 .isNotNull ()
193193 .isEmpty ();
194194 }
195195
196196 @ Test
197197 void shouldDeleteAll () {
198198
199- List <Book > books = List .of (
200- new Book (randomUUID ().toString (), "Java Persistence Layer" , 1 )
201- , new Book (randomUUID ().toString (), "Effective Java" , 3 )
202- , new Book (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 )
203- , new Book (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 )
199+ List <Magazine > magazines = List .of (
200+ new Magazine (randomUUID ().toString (), "Java Persistence Layer" , 1 )
201+ , new Magazine (randomUUID ().toString (), "Effective Java" , 3 )
202+ , new Magazine (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 )
203+ , new Magazine (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 )
204204 );
205205
206- assertThat (bookCustomRepository .saveAll (books ))
206+ assertThat (magazineCustomRepository .saveAll (magazines ))
207207 .isNotNull ()
208- .containsAll (books );
208+ .containsAll (magazines );
209209
210210 await ().atMost (Duration .ofSeconds (2 ))
211- .until (() -> bookCustomRepository .listAll ().toList ().size () >= books .size ());
211+ .until (() -> magazineCustomRepository .listAll ().toList ().size () >= magazines .size ());
212212
213- assertThat (bookCustomRepository .listAll ())
213+ assertThat (magazineCustomRepository .listAll ())
214214 .isNotNull ()
215- .containsAll (books );
215+ .containsAll (magazines );
216216
217- bookCustomRepository .deleteAll ();
217+ magazineCustomRepository .deleteAll ();
218218
219219 await ().atMost (Duration .ofSeconds (2 ))
220- .until (() -> bookCustomRepository .listAll ().toList ().isEmpty ());
220+ .until (() -> magazineCustomRepository .listAll ().toList ().isEmpty ());
221221
222222
223- assertThat (bookCustomRepository .listAll ())
223+ assertThat (magazineCustomRepository .listAll ())
224224 .isNotNull ()
225225 .isEmpty ();
226226
@@ -229,32 +229,32 @@ void shouldDeleteAll() {
229229 @ Test
230230 void shouldRemoveAll () {
231231
232- List <Book > books = List .of (
233- new Book (randomUUID ().toString (), "Java Persistence Layer" , 1 )
234- , new Book (randomUUID ().toString (), "Effective Java" , 3 )
235- , new Book (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 )
236- , new Book (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 )
232+ List <Magazine > magazines = List .of (
233+ new Magazine (randomUUID ().toString (), "Java Persistence Layer" , 1 )
234+ , new Magazine (randomUUID ().toString (), "Effective Java" , 3 )
235+ , new Magazine (randomUUID ().toString (), "Jakarta EE Cookbook" , 1 )
236+ , new Magazine (randomUUID ().toString (), "Mastering The Java Virtual Machine" , 1 )
237237 );
238238
239- assertThat (bookCustomRepository .saveAll (books ))
239+ assertThat (magazineCustomRepository .saveAll (magazines ))
240240 .isNotNull ()
241- .containsAll (books );
241+ .containsAll (magazines );
242242
243243 await ().atMost (Duration .ofSeconds (2 ))
244- .until (() -> bookCustomRepository .listAll ().toList ().size () >= books .size ());
244+ .until (() -> magazineCustomRepository .listAll ().toList ().size () >= magazines .size ());
245245
246- assertThat (bookCustomRepository .listAll ())
246+ assertThat (magazineCustomRepository .listAll ())
247247 .isNotNull ()
248- .containsAll (books );
248+ .containsAll (magazines );
249249
250- bookCustomRepository .removeAll (books );
250+ magazineCustomRepository .removeAll (magazines );
251251
252252 await ().atMost (Duration .ofSeconds (2 ))
253- .until (() -> bookCustomRepository .listAll ()
254- .filter (books ::contains )
253+ .until (() -> magazineCustomRepository .listAll ()
254+ .filter (magazines ::contains )
255255 .toList ().isEmpty ());
256256
257- assertThat (bookCustomRepository .findByIdIn (books .stream ().map (Book ::id ).toList ()))
257+ assertThat (magazineCustomRepository .findByIdIn (magazines .stream ().map (Magazine ::id ).toList ()))
258258 .isNotNull ()
259259 .isEmpty ();
260260 }
0 commit comments