1818import static org .assertj .core .api .Assertions .*;
1919import static org .springframework .data .mongodb .core .query .Criteria .*;
2020import static org .springframework .data .mongodb .core .query .Query .*;
21+ import static org .springframework .data .mongodb .test .util .DirtiesStateExtension .*;
2122
2223import lombok .AllArgsConstructor ;
2324import lombok .Data ;
3536import org .bson .BsonString ;
3637import org .bson .BsonValue ;
3738import org .bson .Document ;
38- import org .junit .jupiter .api .BeforeEach ;
3939import org .junit .jupiter .api .Test ;
40+ import org .junit .jupiter .api .TestInstance ;
4041import org .junit .jupiter .api .extension .ExtendWith ;
42+
4143import org .springframework .beans .factory .annotation .Value ;
4244import org .springframework .dao .IncorrectResultSizeDataAccessException ;
4345import org .springframework .dao .InvalidDataAccessApiUsageException ;
5052import org .springframework .data .mongodb .core .query .Criteria ;
5153import org .springframework .data .mongodb .core .query .NearQuery ;
5254import org .springframework .data .mongodb .test .util .Client ;
55+ import org .springframework .data .mongodb .test .util .DirtiesStateExtension ;
5356import org .springframework .data .mongodb .test .util .MongoClientExtension ;
5457
5558import com .mongodb .client .MongoClient ;
6164 * @author Christoph Strobl
6265 * @author Juergen Zimmermann
6366 */
64- @ ExtendWith (MongoClientExtension .class )
65- class ReactiveFindOperationSupportTests {
67+ @ ExtendWith ({ MongoClientExtension .class , DirtiesStateExtension .class })
68+ @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
69+ class ReactiveFindOperationSupportTests implements StateFunctions {
6670
6771 private static final String STAR_WARS = "star-wars" ;
6872 private MongoTemplate blocking ;
@@ -74,15 +78,25 @@ class ReactiveFindOperationSupportTests {
7478 private Person han ;
7579 private Person luke ;
7680
77- @ BeforeEach
7881 void setUp () {
79-
8082 blocking = new MongoTemplate (new SimpleMongoClientDatabaseFactory (client , "ExecutableFindOperationSupportTests" ));
83+ template = new ReactiveMongoTemplate (reactiveClient , "ExecutableFindOperationSupportTests" );
84+ }
85+
86+ @ Override
87+ public void clear () {
88+ if (blocking == null ) {
89+ setUp ();
90+ }
8191 recreateCollection (STAR_WARS , false );
92+ }
8293
94+ @ Override
95+ public void setupState () {
96+ if (blocking == null ) {
97+ setUp ();
98+ }
8399 insertObjects ();
84-
85- template = new ReactiveMongoTemplate (reactiveClient , "ExecutableFindOperationSupportTests" );
86100 }
87101
88102 void insertObjects () {
@@ -244,6 +258,7 @@ void findByTooManyResults() {
244258 }
245259
246260 @ Test // DATAMONGO-1719
261+ @ DirtiesState
247262 void findAllNearBy () {
248263
249264 blocking .indexOps (Planet .class ).ensureIndex (
@@ -264,6 +279,7 @@ void findAllNearBy() {
264279 }
265280
266281 @ Test // DATAMONGO-1719
282+ @ DirtiesState
267283 void findAllNearByWithCollectionAndProjection () {
268284
269285 blocking .indexOps (Planet .class ).ensureIndex (
@@ -287,6 +303,7 @@ void findAllNearByWithCollectionAndProjection() {
287303 }
288304
289305 @ Test // DATAMONGO-1719
306+ @ DirtiesState
290307 void findAllNearByReturningGeoResultContentAsClosedInterfaceProjection () {
291308
292309 blocking .indexOps (Planet .class ).ensureIndex (
@@ -310,6 +327,7 @@ void findAllNearByReturningGeoResultContentAsClosedInterfaceProjection() {
310327 }
311328
312329 @ Test // DATAMONGO-1719
330+ @ DirtiesState
313331 void findAllNearByReturningGeoResultContentAsOpenInterfaceProjection () {
314332
315333 blocking .indexOps (Planet .class ).ensureIndex (
@@ -333,6 +351,7 @@ void findAllNearByReturningGeoResultContentAsOpenInterfaceProjection() {
333351 }
334352
335353 @ Test // DATAMONGO-2080
354+ @ ProvidesState
336355 void tail () throws InterruptedException {
337356
338357 recreateCollection (STAR_WARS , true );
@@ -361,6 +380,7 @@ void tail() throws InterruptedException {
361380 }
362381
363382 @ Test // DATAMONGO-2080
383+ @ ProvidesState
364384 void tailWithProjection () {
365385
366386 recreateCollection (STAR_WARS , true );
@@ -374,6 +394,7 @@ void tailWithProjection() {
374394 }
375395
376396 @ Test // DATAMONGO-2080
397+ @ ProvidesState
377398 void tailWithClosedInterfaceProjection () {
378399
379400 recreateCollection (STAR_WARS , true );
@@ -391,6 +412,7 @@ void tailWithClosedInterfaceProjection() {
391412 }
392413
393414 @ Test // DATAMONGO-2080
415+ @ ProvidesState
394416 void tailWithOpenInterfaceProjection () {
395417
396418 recreateCollection (STAR_WARS , true );
@@ -431,6 +453,7 @@ void existsShouldReturnTrueIfAtLeastOneElementExistsInCollection() {
431453 }
432454
433455 @ Test // DATAMONGO-1719
456+ @ DirtiesState
434457 void existsShouldReturnFalseIfNoElementExistsInCollection () {
435458
436459 blocking .remove (new BasicQuery ("{}" ), STAR_WARS );
@@ -462,6 +485,7 @@ void distinctReturnsEmptyListIfNoMatchFound() {
462485 }
463486
464487 @ Test // DATAMONGO-1761
488+ @ DirtiesState
465489 void distinctReturnsSimpleFieldValuesCorrectlyForCollectionHavingReturnTypeSpecifiedThatCanBeConvertedDirectlyByACodec () {
466490
467491 Person anakin = new Person ();
@@ -476,6 +500,7 @@ void distinctReturnsSimpleFieldValuesCorrectlyForCollectionHavingReturnTypeSpeci
476500 }
477501
478502 @ Test // DATAMONGO-1761
503+ @ DirtiesState
479504 void distinctReturnsSimpleFieldValuesCorrectly () {
480505
481506 Person anakin = new Person ();
@@ -504,6 +529,7 @@ void distinctReturnsSimpleFieldValuesCorrectly() {
504529 }
505530
506531 @ Test // DATAMONGO-1761
532+ @ DirtiesState
507533 void distinctReturnsComplexValuesCorrectly () {
508534
509535 Sith sith = new Sith ();
@@ -521,6 +547,7 @@ void distinctReturnsComplexValuesCorrectly() {
521547 }
522548
523549 @ Test // DATAMONGO-1761
550+ @ DirtiesState
524551 void distinctReturnsComplexValuesCorrectlyHavingReturnTypeSpecified () {
525552
526553 Sith sith = new Sith ();
@@ -538,6 +565,7 @@ void distinctReturnsComplexValuesCorrectlyHavingReturnTypeSpecified() {
538565 }
539566
540567 @ Test // DATAMONGO-1761
568+ @ DirtiesState
541569 void distinctReturnsComplexValuesCorrectlyReturnTypeDocumentSpecified () {
542570
543571 Sith sith = new Sith ();
@@ -573,6 +601,7 @@ void distinctReturnsRawValuesIfReturnTypeIsBsonValue() {
573601 }
574602
575603 @ Test // DATAMONGO-1761
604+ @ DirtiesState
576605 void distinctReturnsValuesMappedToTheirJavaTypeEvenWhenNotExplicitlyDefinedByTheDomainType () {
577606
578607 blocking .save (new Document ("darth" , "vader" ), STAR_WARS );
@@ -583,6 +612,7 @@ void distinctReturnsValuesMappedToTheirJavaTypeEvenWhenNotExplicitlyDefinedByThe
583612 }
584613
585614 @ Test // DATAMONGO-1761
615+ @ DirtiesState
586616 void distinctReturnsMappedDomainTypeForProjections () {
587617
588618 luke .father = new Person ();
@@ -596,6 +626,7 @@ void distinctReturnsMappedDomainTypeForProjections() {
596626 }
597627
598628 @ Test // DATAMONGO-1761
629+ @ DirtiesState
599630 void distinctAlllowsQueryUsingObjectSourceType () {
600631
601632 luke .father = new Person ();
@@ -609,6 +640,7 @@ void distinctAlllowsQueryUsingObjectSourceType() {
609640 }
610641
611642 @ Test // DATAMONGO-1761
643+ @ DirtiesState
612644 void distinctReturnsMappedDomainTypeExtractedFromPropertyWhenNoExplicitTypePresent () {
613645
614646 luke .father = new Person ();
0 commit comments