@@ -47,10 +47,14 @@ void cleanUp() {
47
47
48
48
@ Test
49
49
void testBasicCrudOperations () {
50
- Company redis = repository .save (
51
- Company .
of (
"RedisInc" ,
2011 ,
LocalDate .
of (
2021 ,
5 ,
1 ),
new Point (-
122.066540 ,
37.377690 ),
"[email protected] " ));
52
- Company microsoft = repository .save (Company .of ("Microsoft" , 1975 , LocalDate .of (2022 , 8 , 15 ),
53
- new Point (-
122.124500 ,
47.640160 ),
"[email protected] " ));
50
+ Company redis =
Company .
of (
"RedisInc" ,
2011 ,
LocalDate .
of (
2021 ,
5 ,
1 ),
new Point (-
122.066540 ,
37.377690 ),
"[email protected] " );
51
+ redis .setMetaList (Set .of (CompanyMeta .of ("Redis" , 100 , Set .of ("RedisTag" ))));
52
+
53
+ Company microsoft = Company .of ("Microsoft" , 1975 , LocalDate .of (2022 , 8 , 15 ),
54
+ new Point (-
122.124500 ,
47.640160 ),
"[email protected] " );
55
+ microsoft .setMetaList (Set .of (CompanyMeta .of ("MS" , 50 , Set .of ("MsTag" ))));
56
+
57
+ repository .saveAll (List .of (redis , microsoft ));
54
58
55
59
assertEquals (2 , repository .count ());
56
60
@@ -452,4 +456,72 @@ void testSearchContainingAllInSetOfLocations() {
452
456
var docs = docWithSetsRepository .findByTheLocationsContainingAll (Set .of (point1 , point2 ));
453
457
assertThat (docs ).containsOnly (doc1 , doc2 );
454
458
}
459
+
460
+ @ Test
461
+ void testFindByTagsInNestedField () {
462
+ Company redis =
Company .
of (
"RedisInc" ,
2011 ,
LocalDate .
of (
2021 ,
5 ,
1 ),
new Point (-
122.066540 ,
37.377690 ),
"[email protected] " );
463
+ redis .setMetaList (Set .of (CompanyMeta .of ("Redis" , 100 , Set .of ("RedisTag" , "CommonTag" ))));
464
+
465
+ Company microsoft = Company .of ("Microsoft" , 1975 , LocalDate .of (2022 , 8 , 15 ),
466
+ new Point (-
122.124500 ,
47.640160 ),
"[email protected] " );
467
+ microsoft .setMetaList (Set .of (CompanyMeta .of ("MS" , 50 , Set .of ("MsTag" , "CommonTag" ))));
468
+
469
+ repository .saveAll (List .of (redis , microsoft ));
470
+
471
+ assertEquals (2 , repository .count ());
472
+
473
+ List <Company > shouldBeOnlyRedis = repository .findByMetaList_tagValues (Set .of ("RedisTag" ));
474
+ List <Company > shouldBeOnlyMS = repository .findByMetaList_tagValues (Set .of ("MsTag" ));
475
+ List <Company > shouldBeBoth = repository .findByMetaList_tagValues (Set .of ("CommonTag" ));
476
+
477
+ assertAll ( //
478
+ () -> assertThat (shouldBeOnlyRedis ).hasSize (1 ).allSatisfy (c -> c .getName ().equalsIgnoreCase ("RedisInc" )), //
479
+ () -> assertThat (shouldBeOnlyMS ).hasSize (1 ).allSatisfy (c -> c .getName ().equalsIgnoreCase ("Microsoft" )), //
480
+ () -> assertThat (shouldBeBoth ).hasSize (2 ).map (Company ::getName ).containsExactlyInAnyOrder ("RedisInc" , "Microsoft" ) //
481
+ );
482
+ }
483
+
484
+ @ Test
485
+ void testFindByStringValueInNestedField () {
486
+ Company redis =
Company .
of (
"RedisInc" ,
2011 ,
LocalDate .
of (
2021 ,
5 ,
1 ),
new Point (-
122.066540 ,
37.377690 ),
"[email protected] " );
487
+ redis .setMetaList (Set .of (CompanyMeta .of ("RD" , 100 , Set .of ("RedisTag" , "CommonTag" ))));
488
+
489
+ Company microsoft = Company .of ("Microsoft" , 1975 , LocalDate .of (2022 , 8 , 15 ),
490
+ new Point (-
122.124500 ,
47.640160 ),
"[email protected] " );
491
+ microsoft .setMetaList (Set .of (CompanyMeta .of ("MS" , 50 , Set .of ("MsTag" , "CommonTag" ))));
492
+
493
+ repository .saveAll (List .of (redis , microsoft ));
494
+
495
+ assertEquals (2 , repository .count ());
496
+
497
+ List <Company > shouldBeOnlyRedis = repository .findByMetaList_stringValue ("RD" );
498
+ List <Company > shouldBeOnlyMS = repository .findByMetaList_stringValue ("MS" );
499
+
500
+ assertAll ( //
501
+ () -> assertThat (shouldBeOnlyRedis ).hasSize (1 ).allSatisfy (c -> c .getName ().equalsIgnoreCase ("RedisInc" )), //
502
+ () -> assertThat (shouldBeOnlyMS ).hasSize (1 ).allSatisfy (c -> c .getName ().equalsIgnoreCase ("Microsoft" )) //
503
+ );
504
+ }
505
+
506
+ @ Test
507
+ void testFindByNumericValueInNestedField () {
508
+ Company redis =
Company .
of (
"RedisInc" ,
2011 ,
LocalDate .
of (
2021 ,
5 ,
1 ),
new Point (-
122.066540 ,
37.377690 ),
"[email protected] " );
509
+ redis .setMetaList (Set .of (CompanyMeta .of ("RD" , 100 , Set .of ("RedisTag" , "CommonTag" ))));
510
+
511
+ Company microsoft = Company .of ("Microsoft" , 1975 , LocalDate .of (2022 , 8 , 15 ),
512
+ new Point (-
122.124500 ,
47.640160 ),
"[email protected] " );
513
+ microsoft .setMetaList (Set .of (CompanyMeta .of ("MS" , 50 , Set .of ("MsTag" , "CommonTag" ))));
514
+
515
+ repository .saveAll (List .of (redis , microsoft ));
516
+
517
+ assertEquals (2 , repository .count ());
518
+
519
+ List <Company > shouldBeOnlyRedis = repository .findByMetaList_numberValue (100 );
520
+ List <Company > shouldBeOnlyMS = repository .findByMetaList_numberValue (50 );
521
+
522
+ assertAll ( //
523
+ () -> assertThat (shouldBeOnlyRedis ).hasSize (1 ).allSatisfy (c -> c .getName ().equalsIgnoreCase ("RedisInc" )), //
524
+ () -> assertThat (shouldBeOnlyMS ).hasSize (1 ).allSatisfy (c -> c .getName ().equalsIgnoreCase ("Microsoft" )) //
525
+ );
526
+ }
455
527
}
0 commit comments