Skip to content

Commit 3fa14f8

Browse files
SK-2291: Add unit test cases for V3 SDK. (#234)
* SK-2291: add unit test cases
1 parent 7b1b3bc commit 3fa14f8

File tree

6 files changed

+184
-15
lines changed

6 files changed

+184
-15
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

v3/test/java/com/skyflow/vault/controller/VaultControllerTests.java renamed to v3/src/test/java/com/skyflow/vault/controller/VaultControllerTests.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.lang.reflect.Method;
2020
import java.util.ArrayList;
2121
import java.util.HashMap;
22-
import java.util.Scanner;
2322

2423
import static org.junit.Assert.*;
2524

@@ -61,15 +60,6 @@ private void writeEnv(String content) {
6160
} catch (IOException e) {
6261
throw new RuntimeException(e);
6362
}
64-
// Print the contents of the .env file
65-
try (Scanner scanner = new Scanner(envFile)) {
66-
System.out.println("Current .env contents:");
67-
while (scanner.hasNextLine()) {
68-
System.out.println(scanner.nextLine());
69-
}
70-
} catch (IOException e) {
71-
System.out.println("Could not read .env file: " + e.getMessage());
72-
}
7363
}
7464

7565
private VaultController createController() throws SkyflowException {
@@ -258,7 +248,7 @@ public void testBatchSizeExceedsMax() throws Exception {
258248
// Ignore, Testing concurrency/batch config
259249
}
260250

261-
assertEquals(1000, getPrivateInt(controller, "insertBatchSize"));
251+
assertEquals(Constants.MAX_INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize"));
262252
}
263253

264254
@Test
@@ -274,7 +264,7 @@ public void testConcurrencyExceedsMax() throws Exception {
274264
// Ignore, Testing concurrency/batch config
275265
}
276266

277-
assertEquals(1, getPrivateInt(controller, "insertConcurrencyLimit"));
267+
assertEquals(Constants.INSERT_CONCURRENCY_LIMIT.intValue(), getPrivateInt(controller, "insertConcurrencyLimit"));
278268
}
279269

280270
@Test
@@ -289,7 +279,7 @@ public void testBatchSizeZeroOrNegative() throws Exception {
289279
// Ignore, Testing concurrency/batch config
290280
}
291281

