From 100bf2d994d4df746b4b6ba94b0d62aac81e6e4f Mon Sep 17 00:00:00 2001 From: Michael Moen Allport Date: Thu, 31 Aug 2023 15:37:21 +0200 Subject: [PATCH 1/3] Initial setup for version timestamp --- .../ssb/dlp/pseudo/core/func/MapFuncTest.java | 30 +++++++++++++++++++ .../dlp/pseudo/core/func/SidMapperMock.java | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java create mode 100644 src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java diff --git a/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java b/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java new file mode 100644 index 0000000..2f1e311 --- /dev/null +++ b/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java @@ -0,0 +1,30 @@ +package no.ssb.dlp.pseudo.core.func; + +import no.ssb.dapla.dlp.pseudo.func.PseudoFunc; +import no.ssb.dapla.dlp.pseudo.func.PseudoFuncConfig; +import no.ssb.dapla.dlp.pseudo.func.PseudoFuncFactory; +import no.ssb.dapla.dlp.pseudo.func.PseudoFuncInput; +import no.ssb.dapla.dlp.pseudo.func.map.Mapper; +import no.ssb.dapla.dlp.pseudo.func.tink.daead.TinkDaeadFuncConfig; +import no.ssb.dapla.dlp.pseudo.func.tink.fpe.TinkFpeFuncConfig; +import org.junit.jupiter.api.Test; +import org.mockito.internal.matchers.Any; + +import java.util.Collections; +import java.util.ServiceLoader; + +import static org.mockito.Mockito.*; + +public class MapFuncTest { + private PseudoFunc f(String funcDecl) throws Exception { + PseudoFuncConfig config = PseudoFuncConfigFactory.get(funcDecl); + return PseudoFuncFactory.create(config); + } + + @Test + void mapFuncWithTimestamp() throws Exception { + String funcDeclStr = "map-sid(keyId=1284924461, versionTimestamp=test)"; + PseudoFunc func = f(funcDeclStr); + func.init(PseudoFuncInput.of("50607080901")); + } +} diff --git a/src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java b/src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java new file mode 100644 index 0000000..5a201c9 --- /dev/null +++ b/src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java @@ -0,0 +1,30 @@ +package no.ssb.dlp.pseudo.core.func; + +import com.google.auto.service.AutoService; +import no.ssb.dapla.dlp.pseudo.func.map.Mapper; + +import java.util.Map; + +@AutoService(Mapper.class) +public class SidMapperMock implements Mapper { + + @Override + public void init(Object data) { + + } + + @Override + public void setConfig(Map config) { + + } + + @Override + public Object map(Object data) { + return null; + } + + @Override + public Object restore(Object mapped) { + return null; + } +} From b331cd46b66f992889ac256ba33c4c80f1cf5073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Skaar=2C=20Bj=C3=B8rn-Andre?= Date: Thu, 31 Aug 2023 20:22:46 +0200 Subject: [PATCH 2/3] Removed SidMapperMock and replace by mockito mocks --- pom.xml | 8 ++++- .../core/func/PseudoFuncConfigFactory.java | 1 + .../ssb/dlp/pseudo/core/func/MapFuncTest.java | 28 ++++++++++------- .../dlp/pseudo/core/func/SidMapperMock.java | 30 ------------------- 4 files changed, 26 insertions(+), 41 deletions(-) delete mode 100644 src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java diff --git a/pom.xml b/pom.xml index 18ee9b9..e1a7947 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 1.1.0 - 1.2.3 + 1.2.4-SNAPSHOT 5.1.2 31.1-jre 1.5.1 @@ -189,6 +189,12 @@ ${jsonassert.version} test + + org.mockito + mockito-core + 5.3.1 + test + diff --git a/src/main/java/no/ssb/dlp/pseudo/core/func/PseudoFuncConfigFactory.java b/src/main/java/no/ssb/dlp/pseudo/core/func/PseudoFuncConfigFactory.java index 7d3447a..d5f76fa 100644 --- a/src/main/java/no/ssb/dlp/pseudo/core/func/PseudoFuncConfigFactory.java +++ b/src/main/java/no/ssb/dlp/pseudo/core/func/PseudoFuncConfigFactory.java @@ -49,6 +49,7 @@ private static PseudoFuncConfigPreset sidMappingPseudoFuncConfigPreset(String fu return PseudoFuncConfigPreset.builder(funcName, MapFunc.class) .staticParam(MapFuncConfig.Param.CONTEXT, "sid") .requiredParam(String.class, TinkFpeFuncConfig.Param.KEY_ID) + .optionalParam(String.class, MapFuncConfig.Param.VERSION_TIMESTAMP) .build(); } diff --git a/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java b/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java index 2f1e311..795203c 100644 --- a/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java +++ b/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java @@ -4,27 +4,35 @@ import no.ssb.dapla.dlp.pseudo.func.PseudoFuncConfig; import no.ssb.dapla.dlp.pseudo.func.PseudoFuncFactory; import no.ssb.dapla.dlp.pseudo.func.PseudoFuncInput; +import no.ssb.dapla.dlp.pseudo.func.map.MapFunc; import no.ssb.dapla.dlp.pseudo.func.map.Mapper; -import no.ssb.dapla.dlp.pseudo.func.tink.daead.TinkDaeadFuncConfig; -import no.ssb.dapla.dlp.pseudo.func.tink.fpe.TinkFpeFuncConfig; import org.junit.jupiter.api.Test; -import org.mockito.internal.matchers.Any; +import org.mockito.ArgumentCaptor; -import java.util.Collections; -import java.util.ServiceLoader; +import java.util.Map; import static org.mockito.Mockito.*; public class MapFuncTest { - private PseudoFunc f(String funcDecl) throws Exception { + private PseudoFunc f(String funcDecl) { PseudoFuncConfig config = PseudoFuncConfigFactory.get(funcDecl); return PseudoFuncFactory.create(config); } @Test - void mapFuncWithTimestamp() throws Exception { - String funcDeclStr = "map-sid(keyId=1284924461, versionTimestamp=test)"; - PseudoFunc func = f(funcDeclStr); - func.init(PseudoFuncInput.of("50607080901")); + void mapFuncWithTimestamp() { + final Mapper mockMapper = mock(Mapper.class); + try (var mapFunc = mockStatic(MapFunc.class)) { + mapFunc.when(() -> MapFunc.loadMapper()).thenReturn(mockMapper); + String funcDeclStr = "map-sid(keyId=1284924461, versionTimestamp=test)"; + PseudoFunc func = f(funcDeclStr); + func.init(PseudoFuncInput.of("50607080901")); + } + // Check that the mockMapper has received the versionTimestamp + ArgumentCaptor argumentsCaptured = ArgumentCaptor.forClass(Map.class); + verify(mockMapper).setConfig(argumentsCaptured.capture()); + assert argumentsCaptured.getValue().containsKey("versionTimestamp"); + // Check that the init method was called + verify(mockMapper).init(eq("50607080901")); } } diff --git a/src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java b/src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java deleted file mode 100644 index 5a201c9..0000000 --- a/src/test/java/no/ssb/dlp/pseudo/core/func/SidMapperMock.java +++ /dev/null @@ -1,30 +0,0 @@ -package no.ssb.dlp.pseudo.core.func; - -import com.google.auto.service.AutoService; -import no.ssb.dapla.dlp.pseudo.func.map.Mapper; - -import java.util.Map; - -@AutoService(Mapper.class) -public class SidMapperMock implements Mapper { - - @Override - public void init(Object data) { - - } - - @Override - public void setConfig(Map config) { - - } - - @Override - public Object map(Object data) { - return null; - } - - @Override - public Object restore(Object mapped) { - return null; - } -} From 075506c74574e75d480d737f148414ff81beffcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Skaar=2C=20Bj=C3=B8rn-Andre?= Date: Mon, 4 Sep 2023 14:42:06 +0200 Subject: [PATCH 3/3] Release dapla-dlp-pseudo-func --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e1a7947..73073bc 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 1.1.0 - 1.2.4-SNAPSHOT + 1.2.4 5.1.2 31.1-jre 1.5.1