21
21
import static org .springframework .data .mongodb .core .query .Criteria .*;
22
22
23
23
import java .security .SecureRandom ;
24
+ import java .time .LocalDate ;
25
+ import java .time .Month ;
24
26
import java .util .Arrays ;
25
27
import java .util .Collections ;
26
28
import java .util .HashMap ;
@@ -89,6 +91,21 @@ void encryptAndDecryptSimpleValue() {
89
91
.loadedIsEqualToSource ();
90
92
}
91
93
94
+ @ Test // GH-4432
95
+ void encryptAndDecryptJavaTime () {
96
+
97
+ Person source = new Person ();
98
+ source .id = "id-1" ;
99
+ source .today = LocalDate .of (1979 , Month .SEPTEMBER , 18 );
100
+
101
+ template .save (source );
102
+
103
+ verifyThat (source ) //
104
+ .identifiedBy (Person ::getId ) //
105
+ .wasSavedMatching (it -> assertThat (it .get ("today" )).isInstanceOf (Binary .class )) //
106
+ .loadedIsEqualToSource ();
107
+ }
108
+
92
109
@ Test // GH-4284
93
110
void encryptAndDecryptComplexValue () {
94
111
@@ -548,6 +565,9 @@ static class Person {
548
565
@ ExplicitEncrypted (algorithm = AEAD_AES_256_CBC_HMAC_SHA_512_Random ) //
549
566
Map <String , Address > mapOfComplex ;
550
567
568
+ @ ExplicitEncrypted (algorithm = AEAD_AES_256_CBC_HMAC_SHA_512_Random ) //
569
+ LocalDate today ;
570
+
551
571
public String getId () {
552
572
return this .id ;
553
573
}
@@ -592,6 +612,10 @@ public Map<String, Address> getMapOfComplex() {
592
612
return this .mapOfComplex ;
593
613
}
594
614
615
+ public LocalDate getToday () {
616
+ return today ;
617
+ }
618
+
595
619
public void setId (String id ) {
596
620
this .id = id ;
597
621
}
@@ -636,6 +660,10 @@ public void setMapOfComplex(Map<String, Address> mapOfComplex) {
636
660
this .mapOfComplex = mapOfComplex ;
637
661
}
638
662
663
+ public void setToday (LocalDate today ) {
664
+ this .today = today ;
665
+ }
666
+
639
667
@ Override
640
668
public boolean equals (Object o ) {
641
669
if (o == this ) {
@@ -650,21 +678,23 @@ public boolean equals(Object o) {
650
678
&& Objects .equals (encryptedZip , person .encryptedZip ) && Objects .equals (listOfString , person .listOfString )
651
679
&& Objects .equals (listOfComplex , person .listOfComplex )
652
680
&& Objects .equals (viaAltKeyNameField , person .viaAltKeyNameField )
653
- && Objects .equals (mapOfString , person .mapOfString ) && Objects .equals (mapOfComplex , person .mapOfComplex );
681
+ && Objects .equals (mapOfString , person .mapOfString ) && Objects .equals (mapOfComplex , person .mapOfComplex )
682
+ && Objects .equals (today , person .today );
654
683
}
655
684
656
685
@ Override
657
686
public int hashCode () {
658
687
return Objects .hash (id , name , ssn , wallet , address , encryptedZip , listOfString , listOfComplex , viaAltKeyNameField ,
659
- mapOfString , mapOfComplex );
688
+ mapOfString , mapOfComplex , today );
660
689
}
661
690
662
691
public String toString () {
663
692
return "EncryptionTests.Person(id=" + this .getId () + ", name=" + this .getName () + ", ssn=" + this .getSsn ()
664
693
+ ", wallet=" + this .getWallet () + ", address=" + this .getAddress () + ", encryptedZip="
665
694
+ this .getEncryptedZip () + ", listOfString=" + this .getListOfString () + ", listOfComplex="
666
695
+ this .getListOfComplex () + ", viaAltKeyNameField=" + this .getViaAltKeyNameField () + ", mapOfString="
667
- + this .getMapOfString () + ", mapOfComplex=" + this .getMapOfComplex () + ")" ;
696
+ + this .getMapOfString () + ", mapOfComplex=" + this .getMapOfComplex ()
697
+ + ", today=" + this .getToday () + ")" ;
668
698
}
669
699
}
670
700
0 commit comments