Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -61,15 +60,6 @@ private void writeEnv(String content) {
} catch (IOException e) {
throw new RuntimeException(e);
}
// Print the contents of the .env file
try (Scanner scanner = new Scanner(envFile)) {
System.out.println("Current .env contents:");
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
} catch (IOException e) {
System.out.println("Could not read .env file: " + e.getMessage());
}
}

private VaultController createController() throws SkyflowException {
Expand Down Expand Up @@ -258,7 +248,7 @@ public void testBatchSizeExceedsMax() throws Exception {
// Ignore, Testing concurrency/batch config
}

assertEquals(1000, getPrivateInt(controller, "insertBatchSize"));
assertEquals(Constants.MAX_INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize"));
}

@Test
Expand All @@ -274,7 +264,7 @@ public void testConcurrencyExceedsMax() throws Exception {
// Ignore, Testing concurrency/batch config
}

assertEquals(1, getPrivateInt(controller, "insertConcurrencyLimit"));
assertEquals(Constants.INSERT_CONCURRENCY_LIMIT.intValue(), getPrivateInt(controller, "insertConcurrencyLimit"));
}

@Test
Expand All @@ -289,7 +279,7 @@ public void testBatchSizeZeroOrNegative() throws Exception {
// Ignore, Testing concurrency/batch config
}

assertEquals(50, getPrivateInt(controller, "insertBatchSize"));
assertEquals(Constants.INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize"));

writeEnv("INSERT_BATCH_SIZE=-5");

Expand All @@ -299,7 +289,7 @@ public void testBatchSizeZeroOrNegative() throws Exception {
// Ignore, Testing concurrency/batch config
}

assertEquals(50, getPrivateInt(controller, "insertBatchSize"));
assertEquals(Constants.INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize"));
}

@Test
Expand Down Expand Up @@ -378,7 +368,7 @@ public void testHighConcurrencyForLowRecords() throws Exception {

// Only 10 batches needed, so concurrency should be clamped to 10
assertEquals(1000, getPrivateInt(controller, "insertBatchSize"));
assertEquals(10, getPrivateInt(controller, "insertConcurrencyLimit"));
assertEquals(Constants.MAX_INSERT_CONCURRENCY_LIMIT.intValue(), getPrivateInt(controller, "insertConcurrencyLimit"));
}


Expand Down
179 changes: 179 additions & 0 deletions v3/src/test/java/com/skyflow/vault/data/DetokenizeRequestTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package com.skyflow.vault.data;

import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.SkyflowException;
import com.skyflow.utils.validations.Validations;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class DetokenizeRequestTests {
@Test
public void testDetokenizeRequestBuilderAndGetters() {
List<String> tokens = Arrays.asList("token1", "token2");
TokenGroupRedactions group = TokenGroupRedactions.builder()
.tokenGroupName("group1")
.redaction("PLAIN_TEXT")
.build();
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);

DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.tokenGroupRedactions(groupRedactions)
.build();

Assert.assertEquals(tokens, request.getTokens());
Assert.assertEquals(groupRedactions, request.getTokenGroupRedactions());
}

@Test
public void testTokenGroupRedactionsBuilderAndGetters() {
TokenGroupRedactions group = TokenGroupRedactions.builder()
.tokenGroupName("groupA")
.redaction("MASKED")
.build();
Assert.assertEquals("groupA", group.getTokenGroupName());
Assert.assertEquals("MASKED", group.getRedaction());
}

@Test
public void testValidateDetokenizeRequestValid() {
try {
List<String> tokens = Arrays.asList("token1", "token2");
TokenGroupRedactions group = TokenGroupRedactions.builder()
.tokenGroupName("group1")
.redaction("PLAIN_TEXT")
.build();
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.tokenGroupRedactions(groupRedactions)
.build();
Validations.validateDetokenizeRequest(request);
} catch (SkyflowException e) {
Assert.fail("Should not have thrown exception for valid request");
}
}

@Test
public void testValidateDetokenizeRequestNull() {
try {
Validations.validateDetokenizeRequest(null);
Assert.fail("Should have thrown exception for null request");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.DetokenizeRequestNull.getMessage(), e.getMessage());
}
}

@Test
public void testValidateDetokenizeRequestEmptyTokens() {
try {
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(new ArrayList<>())
.build();
Validations.validateDetokenizeRequest(request);
Assert.fail("Should have thrown exception for empty tokens");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.EmptyDetokenizeData.getMessage(), e.getMessage());
}
}

@Test
public void testValidateDetokenizeRequestNullOrEmptyToken() {
try {
List<String> tokens = Arrays.asList("token1", null, "");
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.build();
Validations.validateDetokenizeRequest(request);
Assert.fail("Should have thrown exception for null/empty token");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.EmptyTokenInDetokenizeData.getMessage(), e.getMessage());
}
}

@Test
public void testValidateDetokenizeRequestTokensSizeExceed() {
try {
List<String> tokens = new ArrayList<>();
for (int i = 0; i < 10001; i++) {
tokens.add("token" + i);
}
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.build();
Validations.validateDetokenizeRequest(request);
Assert.fail("Should have thrown exception for tokens size exceed");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.TokensSizeExceedError.getMessage(), e.getMessage());
}
}

@Test
public void testValidateDetokenizeRequestNullGroupRedaction() {
try {
List<String> tokens = Arrays.asList("token1");
List<TokenGroupRedactions> groupRedactions = Arrays.asList((TokenGroupRedactions) null);
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.tokenGroupRedactions(groupRedactions)
.build();
Validations.validateDetokenizeRequest(request);
Assert.fail("Should have thrown exception for null group redaction");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.NullTokenGroupRedactions.getMessage(), e.getMessage());
}
}

@Test
public void testValidateDetokenizeRequestEmptyGroupName() {
try {
List<String> tokens = Arrays.asList("token1");
TokenGroupRedactions group = TokenGroupRedactions.builder()
.tokenGroupName("")
.redaction("PLAIN_TEXT")
.build();
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.tokenGroupRedactions(groupRedactions)
.build();
Validations.validateDetokenizeRequest(request);
Assert.fail("Should have thrown exception for empty group name");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.NullTokenGroupNameInTokenGroup.getMessage(), e.getMessage());
}
}

@Test
public void testValidateDetokenizeRequestEmptyRedaction() {
try {
List<String> tokens = Arrays.asList("token1");
TokenGroupRedactions group = TokenGroupRedactions.builder()
.tokenGroupName("group1")
.redaction("")
.build();
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.tokenGroupRedactions(groupRedactions)
.build();
Validations.validateDetokenizeRequest(request);
Assert.fail("Should have thrown exception for empty redaction");
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.NullRedactionInTokenGroup.getMessage(), e.getMessage());
}
}
}
Loading