54
54
import org .springframework .core .convert .converter .Converter ;
55
55
import org .springframework .data .convert .ReadingConverter ;
56
56
import org .springframework .data .convert .WritingConverter ;
57
+ import org .springframework .data .mapping .model .MappingException ;
57
58
import org .springframework .data .redis .core .PartialUpdate ;
58
59
import org .springframework .data .redis .core .convert .ConversionTestEntities .Address ;
59
60
import org .springframework .data .redis .core .convert .ConversionTestEntities .AddressWithId ;
@@ -1345,7 +1346,7 @@ public void writeShouldNotAppendClassTypeHint() {
1345
1346
* @see DATAREDIS-471
1346
1347
*/
1347
1348
@ Test
1348
- public void writeShouldWritePartialUpdateValueCorrectly () {
1349
+ public void writeShouldWritePartialUpdateSimpleValueCorrectly () {
1349
1350
1350
1351
Person value = new Person ();
1351
1352
value .firstname = "rand" ;
@@ -1361,11 +1362,7 @@ public void writeShouldWritePartialUpdateValueCorrectly() {
1361
1362
* @see DATAREDIS-471
1362
1363
*/
1363
1364
@ Test
1364
- public void writeShouldWritePartialUpdatePathValueCorrectly () {
1365
-
1366
- Person value = new Person ();
1367
- value .firstname = "rand" ;
1368
- value .age = 24 ;
1365
+ public void writeShouldWritePartialUpdatePathWithSimpleValueCorrectly () {
1369
1366
1370
1367
PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("firstname" , "rand" ).set ("age" ,
1371
1368
24 );
@@ -1374,6 +1371,213 @@ public void writeShouldWritePartialUpdatePathValueCorrectly() {
1374
1371
isBucket ().containingUtf8String ("firstname" , "rand" ).containingUtf8String ("age" , "24" ));
1375
1372
}
1376
1373
1374
+ /**
1375
+ * @see DATAREDIS-471
1376
+ */
1377
+ @ Test
1378
+ public void writeShouldWritePartialUpdateNestedPathWithSimpleValueCorrectly () {
1379
+
1380
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("address.city" , "two rivers" );
1381
+
1382
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("address.city" , "two rivers" ));
1383
+ }
1384
+
1385
+ /**
1386
+ * @see DATAREDIS-471
1387
+ */
1388
+ @ Test
1389
+ public void writeShouldWritePartialUpdatePathWithComplexValueCorrectly () {
1390
+
1391
+ Address address = new Address ();
1392
+ address .city = "two rivers" ;
1393
+ address .country = "andor" ;
1394
+
1395
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("address" , address );
1396
+
1397
+ assertThat (write (update ).getBucket (),
1398
+ isBucket ().containingUtf8String ("address.city" , "two rivers" ).containingUtf8String ("address.country" , "andor" ));
1399
+ }
1400
+
1401
+ /**
1402
+ * @see DATAREDIS-471
1403
+ */
1404
+ @ Test
1405
+ public void writeShouldWritePartialUpdatePathWithSimpleListValueCorrectly () {
1406
+
1407
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("nicknames" ,
1408
+ Arrays .asList ("dragon" , "lews" ));
1409
+
1410
+ assertThat (write (update ).getBucket (),
1411
+ isBucket ().containingUtf8String ("nicknames.[0]" , "dragon" ).containingUtf8String ("nicknames.[1]" , "lews" ));
1412
+ }
1413
+
1414
+ /**
1415
+ * @see DATAREDIS-471
1416
+ */
1417
+ @ Test
1418
+ public void writeShouldWritePartialUpdatePathWithComplexListValueCorrectly () {
1419
+
1420
+ Person mat = new Person ();
1421
+ mat .firstname = "mat" ;
1422
+ mat .age = 24 ;
1423
+
1424
+ Person perrin = new Person ();
1425
+ perrin .firstname = "perrin" ;
1426
+
1427
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("coworkers" ,
1428
+ Arrays .asList (mat , perrin ));
1429
+
1430
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("coworkers.[0].firstname" , "mat" )
1431
+ .containingUtf8String ("coworkers.[0].age" , "24" ).containingUtf8String ("coworkers.[1].firstname" , "perrin" ));
1432
+ }
1433
+
1434
+ /**
1435
+ * @see DATAREDIS-471
1436
+ */
1437
+ @ Test
1438
+ public void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionCorrectly () {
1439
+
1440
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("nicknames" , "dragon" );
1441
+
1442
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("nicknames.[0]" , "dragon" ));
1443
+ }
1444
+
1445
+ /**
1446
+ * @see DATAREDIS-471
1447
+ */
1448
+ @ Test
1449
+ public void writeShouldWritePartialUpdatePathWithComplexListValueWhenNotPassedInAsCollectionCorrectly () {
1450
+
1451
+ Person mat = new Person ();
1452
+ mat .firstname = "mat" ;
1453
+ mat .age = 24 ;
1454
+
1455
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("coworkers" , mat );
1456
+
1457
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("coworkers.[0].firstname" , "mat" )
1458
+ .containingUtf8String ("coworkers.[0].age" , "24" ));
1459
+ }
1460
+
1461
+ /**
1462
+ * @see DATAREDIS-471
1463
+ */
1464
+ @ Test
1465
+ public void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly () {
1466
+
1467
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("nicknames.[5]" , "dragon" );
1468
+
1469
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("nicknames.[5]" , "dragon" ));
1470
+ }
1471
+
1472
+ /**
1473
+ * @see DATAREDIS-471
1474
+ */
1475
+ @ Test
1476
+ public void writeShouldWritePartialUpdatePathWithComplexListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly () {
1477
+
1478
+ Person mat = new Person ();
1479
+ mat .firstname = "mat" ;
1480
+ mat .age = 24 ;
1481
+
1482
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("coworkers.[5]" , mat );
1483
+
1484
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("coworkers.[5].firstname" , "mat" )
1485
+ .containingUtf8String ("coworkers.[5].age" , "24" ));
1486
+ }
1487
+
1488
+ /**
1489
+ * @see DATAREDIS-471
1490
+ */
1491
+ @ Test
1492
+ public void writeShouldWritePartialUpdatePathWithSimpleMapValueCorrectly () {
1493
+
1494
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("physicalAttributes" ,
1495
+ Collections .singletonMap ("eye-color" , "grey" ));
1496
+
1497
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("physicalAttributes.[eye-color]" , "grey" ));
1498
+ }
1499
+
1500
+ /**
1501
+ * @see DATAREDIS-471
1502
+ */
1503
+ @ Test
1504
+ public void writeShouldWritePartialUpdatePathWithComplexMapValueCorrectly () {
1505
+
1506
+ Person tam = new Person ();
1507
+ tam .firstname = "tam" ;
1508
+ tam .alive = false ;
1509
+
1510
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("relatives" ,
1511
+ Collections .singletonMap ("father" , tam ));
1512
+
1513
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("relatives.[father].firstname" , "tam" )
1514
+ .containingUtf8String ("relatives.[father].alive" , "0" ));
1515
+ }
1516
+
1517
+ /**
1518
+ * @see DATAREDIS-471
1519
+ */
1520
+ @ Test
1521
+ public void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionCorrectly () {
1522
+
1523
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("physicalAttributes" ,
1524
+ Collections .singletonMap ("eye-color" , "grey" ).entrySet ().iterator ().next ());
1525
+
1526
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("physicalAttributes.[eye-color]" , "grey" ));
1527
+ }
1528
+
1529
+ /**
1530
+ * @see DATAREDIS-471
1531
+ */
1532
+ @ Test
1533
+ public void writeShouldWritePartialUpdatePathWithComplexMapValueWhenNotPassedInAsCollectionCorrectly () {
1534
+
1535
+ Person tam = new Person ();
1536
+ tam .firstname = "tam" ;
1537
+ tam .alive = false ;
1538
+
1539
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("relatives" ,
1540
+ Collections .singletonMap ("father" , tam ).entrySet ().iterator ().next ());
1541
+
1542
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("relatives.[father].firstname" , "tam" )
1543
+ .containingUtf8String ("relatives.[father].alive" , "0" ));
1544
+ }
1545
+
1546
+ /**
1547
+ * @see DATAREDIS-471
1548
+ */
1549
+ @ Test
1550
+ public void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly () {
1551
+
1552
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("physicalAttributes.[eye-color]" ,
1553
+ "grey" );
1554
+
1555
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("physicalAttributes.[eye-color]" , "grey" ));
1556
+ }
1557
+
1558
+ /**
1559
+ * @see DATAREDIS-471
1560
+ */
1561
+ @ Test
1562
+ public void writeShouldWritePartialUpdatePathWithSimpleMapValueOnNestedElementCorrectly () {
1563
+
1564
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("relatives.[father].firstname" ,
1565
+ "tam" );
1566
+
1567
+ assertThat (write (update ).getBucket (), isBucket ().containingUtf8String ("relatives.[father].firstname" , "tam" ));
1568
+ }
1569
+
1570
+ /**
1571
+ * @see DATAREDIS-471
1572
+ */
1573
+ @ Test (expected = MappingException .class )
1574
+ public void writeShouldThrowExceptionOnPartialUpdatePathWithSimpleMapValueWhenItsASingleValueWithoutPath () {
1575
+
1576
+ PartialUpdate <Person > update = new PartialUpdate <Person >("123" , Person .class ).set ("physicalAttributes" , "grey" );
1577
+
1578
+ write (update );
1579
+ }
1580
+
1377
1581
private RedisData write (Object source ) {
1378
1582
1379
1583
RedisData rdo = new RedisData ();
0 commit comments