diff --git a/pom.xml b/pom.xml index 340ca67..36ff103 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.skyflow skyflow-java - 1.13.0 + 1.14.0 jar ${project.groupId}:${project.artifactId} diff --git a/src/main/java/com/skyflow/common/utils/Constants.java b/src/main/java/com/skyflow/common/utils/Constants.java index 05c89e3..bb9d7cc 100644 --- a/src/main/java/com/skyflow/common/utils/Constants.java +++ b/src/main/java/com/skyflow/common/utils/Constants.java @@ -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"; } diff --git a/src/main/java/com/skyflow/vault/Detokenize.java b/src/main/java/com/skyflow/vault/Detokenize.java index 2ebcbbb..da0baec 100644 --- a/src/main/java/com/skyflow/vault/Detokenize.java +++ b/src/main/java/com/skyflow/vault/Detokenize.java @@ -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); diff --git a/src/test/java/com/skyflow/common/utils/HelpersTest.java b/src/test/java/com/skyflow/common/utils/HelpersTest.java index 2849cc5..fea055d 100644 --- a/src/test/java/com/skyflow/common/utils/HelpersTest.java +++ b/src/test/java/com/skyflow/common/utils/HelpersTest.java @@ -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"; @@ -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"; @@ -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); } diff --git a/src/test/java/com/skyflow/vault/SkyflowTest.java b/src/test/java/com/skyflow/vault/SkyflowTest.java index b6204d7..810d42d 100644 --- a/src/test/java/com/skyflow/vault/SkyflowTest.java +++ b/src/test/java/com/skyflow/vault/SkyflowTest.java @@ -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.any(), ArgumentMatchers.any(), ArgumentMatchers.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() {