@@ -964,6 +964,39 @@ public void testDetokenizeSuccess() {
964964 }
965965 }
966966
967+ @ Test
968+ @ PrepareForTest (fullyQualifiedNames = {"com.skyflow.common.utils.HttpUtility" , "com.skyflow.common.utils.TokenUtils" })
969+ public void testFormattedDetokenizeSuccess () {
970+ try {
971+ SkyflowConfiguration config = new SkyflowConfiguration (vaultID , vaultURL , new DemoTokenProvider ());
972+
973+ Skyflow skyflowClient = Skyflow .init (config );
974+ JSONObject records = new JSONObject ();
975+ JSONArray recordsArray = new JSONArray ();
976+ JSONObject record = new JSONObject ();
977+ record .put ("token" , token );
978+ recordsArray .add (record );
979+ records .put ("records" , recordsArray );
980+
981+ PowerMockito .mockStatic (HttpUtility .class );
982+ String mockResponse = "{\" records\" :[{\" token\" :\" token123\" ,\" valueType\" :\" INTEGER\" ,\" value\" :\" 10\" ,\" test\" :\" test123\" }]}" ;
983+ PowerMockito .when (HttpUtility .sendRequest (anyString (), ArgumentMatchers .<URL >any (), ArgumentMatchers .<JSONObject >any (), ArgumentMatchers .<String , String >anyMap ())).thenReturn (mockResponse );
984+
985+ JSONObject res = skyflowClient .detokenize (records );
986+ JSONArray responseRecords = (JSONArray ) res .get ("records" );
987+ assertEquals (1 , responseRecords .size ());
988+ assertEquals (token , ((JSONObject ) responseRecords .get (0 )).get ("token" ));
989+ assertEquals (null , ((JSONObject ) responseRecords .get (0 )).get ("test" ));
990+ assertTrue (((JSONObject ) responseRecords .get (0 )).containsKey ("value" ));
991+ } catch (SkyflowException skyflowException ) {
992+ skyflowException .printStackTrace ();
993+ fail (INVALID_EXCEPTION_THROWN );
994+ } catch (IOException e ) {
995+ e .printStackTrace ();
996+ fail (INVALID_EXCEPTION_THROWN );
997+ }
998+ }
999+
9671000 @ Test
9681001 @ PrepareForTest (fullyQualifiedNames = {"com.skyflow.common.utils.HttpUtility" , "com.skyflow.common.utils.TokenUtils" })
9691002 public void testDetokenizeError () {
0 commit comments