-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EncryptedInsideAnnotationOnMapTest
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/test/java/io/github/tap30/hiss/EncryptedInsideAnnotationOnMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package io.github.tap30.hiss; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
public class EncryptedInsideAnnotationOnMapTest extends BaseHissTest { | ||
|
||
@Test | ||
void testEncryptAndDecryptDomainObject() { | ||
// Given | ||
|
||
var user = User.builder() | ||
.id("5") | ||
.phoneNumber("123456789") | ||
.addressMap(Map.of( | ||
"address1", | ||
Address.builder() | ||
.city("list city 1") | ||
.postalCode("LC1") | ||
.build(), | ||
"address2", | ||
Address.builder() | ||
.city("list city 2") | ||
.postalCode("LC2") | ||
.build() | ||
)) | ||
.build(); | ||
|
||
// When | ||
this.hiss.encryptObject(user); | ||
|
||
// Then | ||
{ | ||
assertEquals("5", user.getId()); | ||
assertNotEquals("123456789", user.getPhoneNumber()); | ||
|
||
assertEquals(2, user.getAddressMap().size()); | ||
var listAddress1 = user.getAddressMap().get("address1"); | ||
assertEquals("list city 1", listAddress1.getCity()); | ||
assertNotEquals("LC1", listAddress1.getPostalCode()); | ||
var listAddress2 = user.getAddressMap().get("address2"); | ||
assertEquals("list city 2", listAddress2.getCity()); | ||
assertNotEquals("LC2", listAddress2.getPostalCode()); | ||
} | ||
|
||
|
||
// When | ||
this.hiss.decryptObject(user); | ||
|
||
// Then | ||
{ | ||
assertEquals("5", user.getId()); | ||
assertEquals("123456789", user.getPhoneNumber()); | ||
|
||
assertEquals(2, user.getAddressMap().size()); | ||
var listAddress1 = user.getAddressMap().get("address1"); | ||
assertEquals("list city 1", listAddress1.getCity()); | ||
assertEquals("LC1", listAddress1.getPostalCode()); | ||
var listAddress2 = user.getAddressMap().get("address2"); | ||
assertEquals("list city 2", listAddress2.getCity()); | ||
assertEquals("LC2", listAddress2.getPostalCode()); | ||
} | ||
} | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public static class User { | ||
private String id; | ||
@Encrypted(hashingEnabled = false) | ||
private String phoneNumber; | ||
@EncryptedInside | ||
private Map<String, Address> addressMap; | ||
} | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public static class Address { | ||
private String city; | ||
@Encrypted(hashingEnabled = false) | ||
private String postalCode; | ||
} | ||
|
||
} |