diff --git a/pom.xml b/pom.xml index 18ee9b9..73073bc 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 1.1.0 - 1.2.3 + 1.2.4 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 new file mode 100644 index 0000000..795203c --- /dev/null +++ b/src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java @@ -0,0 +1,38 @@ +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.MapFunc; +import no.ssb.dapla.dlp.pseudo.func.map.Mapper; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.Map; + +import static org.mockito.Mockito.*; + +public class MapFuncTest { + private PseudoFunc f(String funcDecl) { + PseudoFuncConfig config = PseudoFuncConfigFactory.get(funcDecl); + return PseudoFuncFactory.create(config); + } + + @Test + 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")); + } +}