Skip to content

Commit

Permalink
Merge pull request #1377 from kameshsr/MOSIP-35611-2
Browse files Browse the repository at this point in the history
Mosip-38491 Fixed api test rig failure
  • Loading branch information
ckm007 authored Dec 23, 2024
2 parents a9a3bf0 + c12d73b commit e65a878
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ public ResponseWrapper<List<Map<String,?>>> retrieveVidsfromUin(String uin, int
+ e.getMessage() + ExceptionUtils.getStackTrace(e));
throw new ApisResourceAccessException("Unable to retrieve VID : " + e.getMessage());
}

ResponseWrapper<List<Map<String, ?>>> res = new ResponseWrapper<List<Map<String, ?>>>();
res.setId(residentVidGetId);
res.setVersion(newVersion);
res.setResponsetime(DateUtils.getUTCCurrentDateTimeString());
if(response.getErrors()!=null && !response.getErrors().isEmpty()){
res.setResponse(List.of());
return res;
}
List<Map<String, ?>> filteredList = ((List<Map<String, ?>>) response.getResponse()).stream()
.map(map -> {
LinkedHashMap<String, Object> lhm = new LinkedHashMap<String, Object>(map);
Expand All @@ -112,10 +119,6 @@ public ResponseWrapper<List<Map<String,?>>> retrieveVidsfromUin(String uin, int
})
.filter(map1 -> map1.get(TRANSACTIONS_LEFT_COUNT) == null || (int) map1.get(TRANSACTIONS_LEFT_COUNT) > 0)
.collect(Collectors.toList());
ResponseWrapper<List<Map<String, ?>>> res = new ResponseWrapper<List<Map<String, ?>>>();
res.setId(residentVidGetId);
res.setVersion(newVersion);
res.setResponsetime(DateUtils.getUTCCurrentDateTimeString());
res.setResponse(filteredList);
return res;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.mosip.resident.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.kernel.core.exception.ServiceError;
import io.mosip.resident.constant.ResidentErrorCode;
import io.mosip.resident.dto.ResponseWrapper;
import io.mosip.resident.exception.ApisResourceAccessException;
import io.mosip.resident.exception.ResidentServiceCheckedException;
Expand Down Expand Up @@ -141,5 +143,21 @@ public void testRetrieveVidsfromUin_Exception() throws ResidentServiceCheckedExc
perpetualVidUtil.retrieveVidsfromUin(uin, timeZoneOffset, locale);
});
}

@Test
public void testRetrieveVidsfromUin_EmtpyArray() throws ApisResourceAccessException, ResidentServiceCheckedException {
String uin = "123456789012";
int timeZoneOffset = 0;
String locale = "en";

ResponseWrapper<List<Map<String, ?>>> responseWrapper = new ResponseWrapper<>();
responseWrapper.setErrors(List.of(new ServiceError(ResidentErrorCode.NO_RECORDS_FOUND.getErrorCode(),
ResidentErrorCode.NO_RECORDS_FOUND.getErrorMessage())));

when(residentServiceRestClient.getApi(anyString(), eq(ResponseWrapper.class))).thenReturn(responseWrapper);
ResponseWrapper<List<Map<String, ?>>> result = perpetualVidUtil.retrieveVidsfromUin(uin, timeZoneOffset, locale);
assertNotNull(result);
assertEquals(0, result.getResponse().size());
}
}

0 comments on commit e65a878

Please sign in to comment.