Skip to content

Commit

Permalink
Merge pull request #108 from skyflowapi/release/24.2.1
Browse files Browse the repository at this point in the history
SK-1436: address java sdk breaking change for continue on error support in detokenize
  • Loading branch information
yaswanth-pula-skyflow authored Feb 1, 2024
2 parents 72805b1 + 5e5ffec commit c799f7b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.skyflow</groupId>
<artifactId>skyflow-java</artifactId>
<version>1.13.0</version>
<version>1.14.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/skyflow/common/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class Constants {

public static final String SDK_METRICS_HEADER_KEY = "sky-metadata";
public static final String SDK_VERSION = "1.13.0";
public static final String SDK_VERSION = "1.14.0";

}
6 changes: 4 additions & 2 deletions src/main/java/com/skyflow/vault/Detokenize.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public String call() throws SkyflowException {
JSONObject responseJson = (JSONObject) parser.parse(apiResponse);
JSONArray responseRecords = (JSONArray) responseJson.get("records");
JSONObject responseObject = (JSONObject) responseRecords.get(0);
responseObject.remove("valueType");
response = responseObject.toJSONString();
JSONObject formattedResponseJson = new JSONObject();
formattedResponseJson.put("value", responseObject.get("value"));
formattedResponseJson.put("token", responseObject.get("token"));
response = formattedResponseJson.toJSONString();
} catch (IOException e) {
LogUtil.printErrorLog(ErrorLogs.Server.getLog());
throw new SkyflowException(ErrorCode.Server, e);
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/skyflow/common/utils/HelpersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class HelpersTest {

private static String tableName = null;
private static String columnName = null;
private static String reqId = null;
private static String[] columnValue = new String[1];
private static String[] ids = new String[1];
private static String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception";
Expand All @@ -47,7 +48,7 @@ public static void setup() throws SkyflowException {

PowerMockito.mockStatic(HttpUtility.class);
PowerMockito.when(HttpUtility.getRequestID()).thenReturn("abc");

reqId = HttpUtility.getRequestID();
tableName = "account_details";
columnName = "card_number";
columnValue[0] = "123451234554321";
Expand All @@ -56,7 +57,7 @@ public static void setup() throws SkyflowException {

@Test
public void testMessageWithRequestID(){
String message = Helpers.appendRequestId("message", HttpUtility.getRequestID());
String message = Helpers.appendRequestId("message", reqId);
String expectedMessage = "message" + " - requestId: " + "abc";
assertEquals(expectedMessage, message);
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/com/skyflow/vault/SkyflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,39 @@ public void testDetokenizeSuccess() {
}
}

@Test
@PrepareForTest(fullyQualifiedNames = {"com.skyflow.common.utils.HttpUtility", "com.skyflow.common.utils.TokenUtils"})
public void testFormattedDetokenizeSuccess() {
try {
SkyflowConfiguration config = new SkyflowConfiguration(vaultID, vaultURL, new DemoTokenProvider());

Skyflow skyflowClient = Skyflow.init(config);
JSONObject records = new JSONObject();
JSONArray recordsArray = new JSONArray();
JSONObject record = new JSONObject();
record.put("token", token);
recordsArray.add(record);
records.put("records", recordsArray);

PowerMockito.mockStatic(HttpUtility.class);
String mockResponse = "{\"records\":[{\"token\":\"token123\",\"valueType\":\"INTEGER\",\"value\":\"10\",\"test\":\"test123\"}]}";
PowerMockito.when(HttpUtility.sendRequest(anyString(), ArgumentMatchers.<URL>any(), ArgumentMatchers.<JSONObject>any(), ArgumentMatchers.<String, String>anyMap())).thenReturn(mockResponse);

JSONObject res = skyflowClient.detokenize(records);
JSONArray responseRecords = (JSONArray) res.get("records");
assertEquals(1, responseRecords.size());
assertEquals(token, ((JSONObject) responseRecords.get(0)).get("token"));
assertEquals(null, ((JSONObject) responseRecords.get(0)).get("test"));
assertTrue(((JSONObject) responseRecords.get(0)).containsKey("value"));
} catch (SkyflowException skyflowException) {
skyflowException.printStackTrace();
fail(INVALID_EXCEPTION_THROWN);
} catch (IOException e) {
e.printStackTrace();
fail(INVALID_EXCEPTION_THROWN);
}
}

@Test
@PrepareForTest(fullyQualifiedNames = {"com.skyflow.common.utils.HttpUtility", "com.skyflow.common.utils.TokenUtils"})
public void testDetokenizeError() {
Expand Down

0 comments on commit c799f7b

Please sign in to comment.