Skip to content

Commit

Permalink
[INJICERT-499] Added JsonObject in place of HashMap for identity data
Browse files Browse the repository at this point in the history
Signed-off-by: Piyush7034 <[email protected]>
  • Loading branch information
Piyush7034 committed Nov 4, 2024
1 parent 2e0f31c commit d32ff62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class MockIdaDataProviderPlugin implements DataProviderPlugin {
private boolean storeIndividualId;

@Override
public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws DataProviderExchangeException {
public JSONObject fetchData(Map<String, Object> identityDetails) throws DataProviderExchangeException {
try {
OIDCTransaction transaction = mockTransactionHelper.getUserInfoTransaction(identityDetails.get(ACCESS_TOKEN_HASH).toString());
String individualId = getIndividualId(transaction);
Expand All @@ -74,21 +75,21 @@ public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws
getIdentityUrl + "/" + individualId,
HashMap.class);
res = (Map<String, Object>) res.get("response");
Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,8 +72,8 @@ public void setup() throws DataProviderExchangeException {
}

@Test
public void getJSONDataWithValidDetails_thenPass() throws DataProviderExchangeException {
Map<String, Object> 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"));
Expand Down

0 comments on commit d32ff62

Please sign in to comment.