diff --git a/mock-ida-dataprovider-plugin/src/main/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPlugin.java b/mock-ida-dataprovider-plugin/src/main/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPlugin.java index 3ae8675..c76eb61 100644 --- a/mock-ida-dataprovider-plugin/src/main/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPlugin.java +++ b/mock-ida-dataprovider-plugin/src/main/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPlugin.java @@ -10,6 +10,7 @@ import io.mosip.kernel.keymanagerservice.entity.KeyAlias; import io.mosip.kernel.keymanagerservice.helper.KeymanagerDBHelper; import lombok.extern.slf4j.Slf4j; +import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -65,7 +66,7 @@ public class MockIdaDataProviderPlugin implements DataProviderPlugin { private boolean storeIndividualId; @Override - public Map fetchData(Map identityDetails) throws DataProviderExchangeException { + public JSONObject fetchData(Map identityDetails) throws DataProviderExchangeException { try { OIDCTransaction transaction = mockTransactionHelper.getUserInfoTransaction(identityDetails.get(ACCESS_TOKEN_HASH).toString()); String individualId = getIndividualId(transaction); @@ -74,21 +75,21 @@ public Map fetchData(Map identityDetails) throws getIdentityUrl + "/" + individualId, HashMap.class); res = (Map) res.get("response"); - Map ret = new HashMap<>(); - ret.put("vcVer", "VC-V1"); - ret.put("id", getIdentityUrl + "/" + individualId); - ret.put("UIN", individualId); - ret.put("fullName", res.get("fullName")); - ret.put("gender", res.get("gender")); - ret.put("dateOfBirth", res.get("dateOfBirth")); - ret.put("email", res.get("email")); - ret.put("phone", res.get("phone")); - ret.put("addressLine1", res.get("streetAddress")); - ret.put("province", res.get("locality")); - ret.put("region", res.get("region")); - ret.put("postalCode", res.get("postalCode")); - ret.put("face", res.get("encodedPhoto")); - return ret; + JSONObject jsonRes = new JSONObject(); + jsonRes.put("vcVer", "VC-V1"); + jsonRes.put("id", getIdentityUrl + "/" + individualId); + jsonRes.put("UIN", individualId); + jsonRes.put("fullName", res.get("fullName")); + jsonRes.put("gender", res.get("gender")); + jsonRes.put("dateOfBirth", res.get("dateOfBirth")); + jsonRes.put("email", res.get("email")); + jsonRes.put("phone", res.get("phone")); + jsonRes.put("addressLine1", res.get("streetAddress")); + jsonRes.put("province", res.get("locality")); + jsonRes.put("region", res.get("region")); + jsonRes.put("postalCode", res.get("postalCode")); + jsonRes.put("face", res.get("encodedPhoto")); + return jsonRes; } } catch (Exception e) { log.error("Failed to fetch json data for from data provider plugin", e); diff --git a/mock-ida-dataprovider-plugin/src/test/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPluginTest.java b/mock-ida-dataprovider-plugin/src/test/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPluginTest.java index 4b7f199..9b7631a 100644 --- a/mock-ida-dataprovider-plugin/src/test/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPluginTest.java +++ b/mock-ida-dataprovider-plugin/src/test/java/io/mosip/certify/mockidadataprovider/integration/service/MockIdaDataProviderPluginTest.java @@ -2,6 +2,8 @@ import io.mosip.certify.api.exception.DataProviderExchangeException; import io.mosip.esignet.core.dto.OIDCTransaction; +import org.json.JSONException; +import org.json.JSONObject; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -70,8 +72,8 @@ public void setup() throws DataProviderExchangeException { } @Test - public void getJSONDataWithValidDetails_thenPass() throws DataProviderExchangeException { - Map jsonData = mockDataProviderPlugin.fetchData(Map.of("accessTokenHash","ACCESS_TOKEN_HASH","client_id","CLIENT_ID")); + public void getJSONDataWithValidDetails_thenPass() throws DataProviderExchangeException, JSONException { + JSONObject jsonData = mockDataProviderPlugin.fetchData(Map.of("accessTokenHash","ACCESS_TOKEN_HASH","client_id","CLIENT_ID")); Assert.assertNotNull(jsonData); Assert.assertNotNull(jsonData.get("fullName")); Assert.assertEquals("fullName" ,jsonData.get("fullName"));