Skip to content

Commit

Permalink
Add support for supplying a version timestamp for the 'map-sid' funct…
Browse files Browse the repository at this point in the history
…ion (#20)

* Initial setup for version timestamp

* Removed SidMapperMock and replace by mockito mocks

* Release dapla-dlp-pseudo-func

---------

Co-authored-by: Michael Moen Allport <[email protected]>
  • Loading branch information
bjornandre and mallport authored Sep 4, 2023
1 parent f661c6c commit a2bc3f6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<!-- Dependency versions -->
<avro-buddy-core.version>1.1.0</avro-buddy-core.version>
<dapla-dlp-pseudo-func.version>1.2.3</dapla-dlp-pseudo-func.version>
<dapla-dlp-pseudo-func.version>1.2.4</dapla-dlp-pseudo-func.version>
<dapla-storage-client.version>5.1.2</dapla-storage-client.version>
<guava.version>31.1-jre</guava.version>
<jsonassert.version>1.5.1</jsonassert.version>
Expand Down Expand Up @@ -189,6 +189,12 @@
<version>${jsonassert.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
38 changes: 38 additions & 0 deletions src/test/java/no/ssb/dlp/pseudo/core/func/MapFuncTest.java
Original file line number Diff line number Diff line change
@@ -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<Map> 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"));
}
}

0 comments on commit a2bc3f6

Please sign in to comment.