|
15 | 15 | import io.mosip.registration.processor.packet.storage.dao.PacketInfoDao;
|
16 | 16 | import io.mosip.registration.processor.packet.storage.dto.ApplicantInfoDto;
|
17 | 17 | import io.mosip.registration.processor.packet.storage.mapper.PacketInfoMapper;
|
| 18 | +import io.mosip.registration.processor.status.code.RegistrationStatusCode; |
| 19 | +import io.mosip.registration.processor.status.entity.RegistrationStatusEntity; |
18 | 20 | import org.assertj.core.util.Lists;
|
19 | 21 | import org.junit.Before;
|
20 | 22 | import org.junit.Test;
|
|
45 | 47 | @PowerMockIgnore({ "javax.management.*", "javax.net.ssl.*","com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*" })
|
46 | 48 | public class ABISHandlerUtilTest {
|
47 | 49 |
|
48 |
| - private static final String registrationId = "10002100820001420210108085956"; |
49 |
| - private static final String registrationType = "NEW"; |
50 |
| - private static final String latestTransactionId = "123-456-789"; |
51 |
| - List<String> matchedRids = new ArrayList<>(); |
52 |
| - |
53 |
| - |
54 |
| - @InjectMocks |
55 |
| - private ABISHandlerUtil abisHandlerUtil; |
56 |
| - |
57 |
| - @Mock |
58 |
| - private Utilities utilities; |
59 |
| - |
60 |
| - @Mock |
61 |
| - private PacketInfoManager<Identity, ApplicantInfoDto> packetInfoManager; |
62 |
| - |
63 |
| - @Mock |
64 |
| - private PacketInfoDao packetInfoDao; |
65 |
| - |
66 |
| - @Mock |
67 |
| - private IdRepoService idRepoService; |
68 |
| - |
69 |
| - List<String> lst=new ArrayList<>(); |
70 |
| - |
71 |
| - @Before |
72 |
| - public void setup() throws Exception { |
73 |
| - MockitoAnnotations.initMocks(this); |
74 |
| - when(utilities.getLatestTransactionId(any(),any(),anyInt(), any())).thenReturn(latestTransactionId); |
75 |
| - |
76 |
| - List<String> regBioRefIds = new ArrayList<>(); |
77 |
| - regBioRefIds.add("cf1c941a-142c-44f1-9543-4606b4a7884e"); |
78 |
| - |
79 |
| - when(packetInfoDao.getAbisRefIdByWorkflowInstanceId(any())).thenReturn(regBioRefIds); |
80 |
| - when(utilities.getGetRegProcessorDemographicIdentity()).thenReturn(new String()); |
81 |
| - |
82 |
| - List<String> inprogressMatchedIds = new ArrayList<>(); |
83 |
| - inprogressMatchedIds.add("10002100820001420210108085100"); |
84 |
| - inprogressMatchedIds.add("10002100820001420210108085101"); |
85 |
| - inprogressMatchedIds.add("10002100820001420210108085102"); |
86 |
| - |
87 |
| - List<String> processedMatchedIds = new ArrayList<>(); |
88 |
| - processedMatchedIds.add("10002100820001420210108085103"); |
89 |
| - processedMatchedIds.add("10002100820001420210108085104"); |
90 |
| - |
91 |
| - matchedRids.addAll(inprogressMatchedIds); |
92 |
| - matchedRids.addAll(processedMatchedIds); |
93 |
| - |
94 |
| - List<AbisResponseDto> abisResponseDtoList = new ArrayList<>(); |
95 |
| - matchedRids.forEach(matchedRid -> { |
96 |
| - AbisResponseDto abisResponseDto = new AbisResponseDto(); |
97 |
| - abisResponseDto.setId(matchedRid); |
98 |
| - abisResponseDtoList.add(abisResponseDto); |
99 |
| - }); |
100 |
| - |
101 |
| - |
102 |
| - lst.add(RegistrationTransactionStatusCode.PROCESSED.toString());lst.add(RegistrationTransactionStatusCode.PROCESSING.toString()); |
103 |
| - |
104 |
| - |
105 |
| - when(packetInfoManager.getAbisResponseRecords(regBioRefIds.get(0), |
106 |
| - latestTransactionId, AbisConstant.IDENTIFY)).thenReturn(abisResponseDtoList); |
107 |
| - |
108 |
| - List<AbisResponseDetDto> abisResponseDetDtoList = new ArrayList<>(); |
109 |
| - |
110 |
| - matchedRids.forEach(matchedRid -> { |
111 |
| - AbisResponseDetDto abisResponseDto = new AbisResponseDetDto(); |
112 |
| - abisResponseDto.setMatchedBioRefId(matchedRid); |
113 |
| - abisResponseDetDtoList.add(abisResponseDto); |
114 |
| - }); |
115 |
| - for (AbisResponseDetDto dto : abisResponseDetDtoList) { |
116 |
| - AbisResponseDetDto responseDetDto = new AbisResponseDetDto(); |
117 |
| - responseDetDto.setMatchedBioRefId(dto.getMatchedBioRefId()); |
118 |
| - when(packetInfoManager.getAbisResponseDetails(dto.getMatchedBioRefId())).thenReturn(Lists.newArrayList(responseDetDto)); |
119 |
| - } |
120 |
| - |
121 |
| - when(packetInfoDao.getAbisRefRegIdsByMatchedRefIds(matchedRids)).thenReturn(matchedRids); |
122 |
| - |
123 |
| - when(packetInfoDao.getWithoutStatusCodes(matchedRids, RegistrationTransactionStatusCode.REJECTED.toString(), |
124 |
| - RegistrationTransactionStatusCode.PROCESSED.toString())).thenReturn(inprogressMatchedIds); |
125 |
| - when(packetInfoDao.getProcessedOrProcessingRegIds(matchedRids, |
126 |
| - lst)).thenReturn(processedMatchedIds); |
127 |
| - |
128 |
| - when(idRepoService.getUinByRid(processedMatchedIds.get(0), new String())).thenReturn("123456789"); |
129 |
| - when(idRepoService.getUinByRid(processedMatchedIds.get(1), new String())).thenReturn("987654321"); |
130 |
| - |
131 |
| - } |
132 |
| - |
133 |
| - @Test |
134 |
| - public void testProcesssedWithUniqueUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
135 |
| - |
136 |
| - Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, 1, "", ProviderStageName.BIO_DEDUPE); |
137 |
| - |
138 |
| - assertEquals(matchedRids.size(), uniqueRids.size()); |
139 |
| - } |
140 |
| - |
141 |
| - @Test |
142 |
| - public void testProcesssedWithSameUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
143 |
| - |
144 |
| - when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn("987654321"); |
145 |
| - |
146 |
| - Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); |
147 |
| - // expected to pick only 1 rid from processedMatchedIds list. Total should be 3(inprogress) + 1(processed) |
148 |
| - assertEquals(4, uniqueRids.size()); |
149 |
| - } |
150 |
| - |
151 |
| - @Test |
152 |
| - public void testDonotReturnRejected() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
153 |
| - |
154 |
| - when(packetInfoDao.getWithoutStatusCodes(matchedRids, RegistrationTransactionStatusCode.REJECTED.toString(), |
155 |
| - RegistrationTransactionStatusCode.PROCESSED.toString())).thenReturn(Lists.newArrayList()); |
156 |
| - |
157 |
| - Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); |
158 |
| - // expected to pick only rocessedMatchedIds list i.e 2 records. |
159 |
| - assertEquals(2, uniqueRids.size()); |
160 |
| - } |
161 |
| - |
162 |
| - @Test |
163 |
| - public void testReturnAllInprogress() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
164 |
| - |
165 |
| - when(packetInfoDao.getProcessedOrProcessingRegIds(matchedRids, |
166 |
| - lst)).thenReturn(Lists.newArrayList()); |
167 |
| - |
168 |
| - Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); |
169 |
| - // expected not to pick rocessedMatchedIds list i.e 3 records. |
170 |
| - assertEquals(3, uniqueRids.size()); |
171 |
| - } |
| 50 | + private static final String registrationId = "10002100820001420210108085956"; |
| 51 | + private static final String registrationType = "NEW"; |
| 52 | + private static final String latestTransactionId = "123-456-789"; |
| 53 | + List<String> matchedRids = new ArrayList<>(); |
| 54 | + |
| 55 | + |
| 56 | + @InjectMocks |
| 57 | + private ABISHandlerUtil abisHandlerUtil; |
| 58 | + |
| 59 | + @Mock |
| 60 | + private Utilities utilities; |
| 61 | + |
| 62 | + @Mock |
| 63 | + private PacketInfoManager<Identity, ApplicantInfoDto> packetInfoManager; |
| 64 | + |
| 65 | + @Mock |
| 66 | + private PacketInfoDao packetInfoDao; |
| 67 | + |
| 68 | + @Mock |
| 69 | + private IdRepoService idRepoService; |
| 70 | + |
| 71 | + List<String> lst=new ArrayList<>(); |
| 72 | + |
| 73 | + @Before |
| 74 | + public void setup() throws Exception { |
| 75 | + MockitoAnnotations.initMocks(this); |
| 76 | + when(utilities.getLatestTransactionId(any(),any(),anyInt(), any())).thenReturn(latestTransactionId); |
| 77 | + |
| 78 | + List<String> regBioRefIds = new ArrayList<>(); |
| 79 | + regBioRefIds.add("cf1c941a-142c-44f1-9543-4606b4a7884e"); |
| 80 | + |
| 81 | + when(packetInfoDao.getAbisRefIdByWorkflowInstanceId(any())).thenReturn(regBioRefIds); |
| 82 | + when(utilities.getGetRegProcessorDemographicIdentity()).thenReturn(new String()); |
| 83 | + |
| 84 | + List<RegistrationStatusEntity> registrationStatusEntityList = new ArrayList<>(); |
| 85 | + |
| 86 | + RegistrationStatusEntity registrationEntity1 = new RegistrationStatusEntity(); |
| 87 | + registrationEntity1.setRegId("10002100820001420210108085103"); |
| 88 | + registrationEntity1.setStatusCode(RegistrationStatusCode.PROCESSED.toString()); |
| 89 | + registrationStatusEntityList.add(registrationEntity1); |
| 90 | + RegistrationStatusEntity registrationEntity2 = new RegistrationStatusEntity(); |
| 91 | + registrationEntity2.setRegId("10002100820001420210108085100"); |
| 92 | + registrationEntity2.setStatusCode(RegistrationStatusCode.PROCESSING.toString()); |
| 93 | + registrationStatusEntityList.add(registrationEntity2); |
| 94 | + RegistrationStatusEntity registrationEntity3 = new RegistrationStatusEntity(); |
| 95 | + registrationEntity3.setRegId("10002100820001420210108085102"); |
| 96 | + registrationEntity3.setStatusCode(RegistrationStatusCode.PROCESSED.toString()); |
| 97 | + registrationStatusEntityList.add(registrationEntity3); |
| 98 | + matchedRids.add("10002100820001420210108085100"); |
| 99 | + matchedRids.add("10002100820001420210108085103"); |
| 100 | + matchedRids.add("10002100820001420210108085101");// REJECTED |
| 101 | + matchedRids.add("10002100820001420210108085102"); |
| 102 | + |
| 103 | + List<AbisResponseDto> abisResponseDtoList = new ArrayList<>(); |
| 104 | + matchedRids.forEach(matchedRid -> { |
| 105 | + AbisResponseDto abisResponseDto = new AbisResponseDto(); |
| 106 | + abisResponseDto.setId(matchedRid); |
| 107 | + abisResponseDtoList.add(abisResponseDto); |
| 108 | + }); |
| 109 | + |
| 110 | + lst.add(RegistrationTransactionStatusCode.PROCESSED.toString());lst.add(RegistrationTransactionStatusCode.PROCESSING.toString()); |
| 111 | + |
| 112 | + when(packetInfoManager.getAbisResponseRecords(regBioRefIds.get(0), |
| 113 | + latestTransactionId, AbisConstant.IDENTIFY)).thenReturn(abisResponseDtoList); |
| 114 | + |
| 115 | + List<AbisResponseDetDto> abisResponseDetDtoList = new ArrayList<>(); |
| 116 | + matchedRids.forEach(matchedRid -> { |
| 117 | + AbisResponseDetDto abisResponseDto = new AbisResponseDetDto(); |
| 118 | + abisResponseDto.setMatchedBioRefId(matchedRid); |
| 119 | + abisResponseDetDtoList.add(abisResponseDto); |
| 120 | + }); |
| 121 | + for (AbisResponseDetDto dto : abisResponseDetDtoList) { |
| 122 | + AbisResponseDetDto responseDetDto = new AbisResponseDetDto(); |
| 123 | + responseDetDto.setMatchedBioRefId(dto.getMatchedBioRefId()); |
| 124 | + when(packetInfoManager.getAbisResponseDetails(dto.getMatchedBioRefId())).thenReturn(Lists.newArrayList(responseDetDto)); |
| 125 | + } |
| 126 | + when(packetInfoDao.getAbisRefRegIdsByMatchedRefIds(matchedRids)).thenReturn(matchedRids); |
| 127 | + when(packetInfoDao.getWithoutStatusCode(matchedRids, RegistrationStatusCode.REJECTED.toString())) |
| 128 | + .thenReturn(registrationStatusEntityList); |
| 129 | + when(idRepoService.getUinByRid("10002100820001420210108085103", new String())).thenReturn("123456789"); |
| 130 | + when(idRepoService.getUinByRid("10002100820001420210108085102", new String())).thenReturn("987654321"); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void testProcesssedWithUniqueUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
| 135 | + |
| 136 | + Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, 1, "", ProviderStageName.BIO_DEDUPE); |
| 137 | +// expected to pick 2 rids from processedMatchedIds list because different uin. |
| 138 | + // Total should be 1(inprogress) + 2(processed) |
| 139 | + assertEquals(3, uniqueRids.size()); |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + public void testProcesssedWithSameUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
| 144 | + |
| 145 | + when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn("987654321"); |
| 146 | + |
| 147 | + Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); |
| 148 | + // expected to pick only 1 rid from processedMatchedIds list because same uin. Total should be 1(inprogress) + 1(processed) |
| 149 | + assertEquals(2, uniqueRids.size()); |
| 150 | + } |
| 151 | + |
| 152 | + @Test |
| 153 | + public void testDonotReturnRejected() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
| 154 | + |
| 155 | +// List<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, ProviderStageName.BIO_DEDUPE); |
| 156 | + Set<String> uniqueRids= abisHandlerUtil.getUniqueRegIds(registrationId,registrationType,1,"",ProviderStageName.BIO_DEDUPE); |
| 157 | + // expected to pick only processingandprocessed list i.e 3 records. |
| 158 | + assertEquals(3, uniqueRids.size()); |
| 159 | + } |
| 160 | + |
| 161 | + @Test |
| 162 | + public void testReturnAllInprogress() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { |
| 163 | + |
| 164 | + when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn(null); |
| 165 | + |
| 166 | + Set<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); |
| 167 | + // expected not to pick processedMatchedIds list i.e 1 records.. |
| 168 | + assertEquals(1, uniqueRids.size()); |
| 169 | + } |
172 | 170 |
|
173 | 171 | }
|
0 commit comments