2121import static org .springframework .data .mongodb .core .query .Criteria .*;
2222
2323import java .security .SecureRandom ;
24+ import java .time .LocalDate ;
25+ import java .time .Month ;
2426import java .util .Arrays ;
2527import java .util .Collections ;
2628import java .util .HashMap ;
@@ -89,6 +91,21 @@ void encryptAndDecryptSimpleValue() {
8991 .loadedIsEqualToSource ();
9092 }
9193
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+
92109 @ Test // GH-4284
93110 void encryptAndDecryptComplexValue () {
94111
@@ -548,6 +565,9 @@ static class Person {
548565 @ ExplicitEncrypted (algorithm = AEAD_AES_256_CBC_HMAC_SHA_512_Random ) //
549566 Map <String , Address > mapOfComplex ;
550567
568+ @ ExplicitEncrypted (algorithm = AEAD_AES_256_CBC_HMAC_SHA_512_Random ) //
569+ LocalDate today ;
570+
551571 public String getId () {
552572 return this .id ;
553573 }
@@ -592,6 +612,10 @@ public Map<String, Address> getMapOfComplex() {
592612 return this .mapOfComplex ;
593613 }
594614
615+ public LocalDate getToday () {
616+ return today ;
617+ }
618+
595619 public void setId (String id ) {
596620 this .id = id ;
597621 }
@@ -636,6 +660,10 @@ public void setMapOfComplex(Map<String, Address> mapOfComplex) {
636660 this .mapOfComplex = mapOfComplex ;
637661 }
638662
663+ public void setToday (LocalDate today ) {
664+ this .today = today ;
665+ }
666+
639667 @ Override
640668 public boolean equals (Object o ) {
641669 if (o == this ) {
@@ -650,21 +678,23 @@ public boolean equals(Object o) {
650678 && Objects .equals (encryptedZip , person .encryptedZip ) && Objects .equals (listOfString , person .listOfString )
651679 && Objects .equals (listOfComplex , person .listOfComplex )
652680 && 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 );
654683 }
655684
656685 @ Override
657686 public int hashCode () {
658687 return Objects .hash (id , name , ssn , wallet , address , encryptedZip , listOfString , listOfComplex , viaAltKeyNameField ,
659- mapOfString , mapOfComplex );
688+ mapOfString , mapOfComplex , today );
660689 }
661690
662691 public String toString () {
663692 return "EncryptionTests.Person(id=" + this .getId () + ", name=" + this .getName () + ", ssn=" + this .getSsn ()
664693 + ", wallet=" + this .getWallet () + ", address=" + this .getAddress () + ", encryptedZip="
665694 + this .getEncryptedZip () + ", listOfString=" + this .getListOfString () + ", listOfComplex="
666695 + this .getListOfComplex () + ", viaAltKeyNameField=" + this .getViaAltKeyNameField () + ", mapOfString="
667- + this .getMapOfString () + ", mapOfComplex=" + this .getMapOfComplex () + ")" ;
696+ + this .getMapOfString () + ", mapOfComplex=" + this .getMapOfComplex ()
697+ + ", today=" + this .getToday () + ")" ;
668698 }
669699 }
670700
0 commit comments