292-
assertEquals(50, getPrivateInt(controller, "insertBatchSize"));
282+
assertEquals(Constants.INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize"));
293283

294284
writeEnv("INSERT_BATCH_SIZE=-5");
295285

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

302-
assertEquals(50, getPrivateInt(controller, "insertBatchSize"));
292+
assertEquals(Constants.INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize"));
303293
}
304294

305295
@Test
@@ -378,7 +368,7 @@ public void testHighConcurrencyForLowRecords() throws Exception {
378368

379369
// Only 10 batches needed, so concurrency should be clamped to 10
380370
assertEquals(1000, getPrivateInt(controller, "insertBatchSize"));
381-
assertEquals(10, getPrivateInt(controller, "insertConcurrencyLimit"));
371+
assertEquals(Constants.MAX_INSERT_CONCURRENCY_LIMIT.intValue(), getPrivateInt(controller, "insertConcurrencyLimit"));
382372
}
383373

384374

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
package com.skyflow.vault.data;
2+
3+
import com.skyflow.errors.ErrorCode;
4+
import com.skyflow.errors.ErrorMessage;
5+
import com.skyflow.errors.SkyflowException;
6+
import com.skyflow.utils.validations.Validations;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.Collections;
13+
import java.util.List;
14+
15+
public class DetokenizeRequestTests {
16+
@Test
17+
public void testDetokenizeRequestBuilderAndGetters() {
18+
List<String> tokens = Arrays.asList("token1", "token2");
19+
TokenGroupRedactions group = TokenGroupRedactions.builder()
20+
.tokenGroupName("group1")
21+
.redaction("PLAIN_TEXT")
22+
.build();
23+
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
24+
25+
DetokenizeRequest request = DetokenizeRequest.builder()
26+
.tokens(tokens)
27+
.tokenGroupRedactions(groupRedactions)
28+
.build();
29+
30+
Assert.assertEquals(tokens, request.getTokens());
31+
Assert.assertEquals(groupRedactions, request.getTokenGroupRedactions());
32+
}
33+
34+
@Test
35+
public void testTokenGroupRedactionsBuilderAndGetters() {
36+
TokenGroupRedactions group = TokenGroupRedactions.builder()
37+
.tokenGroupName("groupA")
38+
.redaction("MASKED")
39+
.build();
40+
Assert.assertEquals("groupA", group.getTokenGroupName());
41+
Assert.assertEquals("MASKED", group.getRedaction());
42+
}
43+
44+
@Test
45+
public void testValidateDetokenizeRequestValid() {
46+
try {
47+
List<String> tokens = Arrays.asList("token1", "token2");
48+
TokenGroupRedactions group = TokenGroupRedactions.builder()
49+
.tokenGroupName("group1")
50+
.redaction("PLAIN_TEXT")
51+
.build();
52+
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
53+
DetokenizeRequest request = DetokenizeRequest.builder()
54+
.tokens(tokens)
55+
.tokenGroupRedactions(groupRedactions)
56+
.build();
57+
Validations.validateDetokenizeRequest(request);
58+
} catch (SkyflowException e) {
59+
Assert.fail("Should not have thrown exception for valid request");
60+
}
61+
}
62+
63+
@Test
64+
public void testValidateDetokenizeRequestNull() {
65+
try {
66+
Validations.validateDetokenizeRequest(null);
67+
Assert.fail("Should have thrown exception for null request");
68+
} catch (SkyflowException e) {
69+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
70+
Assert.assertEquals(ErrorMessage.DetokenizeRequestNull.getMessage(), e.getMessage());
71+
}
72+
}
73+
74+
@Test
75+
public void testValidateDetokenizeRequestEmptyTokens() {
76+
try {
77+
DetokenizeRequest request = DetokenizeRequest.builder()
78+
.tokens(new ArrayList<>())
79+
.build();
80+
Validations.validateDetokenizeRequest(request);
81+
Assert.fail("Should have thrown exception for empty tokens");
82+
} catch (SkyflowException e) {
83+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
84+
Assert.assertEquals(ErrorMessage.EmptyDetokenizeData.getMessage(), e.getMessage());
85+
}
86+
}
87+
88+
@Test
89+
public void testValidateDetokenizeRequestNullOrEmptyToken() {
90+
try {
91+
List<String> tokens = Arrays.asList("token1", null, "");
92+
DetokenizeRequest request = DetokenizeRequest.builder()
93+
.tokens(tokens)
94+
.build();
95+
Validations.validateDetokenizeRequest(request);
96+
Assert.fail("Should have thrown exception for null/empty token");
97+
} catch (SkyflowException e) {
98+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
99+
Assert.assertEquals(ErrorMessage.EmptyTokenInDetokenizeData.getMessage(), e.getMessage());
100+
}
101+
}
102+
103+
@Test
104+
public void testValidateDetokenizeRequestTokensSizeExceed() {
105+
try {
106+
List<String> tokens = new ArrayList<>();
107+
for (int i = 0; i < 10001; i++) {
108+
tokens.add("token" + i);
109+
}
110+
DetokenizeRequest request = DetokenizeRequest.builder()
111+
.tokens(tokens)
112+
.build();
113+
Validations.validateDetokenizeRequest(request);
114+
Assert.fail("Should have thrown exception for tokens size exceed");
115+
} catch (SkyflowException e) {
116+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
117+
Assert.assertEquals(ErrorMessage.TokensSizeExceedError.getMessage(), e.getMessage());
118+
}
119+
}
120+
121+
@Test
122+
public void testValidateDetokenizeRequestNullGroupRedaction() {
123+
try {
124+
List<String> tokens = Arrays.asList("token1");
125+
List<TokenGroupRedactions> groupRedactions = Arrays.asList((TokenGroupRedactions) null);
126+
DetokenizeRequest request = DetokenizeRequest.builder()
127+
.tokens(tokens)
128+
.tokenGroupRedactions(groupRedactions)
129+
.build();
130+
Validations.validateDetokenizeRequest(request);
131+
Assert.fail("Should have thrown exception for null group redaction");
132+
} catch (SkyflowException e) {
133+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
134+
Assert.assertEquals(ErrorMessage.NullTokenGroupRedactions.getMessage(), e.getMessage());
135+
}
136+
}
137+
138+
@Test
139+
public void testValidateDetokenizeRequestEmptyGroupName() {
140+
try {
141+
List<String> tokens = Arrays.asList("token1");
142+
TokenGroupRedactions group = TokenGroupRedactions.builder()
143+
.tokenGroupName("")
144+
.redaction("PLAIN_TEXT")
145+
.build();
146+
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
147+
DetokenizeRequest request = DetokenizeRequest.builder()
148+
.tokens(tokens)
149+
.tokenGroupRedactions(groupRedactions)
150+
.build();
151+
Validations.validateDetokenizeRequest(request);
152+
Assert.fail("Should have thrown exception for empty group name");
153+
} catch (SkyflowException e) {
154+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
155+
Assert.assertEquals(ErrorMessage.NullTokenGroupNameInTokenGroup.getMessage(), e.getMessage());
156+
}
157+
}
158+
159+
@Test
160+
public void testValidateDetokenizeRequestEmptyRedaction() {
161+
try {
162+
List<String> tokens = Arrays.asList("token1");
163+
TokenGroupRedactions group = TokenGroupRedactions.builder()
164+
.tokenGroupName("group1")
165+
.redaction("")
166+
.build();
167+
List<TokenGroupRedactions> groupRedactions = Collections.singletonList(group);
168+
DetokenizeRequest request = DetokenizeRequest.builder()
169+
.tokens(tokens)
170+
.tokenGroupRedactions(groupRedactions)
171+
.build();
172+
Validations.validateDetokenizeRequest(request);
173+
Assert.fail("Should have thrown exception for empty redaction");
174+
} catch (SkyflowException e) {
175+
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
176+
Assert.assertEquals(ErrorMessage.NullRedactionInTokenGroup.getMessage(), e.getMessage());
177+
}
178+
}
179+
}

v3/test/java/com/skyflow/vault/data/InsertTests.java renamed to v3/src/test/java/com/skyflow/vault/data/InsertTests.java

File renamed without changes.

0 commit comments

Comments
 (0)