47
47
import java .util .Map ;
48
48
import java .util .UUID ;
49
49
50
+ import org .hamcrest .core .IsEqual ;
50
51
import org .junit .Before ;
51
52
import org .junit .Test ;
52
53
import org .junit .runner .RunWith ;
66
67
import org .springframework .data .redis .core .convert .ConversionTestEntities .Species ;
67
68
import org .springframework .data .redis .core .convert .ConversionTestEntities .TaVeren ;
68
69
import org .springframework .data .redis .core .convert .ConversionTestEntities .TheWheelOfTime ;
70
+ import org .springframework .data .redis .core .convert .ConversionTestEntities .WithArrays ;
69
71
import org .springframework .data .redis .core .convert .KeyspaceConfiguration .KeyspaceSettings ;
70
72
import org .springframework .data .redis .core .mapping .RedisMappingContext ;
71
73
import org .springframework .data .redis .serializer .Jackson2JsonRedisSerializer ;
@@ -437,27 +439,6 @@ public void writeAppendsMapWithSimpleKeyCorrectly() {
437
439
.containingUtf8String ("physicalAttributes.[eye-color]" , "grey" ));
438
440
}
439
441
440
- /**
441
- * @see DATAREDIS-492
442
- */
443
- @ Test
444
- public void writeHandlesArraysProperly () {
445
-
446
- this .converter = new MappingRedisConverter (null , null , resolverMock );
447
- this .converter
448
- .setCustomConversions (new CustomConversions (Collections .singletonList (new ListToByteConverter ())));
449
- this .converter .afterPropertiesSet ();
450
-
451
- Map <String , Object > innerMap = new LinkedHashMap <String , Object >();
452
- innerMap .put ("address" , "tyrionl@netflix.com" );
453
- innerMap .put ("when" , new String []{"pipeline.failed" });
454
-
455
- Map <String , Object > map = new LinkedHashMap <String , Object >();
456
- map .put ("email" , Collections .singletonList (innerMap ));
457
-
458
- RedisData target = write (map );
459
- }
460
-
461
442
/**
462
443
* @see DATAREDIS-425
463
444
*/
@@ -1348,13 +1329,115 @@ public void readShouldConsiderMapConvertersForValuesInList() {
1348
1329
assertThat (target .species .get (0 ).name , is ("trolloc" ));
1349
1330
}
1350
1331
1332
+ /**
1333
+ * @see DATAREDIS-492
1334
+ */
1335
+ @ Test
1336
+ public void writeHandlesArraysProperly () {
1337
+
1338
+ this .converter = new MappingRedisConverter (null , null , resolverMock );
1339
+ this .converter .setCustomConversions (new CustomConversions (Collections .singletonList (new ListToByteConverter ())));
1340
+ this .converter .afterPropertiesSet ();
1341
+
1342
+ Map <String , Object > innerMap = new LinkedHashMap <String , Object >();
1343
+ innerMap .put ("address" , "tyrionl@netflix.com" );
1344
+ innerMap .put ("when" , new String [] { "pipeline.failed" });
1345
+
1346
+ Map <String , Object > map = new LinkedHashMap <String , Object >();
1347
+ map .put ("email" , Collections .singletonList (innerMap ));
1348
+
1349
+ RedisData target = write (map );
1350
+ }
1351
+
1352
+ /**
1353
+ * @see DATAREDIS-492
1354
+ */
1355
+ @ Test
1356
+ public void writeHandlesArraysOfSimpleTypeProperly () {
1357
+
1358
+ WithArrays source = new WithArrays ();
1359
+ source .arrayOfSimpleTypes = new String [] { "rand" , "mat" , "perrin" };
1360
+
1361
+ assertThat (write (source ).getBucket (),
1362
+ isBucket ().containingUtf8String ("arrayOfSimpleTypes.[0]" , "rand" )
1363
+ .containingUtf8String ("arrayOfSimpleTypes.[1]" , "mat" )
1364
+ .containingUtf8String ("arrayOfSimpleTypes.[2]" , "perrin" ));
1365
+ }
1366
+
1367
+ /**
1368
+ * @see DATAREDIS-492
1369
+ */
1370
+ @ Test
1371
+ public void readHandlesArraysOfSimpleTypeProperly () {
1372
+
1373
+ Map <String , String > source = new LinkedHashMap <String , String >();
1374
+ source .put ("arrayOfSimpleTypes.[0]" , "rand" );
1375
+ source .put ("arrayOfSimpleTypes.[1]" , "mat" );
1376
+ source .put ("arrayOfSimpleTypes.[2]" , "perrin" );
1377
+
1378
+ WithArrays target = read (WithArrays .class , source );
1379
+
1380
+ assertThat (target .arrayOfSimpleTypes , IsEqual .equalTo (new String [] { "rand" , "mat" , "perrin" }));
1381
+ }
1382
+
1383
+ /**
1384
+ * @see DATAREDIS-492
1385
+ */
1386
+ @ Test
1387
+ public void writeHandlesArraysOfComplexTypeProperly () {
1388
+
1389
+ WithArrays source = new WithArrays ();
1390
+
1391
+ Species trolloc = new Species ();
1392
+ trolloc .name = "trolloc" ;
1393
+
1394
+ Species myrddraal = new Species ();
1395
+ myrddraal .name = "myrddraal" ;
1396
+ myrddraal .alsoKnownAs = Arrays .asList ("halfmen" , "fades" , "neverborn" );
1397
+
1398
+ source .arrayOfCompexTypes = new Species [] { trolloc , myrddraal };
1399
+
1400
+ assertThat (write (source ).getBucket (),
1401
+ isBucket ().containingUtf8String ("arrayOfCompexTypes.[0].name" , "trolloc" ) //
1402
+ .containingUtf8String ("arrayOfCompexTypes.[1].name" , "myrddraal" ) //
1403
+ .containingUtf8String ("arrayOfCompexTypes.[1].alsoKnownAs.[0]" , "halfmen" ) //
1404
+ .containingUtf8String ("arrayOfCompexTypes.[1].alsoKnownAs.[1]" , "fades" ) //
1405
+ .containingUtf8String ("arrayOfCompexTypes.[1].alsoKnownAs.[2]" , "neverborn" ));
1406
+ }
1407
+
1408
+ /**
1409
+ * @see DATAREDIS-492
1410
+ */
1411
+ @ Test
1412
+ public void readHandlesArraysOfComplexTypeProperly () {
1413
+
1414
+ Map <String , String > source = new LinkedHashMap <String , String >();
1415
+ source .put ("arrayOfCompexTypes.[0].name" , "trolloc" );
1416
+ source .put ("arrayOfCompexTypes.[1].name" , "myrddraal" );
1417
+ source .put ("arrayOfCompexTypes.[1].alsoKnownAs.[0]" , "halfmen" );
1418
+ source .put ("arrayOfCompexTypes.[1].alsoKnownAs.[1]" , "fades" );
1419
+ source .put ("arrayOfCompexTypes.[1].alsoKnownAs.[2]" , "neverborn" );
1420
+
1421
+ WithArrays target = read (WithArrays .class , source );
1422
+
1423
+ assertThat (target .arrayOfCompexTypes [0 ], notNullValue ());
1424
+ assertThat (target .arrayOfCompexTypes [0 ].name , is ("trolloc" ));
1425
+ assertThat (target .arrayOfCompexTypes [1 ], notNullValue ());
1426
+ assertThat (target .arrayOfCompexTypes [1 ].name , is ("myrddraal" ));
1427
+ assertThat (target .arrayOfCompexTypes [1 ].alsoKnownAs , contains ("halfmen" , "fades" , "neverborn" ));
1428
+ }
1429
+
1351
1430
private RedisData write (Object source ) {
1352
1431
1353
1432
RedisData rdo = new RedisData ();
1354
1433
converter .write (source , rdo );
1355
1434
return rdo ;
1356
1435
}
1357
1436
1437
+ private <T > T read (Class <T > type , Map <String , String > source ) {
1438
+ return converter .read (type , new RedisData (Bucket .newBucketFromStringMap (source )));
1439
+ }
1440
+
1358
1441
@ WritingConverter
1359
1442
static class AddressToBytesConverter implements Converter <Address , byte []> {
1360
1443
@@ -1408,8 +1491,8 @@ static class ListToByteConverter implements Converter<List, byte[]> {
1408
1491
1409
1492
mapper = new ObjectMapper ();
1410
1493
mapper .setVisibility (mapper .getSerializationConfig ().getDefaultVisibilityChecker ()
1411
- .withFieldVisibility (Visibility .ANY ).withGetterVisibility (Visibility .NONE )
1412
- .withSetterVisibility (Visibility .NONE ).withCreatorVisibility (Visibility .NONE ));
1494
+ .withFieldVisibility (Visibility .ANY ).withGetterVisibility (Visibility .NONE )
1495
+ .withSetterVisibility (Visibility .NONE ).withCreatorVisibility (Visibility .NONE ));
1413
1496
1414
1497
serializer = new Jackson2JsonRedisSerializer <List >(List .class );
1415
1498
serializer .setObjectMapper (mapper );
@@ -1426,7 +1509,6 @@ public byte[] convert(List source) {
1426
1509
}
1427
1510
}
1428
1511
1429
-
1430
1512
@ ReadingConverter
1431
1513
static class MapToSpeciesConverter implements Converter <Map <String , byte []>, Species > {
1432
1514
0 commit comments