From 67aadc1d2fd5c66734dd10e0e58818daecadc7e1 Mon Sep 17 00:00:00 2001 From: Agoston Horvath Date: Mon, 7 Dec 2020 14:14:23 +0100 Subject: [PATCH] added test coverage for UUID --- .../com/bol/system/EncryptSystemTest.java | 5 +++++ .../com/bol/system/model/PrimitiveField.java | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/bol/system/EncryptSystemTest.java b/src/test/java/com/bol/system/EncryptSystemTest.java index 48f733a..863b9ee 100644 --- a/src/test/java/com/bol/system/EncryptSystemTest.java +++ b/src/test/java/com/bol/system/EncryptSystemTest.java @@ -37,6 +37,7 @@ public void cleanDb() { mongoTemplate.dropCollection(MyBean.class); mongoTemplate.dropCollection(Person.class); mongoTemplate.dropCollection(RenamedField.class); + mongoTemplate.dropCollection(PrimitiveField.class); } @Test @@ -71,14 +72,18 @@ public void simpleEncryption() { @Test public void checkEncryptPrimitives() { PrimitiveField bean = new PrimitiveField(); + bean.id = UUID.randomUUID(); bean.primitiveInt = 1; bean.encryptedPrimitiveInt = 2; + bean.data = new byte[]{1, 2, 3}; mongoTemplate.save(bean); PrimitiveField fromDb = mongoTemplate.findOne(new Query(), PrimitiveField.class); + assertThat(fromDb.id).isEqualTo(bean.id); assertThat(fromDb.primitiveInt).isEqualTo(bean.primitiveInt); assertThat(fromDb.encryptedPrimitiveInt).isEqualTo(bean.encryptedPrimitiveInt); + assertThat(fromDb.data).isEqualTo(bean.data); // FIXME: test for DB encoding of java primitives } diff --git a/src/test/java/com/bol/system/model/PrimitiveField.java b/src/test/java/com/bol/system/model/PrimitiveField.java index e4e1f6f..25f23d2 100644 --- a/src/test/java/com/bol/system/model/PrimitiveField.java +++ b/src/test/java/com/bol/system/model/PrimitiveField.java @@ -1,16 +1,36 @@ package com.bol.system.model; import com.bol.secure.Encrypted; +import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Field; +import java.util.UUID; + import static com.bol.system.model.PrimitiveField.MONGO_PRIMITIVEFIELD; -import static com.bol.system.model.RenamedField.MONGO_RENAMEDFIELD; +/* +> db.primitivefield.find().pretty(); +{ + "_id" : BinData(3,"m0jcj60kTHxdZZriPCPxuw=="), + "data" : BinData(0,"gIUv9oVQRNFDcialLXqdd/MiSrrkuSmOLmFr1M+x5hBk"), + "primitiveInt" : 1, + "encryptedPrimitiveInt" : BinData(0,"gCIePEAEVzZ8ymqz30WeSVCqkq3sLtk0Pc+6rjgMDaoO"), + "_class" : "com.bol.system.model.PrimitiveField" +} + */ @Document(collection = MONGO_PRIMITIVEFIELD) public class PrimitiveField { public static final String MONGO_PRIMITIVEFIELD = "primitivefield"; + // try using UUID as ID + @Id + public UUID id; + + @Field + @Encrypted + public byte[] data; + @Field public int primitiveInt;