Skip to content

Commit

Permalink
fixed notification issue
Browse files Browse the repository at this point in the history
Signed-off-by: Ritik Jain <[email protected]>
  • Loading branch information
Ritik Jain authored and Ritik Jain committed Nov 10, 2023
1 parent 95e696e commit 86685ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,13 @@ public Tuple2<byte[], String> downloadPersonalizedCard(
return Tuples.of(utility.signPdf(new ByteArrayInputStream(decodedData), password), eventId);
}

Map<String, Object> getIdentityData(String individualId) throws IOException {
private Map<String, Object> getIdentityData(String individualId) {
Map<String, Object> identityAttributes = null;
try {
identityAttributes = (Map<String, Object>) identityService.getIdentityAttributes(individualId, null);
identityAttributes = (Map<String, Object>) identityService.getIdentity(individualId);
} catch (ResidentServiceCheckedException e) {
logger.error("Unable to get attributes- " + e);
throw new ResidentServiceException(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD, e);
} catch (IOException e) {
logger.error("Unable to get attributes- " + e);
throw new IOException(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD.getErrorCode(), e);
}
return identityAttributes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package io.mosip.resident.service.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;

import io.mosip.kernel.core.exception.BaseCheckedException;
import io.mosip.kernel.core.exception.ServiceError;
import io.mosip.resident.constant.IdType;
Expand Down Expand Up @@ -30,30 +51,9 @@
import io.mosip.resident.util.ResidentServiceRestClient;
import io.mosip.resident.util.Utilities;
import io.mosip.resident.util.Utility;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;

/**
* This class is used to create service class test for getting cards.
*
Expand Down Expand Up @@ -107,7 +107,7 @@ public class DownloadCardServiceTest {

private MainRequestDTO<DownloadPersonalizedCardDto> downloadPersonalizedCardMainRequestDTO;

private Map identityMap;
private IdentityDTO identityMap;

private ResidentTransactionEntity residentTransactionEntity;

Expand Down Expand Up @@ -144,7 +144,7 @@ public void setup() throws Exception {
Mockito.when(identityService.getResidentIndvidualIdFromSession()).thenReturn("1234567890");
Mockito.when(idAuthService.validateOtpV2(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
Mockito.any())).thenReturn(Tuples.of(true, residentTransactionEntity));
identityMap = new LinkedHashMap();
identityMap = new IdentityDTO();
identityMap.put("UIN", "8251649601");
identityMap.put("email", "[email protected]");
identityMap.put("phone", "9395910872");
Expand All @@ -155,8 +155,7 @@ public void setup() throws Exception {
Mockito.when(identityService.getIdentity("1234567890")).thenReturn(identityDTO);
Mockito.when(identityService.getIdentity("7841261580")).thenReturn(identityDTO);
identityDTO.setUIN("123");
Map<String, Object> identityAttributes = new HashMap<>();
Mockito.when(identityService.getIdentityAttributes("1234567890",null)).thenReturn(identityAttributes);
Mockito.when(identityService.getIdentity("1234567890")).thenReturn(new IdentityDTO());
}

@Test
Expand Down Expand Up @@ -214,7 +213,7 @@ public void testDownloadPersonalizedCardWithAttributesListAndPassword()
name.put("language", "eng");
name.put("value", "kamesh");
identityMap.put("firstName", List.of(name));
Mockito.when(identityService.getIdentityAttributes(Mockito.anyString(), isNull())).thenReturn(identityMap);
Mockito.when(identityService.getIdentity(Mockito.anyString())).thenReturn(identityMap);
Mockito.when(utilities.getLanguageCode()).thenReturn("eng");
Mockito.when(utility.getPassword(Mockito.anyList())).thenReturn("kame1970");
Tuple2<byte[], String> actualResult = downloadCardService
Expand All @@ -234,18 +233,11 @@ public void testDownloadPersonalizedCardPasswordFailed() throws ResidentServiceC
@Test(expected = ResidentServiceException.class)
public void testDownloadPersonalizedCardResidentServiceCheckedException()
throws ResidentServiceCheckedException, IOException {
Mockito.when(identityService.getIdentityAttributes(Mockito.anyString(), Mockito.isNull()))
Mockito.when(identityService.getIdentity(Mockito.anyString()))
.thenThrow(new ResidentServiceCheckedException());
downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO, 0, LOCALE_EN_US);
}

@Test(expected = ResidentServiceException.class)
public void testDownloadPersonalizedCardIOException() throws ResidentServiceCheckedException, IOException {
Mockito.when(identityService.getIdentityAttributes(Mockito.anyString(), Mockito.isNull()))
.thenThrow(new IOException());
downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO, 0, LOCALE_EN_US);
}

@Test
public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException, IOException {
Mockito.when(identityService.getResidentIndvidualIdFromSession()).thenReturn("3257091426984315");
Expand Down

0 comments on commit 86685ba

Please sign in to comment.