1
1
/*
2
- * Copyright 2015 the original author or authors.
2
+ * Copyright 2015-216 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
import java .lang .annotation .Annotation ;
28
28
import java .util .ArrayList ;
29
29
import java .util .LinkedHashMap ;
30
+ import java .util .List ;
31
+ import java .util .Map ;
30
32
import java .util .Set ;
31
33
32
34
import org .hamcrest .core .IsCollectionContaining ;
@@ -66,8 +68,8 @@ public class PathIndexResolverUnitTests {
66
68
public void setUp () {
67
69
68
70
indexConfig = new IndexConfiguration ();
69
- this .indexResolver = new PathIndexResolver (new RedisMappingContext ( new MappingConfiguration ( indexConfig ,
70
- new KeyspaceConfiguration ())));
71
+ this .indexResolver = new PathIndexResolver (
72
+ new RedisMappingContext ( new MappingConfiguration ( indexConfig , new KeyspaceConfiguration ())));
71
73
}
72
74
73
75
/**
@@ -146,9 +148,10 @@ public void shouldResolveMultipleAnnotatedIndexesInLists() {
146
148
Set <IndexedData > indexes = indexResolver .resolveIndexesFor (ClassTypeInformation .from (TheWheelOfTime .class ), twot );
147
149
148
150
assertThat (indexes .size (), is (2 ));
149
- assertThat (indexes , IsCollectionContaining .<IndexedData > hasItems (new SimpleIndexedPropertyValue (KEYSPACE_TWOT ,
150
- "mainCharacters.address.country" , "andor" ), new SimpleIndexedPropertyValue (KEYSPACE_TWOT ,
151
- "mainCharacters.address.country" , "saldaea" )));
151
+ assertThat (indexes ,
152
+ IsCollectionContaining .<IndexedData > hasItems (
153
+ new SimpleIndexedPropertyValue (KEYSPACE_TWOT , "mainCharacters.address.country" , "andor" ),
154
+ new SimpleIndexedPropertyValue (KEYSPACE_TWOT , "mainCharacters.address.country" , "saldaea" )));
152
155
}
153
156
154
157
/**
@@ -171,8 +174,8 @@ public void shouldResolveAnnotatedIndexesInMap() {
171
174
Set <IndexedData > indexes = indexResolver .resolveIndexesFor (ClassTypeInformation .from (TheWheelOfTime .class ), twot );
172
175
173
176
assertThat (indexes .size (), is (1 ));
174
- assertThat (indexes , hasItem ( new SimpleIndexedPropertyValue ( KEYSPACE_TWOT , "places.stone-of-tear.address.country" ,
175
- "illian" )));
177
+ assertThat (indexes ,
178
+ hasItem ( new SimpleIndexedPropertyValue ( KEYSPACE_TWOT , "places.stone-of-tear.address.country" , "illian" )));
176
179
}
177
180
178
181
/**
@@ -245,8 +248,8 @@ public void shouldNotResolveIndexOnReferencedEntity() {
245
248
rand .addressRef .id = "emond_s_field" ;
246
249
rand .addressRef .country = "andor" ;
247
250
248
- Set <IndexedData > indexes = indexResolver . resolveIndexesFor (
249
- ClassTypeInformation .from (PersonWithAddressReference .class ), rand );
251
+ Set <IndexedData > indexes = indexResolver
252
+ . resolveIndexesFor ( ClassTypeInformation .from (PersonWithAddressReference .class ), rand );
250
253
251
254
assertThat (indexes .size (), is (0 ));
252
255
}
@@ -443,6 +446,50 @@ public void resolveIndexForTypeThatHasNoIndexDefined() {
443
446
assertThat (indexes , is (empty ()));
444
447
}
445
448
449
+ /**
450
+ * @see DATAREDIS-425
451
+ */
452
+ @ Test
453
+ public void resolveIndexOnMapField () {
454
+
455
+ IndexedOnMapField source = new IndexedOnMapField ();
456
+ source .values = new LinkedHashMap <String , String >();
457
+
458
+ source .values .put ("jon" , "snow" );
459
+ source .values .put ("arya" , "stark" );
460
+
461
+ Set <IndexedData > indexes = indexResolver .resolveIndexesFor (ClassTypeInformation .from (IndexedOnMapField .class ),
462
+ source );
463
+
464
+ assertThat (indexes .size (), is (2 ));
465
+ assertThat (indexes ,
466
+ IsCollectionContaining .<IndexedData > hasItems (
467
+ new SimpleIndexedPropertyValue (IndexedOnMapField .class .getName (), "values.jon" , "snow" ),
468
+ new SimpleIndexedPropertyValue (IndexedOnMapField .class .getName (), "values.arya" , "stark" )));
469
+ }
470
+
471
+ /**
472
+ * @see DATAREDIS-425
473
+ */
474
+ @ Test
475
+ public void resolveIndexOnListField () {
476
+
477
+ IndexedOnListField source = new IndexedOnListField ();
478
+ source .values = new ArrayList <String >();
479
+
480
+ source .values .add ("jon" );
481
+ source .values .add ("arya" );
482
+
483
+ Set <IndexedData > indexes = indexResolver .resolveIndexesFor (ClassTypeInformation .from (IndexedOnListField .class ),
484
+ source );
485
+
486
+ assertThat (indexes .size (), is (2 ));
487
+ assertThat (indexes ,
488
+ IsCollectionContaining .<IndexedData > hasItems (
489
+ new SimpleIndexedPropertyValue (IndexedOnListField .class .getName (), "values" , "jon" ),
490
+ new SimpleIndexedPropertyValue (IndexedOnListField .class .getName (), "values" , "arya" )));
491
+ }
492
+
446
493
private IndexedData resolve (String path , Object value ) {
447
494
448
495
Set <IndexedData > data = indexResolver .resolveIndex (KEYSPACE_PERSON , path , propertyMock , value );
@@ -466,4 +513,15 @@ public Class<? extends Annotation> annotationType() {
466
513
467
514
};
468
515
}
516
+
517
+ static class IndexedOnListField {
518
+
519
+ @ Indexed List <String > values ;
520
+ }
521
+
522
+ static class IndexedOnMapField {
523
+
524
+ @ Indexed Map <String , String > values ;
525
+ }
526
+
469
527
}
0 commit comments