From f1a8ce31baf81450f1a49ca4b69db18f916823e0 Mon Sep 17 00:00:00 2001 From: nkokkiligadda87 Date: Mon, 26 Aug 2024 16:18:01 +0530 Subject: [PATCH] deleted junit test classes --- .../controller/IdentityControllerTest.java | 377 -------- .../rmnch/RMNCHMobileAppControllerTest.java | 127 --- .../identity/service/IdentityServiceTest.java | 906 ----------------- .../FamilyTagServiceImplTest.java | 537 ----------- .../rmnch/RmnchDataSyncServiceImplTest.java | 907 ------------------ 5 files changed, 2854 deletions(-) delete mode 100644 src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java delete mode 100644 src/test/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppControllerTest.java delete mode 100644 src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java delete mode 100644 src/test/java/com/iemr/common/identity/service/familyTagging/FamilyTagServiceImplTest.java delete mode 100644 src/test/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImplTest.java diff --git a/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java b/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java deleted file mode 100644 index 640864e..0000000 --- a/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java +++ /dev/null @@ -1,377 +0,0 @@ -/* -* AMRIT – Accessible Medical Records via Integrated Technology -* Integrated EHR (Electronic Health Records) Solution -* -* Copyright (C) "Piramal Swasthya Management and Research Institute" -* -* This file is part of AMRIT. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see https://www.gnu.org/licenses/. -*/ -package com.iemr.common.identity.controller; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.google.common.collect.Lists; -import com.google.gson.Gson; -import com.iemr.common.identity.domain.Address; -import com.iemr.common.identity.dto.BenFamilyDTO; -import com.iemr.common.identity.dto.BenIdentityDTO; -import com.iemr.common.identity.dto.BenServiceDTO; -import com.iemr.common.identity.dto.BeneficiariesDTO; -import com.iemr.common.identity.dto.IdentityEditDTO; -import com.iemr.common.identity.dto.IdentitySearchDTO; -import com.iemr.common.identity.dto.ReserveIdentityDTO; -import com.iemr.common.identity.dto.SearchSyncDTO; -import com.iemr.common.identity.exception.MissingMandatoryFieldsException; -import com.iemr.common.identity.service.IdentityService; - -import jakarta.persistence.NoResultException; -import jakarta.persistence.QueryTimeoutException; -import net.minidev.json.JSONObject; -import net.minidev.json.parser.JSONParser; -import net.minidev.json.parser.ParseException; - - -@ExtendWith(MockitoExtension.class) -class IdentityControllerTest { - @InjectMocks - IdentityController identityController; - @Mock - IdentityService svc; - - @Test - void testGetBeneficiaries() throws NoResultException, QueryTimeoutException, Exception { - IdentitySearchDTO searchParams = new IdentitySearchDTO(); - - BeneficiariesDTO a1 = new BeneficiariesDTO(); - makeBeneficiariesDTO(a1); - List bdList = Lists.newArrayList(); - a1.setBenId(new BigInteger("1")); - bdList.add(a1); - - String req = new Gson().toJson(searchParams); - //when(svc.getBeneficiaries(searchParams)).thenReturn(any()).thenReturn(bdList); - String resp = identityController.getBeneficiaries(req); - Assertions.assertNotNull(resp); - - } - - private void makeBeneficiariesDTO(BeneficiariesDTO dto) { - dto.setAbhaDetails(null); - dto.setAccountNo(null); - dto.setAgeAtMarriage(null); - dto.setBankName(null); - dto.setBenAccountID(null); - dto.setBeneficiaryAge(null); - dto.setBeneficiaryDetails(null); - List tags = new ArrayList<>(); - BenFamilyDTO benFamilyDTO = new BenFamilyDTO(); - benFamilyDTO.setAssociatedBenRegId(null); - benFamilyDTO.setBenFamilyMapId(null); - benFamilyDTO.setCreatedBy(null); - benFamilyDTO.setCreatedDate(null); - benFamilyDTO.setDeleted(null); - benFamilyDTO.setIsEmergencyContact(true); - benFamilyDTO.setLastModDate(null); - benFamilyDTO.setModifiedBy(null); - benFamilyDTO.setParkingPlaceID(null); - benFamilyDTO.setRelationshipID(null); - benFamilyDTO.setRelationshipToSelf(null); - benFamilyDTO.setVanID(null); - - tags.add(benFamilyDTO); - dto.setBeneficiaryFamilyTags(tags); - List identity = new ArrayList<>(); - BenIdentityDTO benIdentityDTO= new BenIdentityDTO(); - benIdentityDTO.toString(); - identity.add(benIdentityDTO); - dto.setBeneficiaryIdentites(identity); - - List service = new ArrayList<>(); - BenServiceDTO benServiceDTO= new BenServiceDTO(); - benServiceDTO.toString(); - service.add(benServiceDTO); - dto.setBeneficiaryServiceMap(service); - dto.setBenId(null); - dto.setBenMapId(null); - dto.setBenRegId(null); - dto.setBranchName(null); - dto.setContacts(null); - dto.setCreatedBy(null); - dto.setCreatedDate(null); - Address address = new Address(); - address.toString(); - address.equals(address); - dto.setCurrentAddress(null); - dto.setDeleted(null); - dto.setEmail(null); - dto.setEmergencyAddress(address); - dto.setEmergencyContactNum(null); - dto.setEmergencyContactTyp(null); - dto.setIfscCode(null); - dto.setIncomeStatus(null); - dto.setIsHIVPos(null); - dto.setLastModDate(null); - dto.setLiteracyStatus(null); - dto.setMarriageDate(null); - dto.setModifiedBy(null); - dto.setMonthlyFamilyIncome(null); - dto.setMotherName(null); - dto.setOccupationName(null); - dto.setOccupationId(null); - dto.setPermanentAddress(address); - dto.setPreferredEmailId(null); - dto.setPreferredPhoneNum(null); - dto.setPreferredPhoneTyp(null); - dto.setPreferredSMSPhoneNum(null); - dto.setPreferredSMSPhoneTyp(null); - dto.setReligion(null); - dto.setReligionId(null); - dto.setSourceOfInformation(null); - dto.toString(); - BeneficiariesDTO beneficiariesDTO = new BeneficiariesDTO(); - dto.equals(beneficiariesDTO); - - } - - @Test - void testGetBeneficiariesByBeneficiaryRegId() { - String resp = identityController.getBeneficiariesByBeneficiaryRegId("123"); - Assertions.assertNotNull(resp); - } - - @Test - void testGetBeneficiariesByBeneficiaryRegIdCatchBlock() throws NoResultException, QueryTimeoutException, Exception { - when(svc.getBeneficiariesByBenRegId(any())).thenThrow(NoResultException.class); - String resp = identityController.getBeneficiariesByBeneficiaryRegId("123"); - Assertions.assertNotNull(resp); - } - - @Test - void testGetBeneficiariesByBeneficiaryId() { - String resp = identityController.getBeneficiariesByBeneficiaryId("987"); - Assertions.assertNotNull(resp); - } - @Test - void testGetBeneficiariesByBeneficiaryIdCatchBlock() throws NoResultException, QueryTimeoutException, Exception { - when(svc.getBeneficiariesByBenId(any())).thenThrow(NoResultException.class); - String resp = identityController.getBeneficiariesByBeneficiaryId("987"); - Assertions.assertNotNull(resp); - } - - @Test - void testGetBeneficiariesByPhoneNum() { - String resp = identityController.getBeneficiariesByPhoneNum("9988776655"); - Assertions.assertNotNull(resp); - } - @Test - void testGetBeneficiariesByPhoneNumCatchblock() throws NoResultException, QueryTimeoutException, Exception { - when(svc.getBeneficiariesByPhoneNum(any())).thenThrow(NoResultException.class); - String resp = identityController.getBeneficiariesByPhoneNum("9988776655"); - Assertions.assertNotNull(resp); - } - @Test - void testSearhBeneficiaryByABHAAddress() { - String resp = identityController.searhBeneficiaryByABHAAddress("9876"); - Assertions.assertNotNull(resp); - } - - @Test - void testSearhBeneficiaryByABHAAddressCatchblock() throws NoResultException, QueryTimeoutException, Exception { - when(svc.getBeneficiaryByHealthIDAbhaAddress(any())).thenThrow(NoResultException.class); - String resp = identityController.searhBeneficiaryByABHAAddress("9876"); - Assertions.assertNotNull(resp); - } - @Test - void testSearhBeneficiaryByABHAIdNo() { - String resp = identityController.searhBeneficiaryByABHAIdNo("9876"); - Assertions.assertNotNull(resp); - } - @Test - void testSearhBeneficiaryByABHAIdNoCatchblock() throws NoResultException, QueryTimeoutException, Exception { - when(svc.getBeneficiaryByHealthIDNoAbhaIdNo(any())).thenThrow(NoResultException.class); - String resp = identityController.searhBeneficiaryByABHAIdNo("9876"); - Assertions.assertNotNull(resp); - } - - @Test - void testSearhBeneficiaryByFamilyId() { - String resp = identityController.searhBeneficiaryByFamilyId("9876"); - Assertions.assertNotNull(resp); - } - @Test - void testSearhBeneficiaryByFamilyIdCatchblock() throws NoResultException, QueryTimeoutException, Exception { - when(svc.searhBeneficiaryByFamilyId(any())).thenThrow(NoResultException.class); - String resp = identityController.searhBeneficiaryByFamilyId("9876"); - Assertions.assertNotNull(resp); - } - - @Test - void testSearchBeneficiaryByBlockIdAndLastModDate() { - BeneficiariesDTO a1 = new BeneficiariesDTO(); - List bdList = Lists.newArrayList(); - a1.setBenId(new BigInteger("1")); - bdList.add(a1); - SearchSyncDTO searchSyncDTO = new SearchSyncDTO(); - String req = new Gson().toJson(searchSyncDTO); - //when(svc.searchBeneficiaryByBlockIdAndLastModifyDate(any(), any())).thenReturn(bdList); - - String resp = identityController.searchBeneficiaryByVillageIdAndLastModDate(req); - - Assertions.assertNotNull(resp); - } - - - - @Test - void testReserveIdentityEmptyIdentity() throws ParseException { - String resp = identityController.reserveIdentity("String"); - String status = getData(resp, "statusMessage"); - Assertions.assertNotEquals("Null/Empty Identity Create Data.", status); - } - - @Test - void testReserveIdentity() throws ParseException { - ReserveIdentityDTO reserveIdentityDTO = new ReserveIdentityDTO(); - String req = new Gson().toJson(reserveIdentityDTO); - String resp = identityController.reserveIdentity(req); - String status = getData(resp, "statusMessage"); - Assertions.assertEquals("success", status); - } - - @Test - void testUnreserveIdentityEmptyIdentity() throws ParseException { - String resp = identityController.unreserveIdentity("String"); - String status = getData(resp, "statusMessage"); - Assertions.assertNotEquals("Null/Empty Identity Create Data.", status); - - } - @Test - void testUnreserveIdentity() throws ParseException { - ReserveIdentityDTO reserveIdentityDTO = new ReserveIdentityDTO(); - String req = new Gson().toJson(reserveIdentityDTO); - String resp = identityController.unreserveIdentity(req); - String status = getData(resp, "statusMessage"); - Assertions.assertEquals("success", status); - } - - //@Test - void testGetJsonAsString() { - //identityController. - } - - @Test - void testGetFiniteBeneficiariesCatchblockIfInvalidJSON() { - String resp = identityController.getFiniteBeneficiaries("String"); - Assertions.assertNotNull(resp); - } - @Test - void testGetFiniteBeneficiaries() throws ParseException { - IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO(); - String req = new Gson().toJson(identitySearchDTO); - String resp = identityController.getFiniteBeneficiaries(req); - String status = getData(resp, "statusMessage"); - Assertions.assertEquals("success", status); - } - - @Test - void testGetFiniteBeneficiariesNoResultException() throws NoResultException, QueryTimeoutException, Exception { - IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO(); - String req = new Gson().toJson(identitySearchDTO); - when(svc.getBeneficiaries(identitySearchDTO)).thenThrow(NoResultException.class); - String resp = identityController.getFiniteBeneficiaries(req); - String status = getData(resp, "statusMessage"); - Assertions.assertEquals("failure", status); - } - @Test - void testGetFiniteBeneficiariesQueryTimeoutException() throws NoResultException, QueryTimeoutException, Exception { - IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO(); - String req = new Gson().toJson(identitySearchDTO); - when(svc.getBeneficiaries(identitySearchDTO)).thenThrow(QueryTimeoutException.class); - String resp = identityController.getFiniteBeneficiaries(req); - String status = getData(resp, "statusMessage"); - Assertions.assertEquals("failure", status); - } - - - @Test - void testGetBeneficiaryImageByBenRegID() { - String resp = identityController.getBeneficiaryImageByBenRegID("String"); - Assertions.assertNull(resp); - } - - @Test - void testEditIdentityEducationOrCommunity() throws ParseException { - IdentityEditDTO identityEditDTO = new IdentityEditDTO(); - String req = new Gson().toJson(identityEditDTO); - String resp = identityController.editIdentityEducationOrCommunity(req); - String actualresp = getData(resp,"data"); - Assertions.assertEquals("Updated successfully", actualresp); - } - - - private String getData(String resp,String status) throws ParseException { - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(resp); - JSONObject object = (JSONObject) json.get("response"); - String actualresp = object.getAsString(status); - return actualresp; - } - - @Test - void testEditIdentityEducationOrCommunityCatchblock() throws MissingMandatoryFieldsException, ParseException { - IdentityEditDTO identityEditDTO = new IdentityEditDTO(); - String req = new Gson().toJson(identityEditDTO); - doThrow(MissingMandatoryFieldsException.class).when(svc).editIdentityEducationOrCommunity(identityEditDTO); - svc.editIdentityEducationOrCommunity(any()); - String resp = identityController.editIdentityEducationOrCommunity(req); - String actualresp = getData(resp,"data"); - Assertions.assertNotEquals("Updated successfully", actualresp); - } - - @Test - void testCheckAvailablBenIDLocalServer() { - String resp = identityController.checkAvailablBenIDLocalServer(); - Assertions.assertNotNull(resp); - } - - @Test - void testSaveGeneratedBenIDToLocalServer() { - String resp = identityController.saveGeneratedBenIDToLocalServer(null); - Assertions.assertNotNull(resp); - } - @Test - public void testcountBeneficiaryByVillageIdAndLastModDate() { - SearchSyncDTO searchSyncDTO = new SearchSyncDTO(); - searchSyncDTO.setLastModifiedDate(9l); - String json = new Gson().toJson(searchSyncDTO); - when(svc.countBeneficiaryByVillageIdAndLastModifyDate(any(), any())).thenReturn(9l); - String resp = identityController.countBeneficiaryByVillageIdAndLastModDate(json); - Assertions.assertNotNull(resp); - } -} diff --git a/src/test/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppControllerTest.java b/src/test/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppControllerTest.java deleted file mode 100644 index ff95378..0000000 --- a/src/test/java/com/iemr/common/identity/controller/rmnch/RMNCHMobileAppControllerTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.iemr.common.identity.controller.rmnch; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.iemr.common.identity.service.rmnch.RmnchDataSyncService; - -import net.minidev.json.JSONObject; -import net.minidev.json.parser.JSONParser; -import net.minidev.json.parser.ParseException; -@ExtendWith(MockitoExtension.class) -class RMNCHMobileAppControllerTest { - @InjectMocks - RMNCHMobileAppController rmnchMobileAppController; - @Mock - RmnchDataSyncService rmnchDataSyncService; - - @Test - void testSyncDataToAmrit() throws Exception { - String req = "requestObj"; - when(rmnchDataSyncService.syncDataToAmrit(any())).thenReturn("resp"); - String syncDataToAmrit = rmnchMobileAppController.syncDataToAmrit(req); - assertNotNull(syncDataToAmrit); - } - @Test - void testSyncDataToAmritNullReq() throws Exception { - String req = null; - String syncDataToAmrit = rmnchMobileAppController.syncDataToAmrit(req); - String data = getData(syncDataToAmrit,"errorMessage"); - assertEquals("Invalid/NULL request obj", data); - } - @Test - void testSyncDataToAmritException() throws Exception { - String req = "requestObj"; - when(rmnchDataSyncService.syncDataToAmrit(any())).thenThrow(Exception.class); - String syncDataToAmrit = rmnchMobileAppController.syncDataToAmrit(req); - String data = getData(syncDataToAmrit,"errorMessage"); - assertTrue(data.contains("Error in RMNCH mobile data sync")); - } - - @Test - void testGetBeneficiaryData() throws Exception { - String req = "requestObj"; - String auth = "authorization"; - when(rmnchDataSyncService.getBenData(req, auth)).thenReturn("resp"); - String beneficiaryData = rmnchMobileAppController.getBeneficiaryData(req, auth); - assertNotNull(beneficiaryData); - } - @Test - void testGetBeneficiaryDataNullResp() throws Exception { - String req = "requestObj"; - String auth = "authorization"; - when(rmnchDataSyncService.getBenData(req, auth)).thenReturn(null); - String beneficiaryData = rmnchMobileAppController.getBeneficiaryData(req, auth); - String data = getData(beneficiaryData,"errorMessage"); - assertTrue(data.contains("No record found")); - } - @Test - void testGetBeneficiaryDataNullReq() throws Exception { - String req = null; - String auth = "authorization"; - String beneficiaryData = rmnchMobileAppController.getBeneficiaryData(req, auth); - String data = getData(beneficiaryData,"errorMessage"); - assertEquals("Invalid/NULL request obj", data); - } - @Test - void testGetBeneficiaryDataException() throws Exception { - String req = "requestObj"; - String auth = "authorization"; - when(rmnchDataSyncService.getBenData(req, auth)).thenThrow(Exception.class); - String beneficiaryData = rmnchMobileAppController.getBeneficiaryData(req, auth); - String data = getData(beneficiaryData,"errorMessage"); - assertTrue(data.contains("Error in get data")); - } - - @Test - void testGetBeneficiaryDataByAsha() throws Exception { - String req = "requestObj"; - String auth = "authorization"; - when(rmnchDataSyncService.getBenDataByAsha(req, auth)).thenReturn("resp"); - String beneficiaryDataByAsha = rmnchMobileAppController.getBeneficiaryDataByAsha(req, auth); - assertNotNull(beneficiaryDataByAsha); - } - - @Test - void testGetBeneficiaryDataByAshaNullResp() throws Exception { - String req = "requestObj"; - String auth = "authorization"; - when(rmnchDataSyncService.getBenDataByAsha(req, auth)).thenReturn(null); - String beneficiaryDataByAsha = rmnchMobileAppController.getBeneficiaryDataByAsha(req, auth); - String data = getData(beneficiaryDataByAsha,"errorMessage"); - assertTrue(data.contains("No record found")); - } - @Test - void testGetBeneficiaryDataByAshaNullReq() throws Exception { - String req = null; - String auth = "authorization"; - String beneficiaryDataByAsha = rmnchMobileAppController.getBeneficiaryDataByAsha(req, auth); - String data = getData(beneficiaryDataByAsha,"errorMessage"); - assertEquals("Invalid/NULL request obj", data); - } - - @Test - void testGetBeneficiaryDataByAshaException() throws Exception { - String req = "requestObj"; - String auth = "authorization"; - when(rmnchDataSyncService.getBenDataByAsha(req, auth)).thenThrow(Exception.class); - String beneficiaryDataByAsha = rmnchMobileAppController.getBeneficiaryDataByAsha(req, auth); - String data = getData(beneficiaryDataByAsha,"errorMessage"); - assertTrue(data.contains("Error in get data")); - } - private String getData(String resp, String status) throws ParseException { - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(resp); - String actualresp = json.getAsString(status); - return actualresp; - } -} diff --git a/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java b/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java deleted file mode 100644 index 3e87215..0000000 --- a/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java +++ /dev/null @@ -1,906 +0,0 @@ -/* -* AMRIT – Accessible Medical Records via Integrated Technology -* Integrated EHR (Electronic Health Records) Solution -* -* Copyright (C) "Piramal Swasthya Management and Research Institute" -* -* This file is part of AMRIT. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see https://www.gnu.org/licenses/. -*/ -package com.iemr.common.identity.service; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.when; - -import java.math.BigInteger; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.annotation.Description; -import org.springframework.jdbc.core.JdbcTemplate; - -import com.google.common.collect.Lists; -import com.google.gson.Gson; -import com.iemr.common.identity.data.rmnch.RMNCHBeneficiaryDetailsRmnch; -import com.iemr.common.identity.domain.Address; -import com.iemr.common.identity.domain.Identity; -import com.iemr.common.identity.domain.MBeneficiaryAccount; -import com.iemr.common.identity.domain.MBeneficiaryImage; -import com.iemr.common.identity.domain.MBeneficiaryaddress; -import com.iemr.common.identity.domain.MBeneficiaryconsent; -import com.iemr.common.identity.domain.MBeneficiarycontact; -import com.iemr.common.identity.domain.MBeneficiarydetail; -import com.iemr.common.identity.domain.MBeneficiaryfamilymapping; -import com.iemr.common.identity.domain.MBeneficiaryidentity; -import com.iemr.common.identity.domain.MBeneficiarymapping; -import com.iemr.common.identity.domain.MBeneficiaryregidmapping; -import com.iemr.common.identity.domain.MBeneficiaryservicemapping; -import com.iemr.common.identity.dto.BenFamilyDTO; -import com.iemr.common.identity.dto.BenIdImportDTO; -import com.iemr.common.identity.dto.BenIdentityDTO; -import com.iemr.common.identity.dto.BeneficiariesDTO; -import com.iemr.common.identity.dto.BeneficiariesPartialDTO; -import com.iemr.common.identity.dto.BeneficiaryCreateResp; -import com.iemr.common.identity.dto.IdentityDTO; -import com.iemr.common.identity.dto.IdentityEditDTO; -import com.iemr.common.identity.dto.IdentitySearchDTO; -import com.iemr.common.identity.dto.ReserveIdentityDTO; -import com.iemr.common.identity.exception.MissingMandatoryFieldsException; -import com.iemr.common.identity.mapper.BenIdImportMapper; -import com.iemr.common.identity.mapper.IdentityEditMapper; -import com.iemr.common.identity.mapper.IdentityMapper; -import com.iemr.common.identity.mapper.IdentityPartialMapper; -import com.iemr.common.identity.repo.BenAddressRepo; -import com.iemr.common.identity.repo.BenConsentRepo; -import com.iemr.common.identity.repo.BenContactRepo; -import com.iemr.common.identity.repo.BenDataAccessRepo; -import com.iemr.common.identity.repo.BenDetailRepo; -import com.iemr.common.identity.repo.BenFamilyMappingRepo; -import com.iemr.common.identity.repo.BenIdentityRepo; -import com.iemr.common.identity.repo.BenMappingRepo; -import com.iemr.common.identity.repo.BenRegIdMappingRepo; -import com.iemr.common.identity.repo.BenServiceMappingRepo; -import com.iemr.common.identity.repo.MBeneficiaryAccountRepo; -import com.iemr.common.identity.repo.MBeneficiaryImageRepo; -import com.iemr.common.identity.repo.V_BenAdvanceSearchRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBeneficiaryDetailsRmnchRepo; -import com.iemr.common.identity.utils.exception.IEMRException; - -import jakarta.persistence.NoResultException; -import jakarta.persistence.QueryTimeoutException; -import net.minidev.json.JSONObject; -import net.minidev.json.parser.JSONParser; -import net.minidev.json.parser.ParseException; - -@ExtendWith(MockitoExtension.class) -public class IdentityServiceTest { - @Mock - private JdbcTemplate jdbcTemplate; - @Mock - private DataSource dataSource; - - @InjectMocks - IdentityService identityService; - - @Mock - BenRegIdMappingRepo benRegIdMappingRepo; - - @Mock - BenMappingRepo benMappingRepo; - - @Mock - IdentityMapper identityMapper; - - @Mock - BenDetailRepo detailRepo; - - @Mock - BenContactRepo contactRepo; - - @Mock - IdentityEditMapper editMapper; - - @Mock - BenAddressRepo addressRepo; - - @Mock - MBeneficiarymapping beneficiarymapping; - - @Mock - MBeneficiarydetail beneficiarydetail; - - @Mock - MBeneficiaryaddress beneficiaryaddress; - - @Mock - BenIdentityRepo identityRepo; - - @Mock - MBeneficiaryconsent mBeneficiaryconsent; - - @Mock - BenConsentRepo consentRepo; - - @Mock - MBeneficiarycontact mBeneficiarycontact; - - @Mock - MBeneficiaryregidmapping mBeneficiaryregidmapping; - - @Mock - MBeneficiaryfamilymapping fMap; - - @Mock - BenFamilyMappingRepo familyMapRepo; - - @Mock - MBeneficiaryservicemapping mBeneficiaryservicemapping; - - @Mock - BenServiceMappingRepo serviceMapRepo; - - @Mock - IdentityPartialMapper partialMapper; - - @Mock - BenDataAccessRepo accessRepo; - @Mock - MBeneficiaryAccountRepo accountRepo; - @Mock - MBeneficiaryImageRepo imageRepo; - @Mock - BenMappingRepo mappingRepo; - @Mock - private V_BenAdvanceSearchRepo v_BenAdvanceSearchRepo; - @Mock - private RMNCHBeneficiaryDetailsRmnchRepo rMNCHBeneficiaryDetailsRmnchRepo; - @Mock - private BenIdImportMapper benIdImportMapper; - - @Test - void getBenAdressTest() { - identityService.getBenAdress(); - } - - @Test - @Description("getting beneficiaries by Id") - void getBeneficiariesTest() throws NoResultException, QueryTimeoutException, Exception { - - List list = Lists.newArrayList(); - - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenMapId(new BigInteger("201")); - MBeneficiaryregidmapping mBeneficiaryregidmapping = new MBeneficiaryregidmapping(); - mBeneficiaryregidmapping.setBeneficiaryID(new BigInteger("303")); - mBeneficiarymapping.setMBeneficiaryregidmapping(mBeneficiaryregidmapping); - - List familyList = Lists.newArrayList(); - MBeneficiaryfamilymapping familyMapping = new MBeneficiaryfamilymapping(); - familyMapping.setBenFamilyMapId(new BigInteger("808")); - familyList.add(familyMapping); - mBeneficiarymapping.setMBeneficiaryfamilymappings(familyList); - - List identitylist = Lists.newArrayList(); - MBeneficiaryidentity identity = new MBeneficiaryidentity(); - identity.setBenIdentityId(new BigInteger("909")); - identitylist.add(identity); - mBeneficiarymapping.setMBeneficiaryidentities(identitylist); - - list.add(mBeneficiarymapping); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - - IdentitySearchDTO searchParams = new IdentitySearchDTO(); - searchParams.setContactNumber("9876543210"); - - List mBenContactList = new ArrayList<>(); - MBeneficiarycontact mBeneficiarycontact2 = makeMBeneficiarycontact(); - mBenContactList.add(mBeneficiarycontact2); - - when(contactRepo.findByAnyPhoneNum(searchParams.getContactNumber())).thenReturn(mBenContactList); - ; - List objArr = new ArrayList<>(); - Object[] elements = new Object[12]; - elements[0] = 987; - elements[1] = 1; - elements[2] = 2; - elements[3] = 3; - elements[4] = 45; - elements[5] = BigInteger.valueOf(55); - elements[6] = Long.valueOf(98); - elements[7] = 7; - elements[8] = 123; - elements[9] = 9; - elements[10] = ""; - elements[11] = Timestamp.valueOf("2011-10-02 18:48:05.123"); - objArr.add(elements); - when(mappingRepo.getBenMappingByBenContactIdListNew(mBeneficiarycontact2.getVanSerialNo(), - mBeneficiarycontact2.getVanID())).thenReturn(objArr); - RMNCHBeneficiaryDetailsRmnch rmnchBenDetails = new RMNCHBeneficiaryDetailsRmnch(); - rmnchBenDetails.setHouseoldId(9l); - rmnchBenDetails.setGuidelineId("8"); - rmnchBenDetails.setRchid("7"); - rmnchBenDetails.toString(); - - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(new BigInteger( elements[5].toString()))) - .thenReturn(rmnchBenDetails); - MBeneficiaryaddress beneficiaryaddress1 = new MBeneficiaryaddress(); - beneficiaryaddress1.setCreatedBy(null); - beneficiaryaddress1.toString(); - when(addressRepo.getWithVanSerialNoVanID(any(), any())).thenReturn(beneficiaryaddress1); - when(identityMapper.mBeneficiarymappingToBeneficiariesDTO(any())).thenReturn(dto); - List listOfBenIdentityDTO = new ArrayList<>(); - when(identityMapper.mBeneficiaryidentityListToBenIdentityDTOList(any())).thenReturn(listOfBenIdentityDTO); - Object[] elements2 = new Object[4]; - elements2[0] = 987; - elements2[1] = 1; - elements2[2] = 2; - // elements2[3] = 3; - elements2[3] = Timestamp.valueOf("2011-10-02 18:48:05.123"); - List objArraylist = new ArrayList<>(); - objArraylist.add(elements2); - when(v_BenAdvanceSearchRepo.getBenAbhaDetailsByBenRegID(any())).thenReturn(objArraylist); - - List benDTOList = identityService.getBeneficiaries(searchParams); - Assertions.assertTrue(benDTOList.size() >= 0); - Assertions.assertFalse(benDTOList.size() == 0); - assertNotNull(mBenContactList); - assertNotNull(objArr); - assertNotNull(rmnchBenDetails); - assertNotNull(beneficiaryaddress1); - assertNotNull(objArraylist); - } - - private MBeneficiarycontact makeMBeneficiarycontact() { - MBeneficiarycontact mBeneficiarycontact2 = new MBeneficiarycontact(); - mBeneficiarycontact2.setBenContactsID(null); - mBeneficiarycontact2.setCreatedBy(null); - mBeneficiarycontact2.setCreatedDate(null); - mBeneficiarycontact2.setDeleted(null); - mBeneficiarycontact2.setEmailId(null); - mBeneficiarycontact2.setEmergencyContactNum(null); - mBeneficiarycontact2.setEmergencyContactTyp(null); - mBeneficiarycontact2.setLastModDate(null); - mBeneficiarycontact2.setModifiedBy(null); - mBeneficiarycontact2.setParkingPlaceID(null); - mBeneficiarycontact2.setPhoneNum1(null); - ; - mBeneficiarycontact2.setPhoneNum2(null); - ; - mBeneficiarycontact2.setPhoneNum3(null); - ; - mBeneficiarycontact2.setPhoneNum4(null); - mBeneficiarycontact2.setPhoneNum5(null); - ; - mBeneficiarycontact2.setPhoneTyp1(null); - mBeneficiarycontact2.setPhoneTyp2(null); - mBeneficiarycontact2.setPhoneTyp3(null); - mBeneficiarycontact2.setPhoneTyp4(null); - mBeneficiarycontact2.setPhoneTyp5(null); - mBeneficiarycontact2.setPreferredPhoneNum(null); - mBeneficiarycontact2.setPreferredPhoneTyp(null); - mBeneficiarycontact2.setPreferredSMSPhoneNum(null); - mBeneficiarycontact2.setPreferredSMSPhoneTyp(null); - mBeneficiarycontact2.setProcessed(null); - mBeneficiarycontact2.setReserved(null); - mBeneficiarycontact2.setReservedById(null); - ; - mBeneficiarycontact2.setReservedFor(null); - ; - mBeneficiarycontact2.setReservedOn(null); - ; - mBeneficiarycontact2.setVanID(654); - ; - mBeneficiarycontact2.setVanSerialNo(BigInteger.valueOf(987)); - mBeneficiarycontact2.toString(); - return mBeneficiarycontact2; - - } - - @Test - @Description("Tests the behavior of the \"getBeneficiaries\" function with a null beneficiary ID parameter to ensure correct handling of unspecified IDs.") - void getBeneficiariesBenIDNullTest() throws NoResultException, QueryTimeoutException, Exception { - IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO(); - identitySearchDTO.setBeneficiaryId(new BigInteger("101")); - List benDTOList = identityService.getBeneficiaries(identitySearchDTO); - assertFalse(benDTOList.size() > 0); - } - - @Test - @Description("Tests the functionality of the \"getBeneficiaries\" method using a specific ben reg Id to verify accurate retrieval of beneficiary information.") - void getBeneficiariesBenRegIDTest() throws NoResultException, QueryTimeoutException, Exception { - IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO(); - identitySearchDTO.setBeneficiaryRegId(new BigInteger("201")); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - List familyList = Lists.newArrayList(); - MBeneficiaryfamilymapping familyMapping = new MBeneficiaryfamilymapping(); - familyMapping.setBenFamilyMapId(new BigInteger("808")); - familyList.add(familyMapping); - mBeneficiarymapping.setMBeneficiaryfamilymappings(familyList); - - List identitylist = Lists.newArrayList(); - MBeneficiaryidentity identity = new MBeneficiaryidentity(); - identity.setBenIdentityId(new BigInteger("909")); - identitylist.add(identity); - mBeneficiarymapping.setMBeneficiaryidentities(identitylist); - - - List benDTOList = identityService.getBeneficiaries(identitySearchDTO); - // assertTrue(benDTOList.size() >= 0); - assertFalse(benDTOList.size() > 0); - } - - @Test - @Description("Tests the \"getBeneficiaries\" method with a specified beneficiary contact to validate correct retrieval of beneficiary details associated with the provided contact information.") - void getBeneficiariesBenConTest() throws NoResultException, QueryTimeoutException, Exception { - IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO(); - identitySearchDTO.setContactNumber("605"); - List benDTOList = identityService.getBeneficiaries(identitySearchDTO); - assertFalse(benDTOList.size() > 0); - } - - @Test - @Description("Tests the \"getBeneficiariesByBenId\" method to verify accurate retrieval of beneficiaries based on a specified beneficiary ID.") - void getBeneficiariesByBenIdTest() throws NoResultException, QueryTimeoutException, Exception { - List benMapList = Lists.newArrayList(); - MBeneficiarymapping Mbeneficiary = new MBeneficiarymapping(); - Mbeneficiary.setBenMapId(new BigInteger("101")); - MBeneficiaryregidmapping mapping = new MBeneficiaryregidmapping(); - mapping.setBeneficiaryID(new BigInteger("201")); - Mbeneficiary.setMBeneficiaryregidmapping(mapping); - benMapList.add(Mbeneficiary); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - - List bList = identityService.getBeneficiariesByBenId(Mockito.any(BigInteger.class)); - - assertNotNull(bList); - } - - @Test - void getBeneficiariesByBenIdTest1() throws NoResultException, QueryTimeoutException, Exception { - List benMapList = Lists.newArrayList(); - MBeneficiarymapping Mbeneficiary = new MBeneficiarymapping(); - Mbeneficiary.setBenMapId(new BigInteger("101")); - MBeneficiaryregidmapping mapping = new MBeneficiaryregidmapping(); - mapping.setBeneficiaryID(new BigInteger("201")); - Mbeneficiary.setMBeneficiaryregidmapping(mapping); - benMapList.add(Mbeneficiary); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - - List bList = identityService.getBeneficiariesByBenId(Mockito.any(BigInteger.class)); - - assertFalse(bList.size() > 0); - } - - @Test - @Description("Tests the \"getBeneficiariesByPhoneNum\" method to verify correct retrieval of beneficiaries based on a specified phone number.") - void getBeneficiariesByPhoneNumTest() throws NoResultException, QueryTimeoutException, Exception { - - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenMapId(new BigInteger("201")); - List mappingList = Lists.newArrayList(); - mappingList.add(mBeneficiarymapping); - - // doReturn(mappingList).when(benMappingRepo).findByBeneficiaryDetailsByPhoneNumber(anyObject()); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - - List dtoList = identityService.getBeneficiariesByPhoneNum(Mockito.anyString()); - assertNotNull(dtoList); - } - - @Test - void getBeneficiariesByPhoneNumTest1() throws NoResultException, QueryTimeoutException, Exception { - List dtoList = identityService.getBeneficiariesByPhoneNum(Mockito.anyString()); - assertFalse(dtoList.size() > 0); - } - - @Test - void createIdentityTest() { - IdentityDTO identityDTO = new IdentityDTO(); - identityDTO.setIsPermAddrSameAsCurrAddr(true); - identityDTO.setIsPermAddrSameAsEmerAddr(true); - identityDTO.setIsEmerAddrSameAsCurrAddr(true); - identityDTO.setIsEmerAddrSameAsPermAddr(true); - - IdentityDTO identityDTODup = new IdentityDTO(); - identityDTODup.setIsPermAddrSameAsCurrAddr(true); - identityDTODup.setIsPermAddrSameAsEmerAddr(true); - identityDTODup.setIsEmerAddrSameAsCurrAddr(true); - identityDTODup.setIsEmerAddrSameAsPermAddr(true); - - identityDTO.equals(identityDTODup); - identityDTO.hashCode(); - - MBeneficiaryaddress benaddress = new MBeneficiaryaddress(); - benaddress.setBenAddressID(new BigInteger("101")); - - MBeneficiaryconsent benconsent = new MBeneficiaryconsent(); - benconsent.setBenConsentID(new BigInteger("201")); - - MBeneficiarycontact bencontact = new MBeneficiarycontact(); - bencontact.setBenContactsID(new BigInteger("301")); - - MBeneficiarydetail bendetail = new MBeneficiarydetail(); - bendetail.setBeneficiaryDetailsId(new BigInteger("401")); - - MBeneficiaryregidmapping Benregidmapping = new MBeneficiaryregidmapping(); - - MBeneficiarymapping benMapping = new MBeneficiarymapping(); - benMapping.setBenMapId(new BigInteger("701")); - - MBeneficiaryfamilymapping familymapping = new MBeneficiaryfamilymapping(); - familymapping.setBenFamilyMapId(new BigInteger("501")); - List fmappingList = Lists.newArrayList(); - fmappingList.add(familymapping); - - MBeneficiaryservicemapping servicemapping = new MBeneficiaryservicemapping(); - servicemapping.setBenServiceMapID(new BigInteger("801")); - - List mIdenList = Lists.newArrayList(); - MBeneficiaryidentity mBeneficiaryidentity = new MBeneficiaryidentity(); - mBeneficiaryidentity.setBenIdentityId(new BigInteger("601")); - mIdenList.add(mBeneficiaryidentity); - - List identityList = Lists.newArrayList(); - Identity identity = new Identity(); - identity.setIdentityNo("identity"); - identityList.add(identity); - identityDTO.setIdentities(identityList); - - BeneficiaryCreateResp beneficiaryCreateResp = new BeneficiaryCreateResp(); - beneficiaryCreateResp.setBenId(new BigInteger("102")); - beneficiaryCreateResp.setBenRegId(new BigInteger("105")); - - Assertions.assertThrows(Exception.class, () -> identityService.createIdentity(identityDTO)); - } - - @Test - @Description("Tests the retrieval of partial beneficiary details using a list of beneficiary registration IDs (BenRegIdList) to ensure accurate and efficient data fetching.") - void getBeneficiariesPartialDeatilsByBenRegIdListTest1() { - List BenRegIds = new ArrayList<>(); - BenRegIds.add(BigInteger.valueOf(987)); - List list = new ArrayList<>(); - Object[] elements = new Object[12]; - elements[0] = 987; - elements[1] = ""; - elements[2] = ""; - elements[3] = ""; - elements[4] = 45; - elements[5] = 55; - elements[6] = ""; - elements[7] = ""; - elements[8] = 123; - elements[9] = ""; - elements[10] = ""; - elements[11] = new Timestamp(System.currentTimeMillis()); - list.add(elements); - when(detailRepo.getWith_vanSerialNo_vanID(any(), any())).thenReturn(beneficiarydetail); - when(benRegIdMappingRepo.getWithVanSerialNoVanID(any(), any())).thenReturn(mBeneficiaryregidmapping); - when(mappingRepo.getBenMappingByRegIDList(BenRegIds)).thenReturn(list); - List dtoList = identityService.getBeneficiariesPartialDeatilsByBenRegIdList(BenRegIds); - Assertions.assertTrue(dtoList.size() > 0); - assertNotNull(beneficiarydetail); - assertNotNull(list); - - } - - @Test - @Description("reserveIdentity allocates an identity temporarily, ensuring it remains available until formally assigned or released to prevent conflicts.") - void reserveIdentity() { - ReserveIdentityDTO reserveIdentityDTO = new ReserveIdentityDTO(); - reserveIdentityDTO.setReserveCount(Long.valueOf(4)); - when(benRegIdMappingRepo.countByProviderServiceMapIDAndVehicalNoOrderByBenRegIdAsc( - reserveIdentityDTO.getProviderServiceMapID(), reserveIdentityDTO.getVehicalNo())) - .thenReturn(Long.valueOf(5)); - - MBeneficiaryregidmapping mBeneficiaryregidmapping = new MBeneficiaryregidmapping(); - String res = identityService.reserveIdentity(reserveIdentityDTO); - Assertions.assertTrue(res.equalsIgnoreCase("Successfully Completed")); - } - - @Test - @Description("Tests the functionality of editing an identity to ensure accurate modification of identity information and data integrity.") - void editIdentityTest() throws MissingMandatoryFieldsException { - IdentityEditDTO identityEditDTO = new IdentityEditDTO(); - identityEditDTO.setBeneficaryId(new BigInteger("100")); - identityEditDTO.setBeneficiaryRegId(new BigInteger("200")); - identityEditDTO.setChangeInSelfDetails(true); - identityEditDTO.setChangeInOtherDetails(true); - identityEditDTO.setChangeInAssociations(true); - identityEditDTO.setChangeInAddress(true); - identityEditDTO.setChangeInAddress(true); - identityEditDTO.setChangeInContacts(true); - identityEditDTO.setChangeInIdentities(true); - identityEditDTO.setChangeInFamilyDetails(true); - identityEditDTO.setChangeInBankDetails(true); - identityEditDTO.setChangeInBenImage(true); - identityEditDTO.hashCode(); - MBeneficiarymapping benMapping = new MBeneficiarymapping(); - benMapping.setMBeneficiarydetail(beneficiarydetail); - benMapping.setMBeneficiaryaddress(beneficiaryaddress); - benMapping.setMBeneficiarycontact(mBeneficiarycontact); - MBeneficiaryImage img = new MBeneficiaryImage(); - benMapping.setMBeneficiaryImage(img); - MBeneficiaryAccount mBeneficiaryAccount = new MBeneficiaryAccount(); - benMapping.setMBeneficiaryAccount(mBeneficiaryAccount); - ; - MBeneficiarydetail mbDetl = new MBeneficiarydetail(); - mbDetl.setFamilyId("123"); - mbDetl.setHeadOfFamily_RelationID(456); - mbDetl.setHeadOfFamily_Relation(""); - mbDetl.setOther("other"); - mbDetl.setEmergencyRegistration(true); - - MBeneficiaryaddress mbAddr = new MBeneficiaryaddress(); - MBeneficiarycontact benCon = new MBeneficiarycontact(); - MBeneficiaryidentity mbenIdentity = new MBeneficiaryidentity(); - mbenIdentity.setBenIdentityId(BigInteger.valueOf(987)); - List identities = new ArrayList<>(); - identities.add(mbenIdentity); - List idList = new ArrayList<>(); - MBeneficiaryfamilymapping mbenFamilyMapping = new MBeneficiaryfamilymapping(); - mbenFamilyMapping.setBenFamilyMapId(BigInteger.valueOf(9)); - List fbMaps = new ArrayList<>(); - fbMaps.add(mbenFamilyMapping); - List fmList = new ArrayList<>(); - fmList.add(mbenFamilyMapping); - - MBeneficiaryAccount beneficiaryAccount = new MBeneficiaryAccount(); - when(editMapper.identityEditDTOToMBeneficiaryImage(any(IdentityEditDTO.class))).thenReturn(img); - when(imageRepo.findIdByVanSerialNoAndVanID(any(), any())).thenReturn(BigInteger.valueOf(987)); - when(accountRepo.save(any())).thenReturn(beneficiaryAccount); - when(editMapper.identityEditDTOToMBeneficiaryAccount(any(IdentityEditDTO.class))) - .thenReturn(beneficiaryAccount); - - when(accountRepo.findIdByVanSerialNoAndVanID(any(), any())).thenReturn(BigInteger.valueOf(987)); - - when(familyMapRepo.save(any())).thenReturn(mbenFamilyMapping); - when(editMapper.identityEditDTOListToMBeneficiaryfamilymappingList(any())).thenReturn(fbMaps); - - when(familyMapRepo.findByBenMapIdOrderByBenFamilyMapIdAsc(benMapping.getVanSerialNo())).thenReturn(fmList); - when(identityRepo.findByBenMapId(any())).thenReturn(idList); - when(editMapper.identityEditDTOListToMBeneficiaryidentityList(any())).thenReturn(identities); - when(contactRepo.findIdByVanSerialNoAndVanID(any(), any())).thenReturn(BigInteger.valueOf(987)); - when(editMapper.identityEdiDTOToMBeneficiarycontact(any())).thenReturn(benCon); - when(addressRepo.findIdByVanSerialNoAndVanID(any(), any())).thenReturn(BigInteger.valueOf(987)); - when(editMapper.identityEditDTOToMBeneficiaryaddress(any())).thenReturn(mbAddr); - when(detailRepo.findBenDetailsByVanSerialNoAndVanID(any(), any())).thenReturn(mbDetl); - // when(editMapper.identityEditDTOToMBeneficiarydetail(any())).thenReturn(mbDetl); - when(mappingRepo.findByBenRegIdOrderByBenMapIdAsc(identityEditDTO.getBeneficiaryRegId())) - .thenReturn(benMapping); - identityService.editIdentity(identityEditDTO); - } - - @Test - @Description("Tests the method getBeneficiariesByBenRegId to verify its capability to retrieve beneficiaries based on a specified beneficiary registration ID (BenRegId).") - void getBeneficiariesByBenRegIdTest() throws NoResultException, QueryTimeoutException, Exception { - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenMapId(new BigInteger("201")); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - - List dtoList = identityService.getBeneficiariesByBenRegId(Mockito.any(BigInteger.class)); - assertNotNull(dtoList); - assertFalse(dtoList.size() > 0); - } - - @Test - @Description("Tests the method getBeneficiariesDetailsByBenRegIdList to verify its capability to retrieve detailed beneficiary information using a list of beneficiary registration IDs (BenRegIdList).") - void getBeneficiariesDeatilsByBenRegIdListTest() { - List benRegIds = new ArrayList<>(); - benRegIds.add(BigInteger.valueOf(987)); - List benMapIDList = Lists.newArrayList(); - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenMapId(new BigInteger("201")); - benMapIDList.add(mBeneficiarymapping); - // doReturn(benMapIDList).when(benMappingRepo).findAllByBenRegIdOrderByBenMapIdAsc(Mockito.anyListOf(BigInteger.class)); - - BeneficiariesDTO dto = new BeneficiariesDTO(); - dto.setBenId(new BigInteger("301")); - List dtoList = identityService.getBeneficiariesDeatilsByBenRegIdList(benRegIds); - - } - - @Test - @Description("Tests the createIdentity method to validate its functionality in creating a new identity, ensuring data integrity and correctness of the created identity object.") - void testcreateIdentity() throws IEMRException { - IdentityDTO identityDTO = new IdentityDTO(); - identityDTO.setParkingPlaceId(123); - identityDTO.toString(); - - Identity identity = new Identity(); - - identity.toString(); - List listOfIdentities = new ArrayList<>(); - listOfIdentities.add(identity); - identityDTO.setIdentities(listOfIdentities); - - List fDTOs = new ArrayList<>(); - BenFamilyDTO benFamilyDTO = new BenFamilyDTO(); - benFamilyDTO.setBenFamilyMapId(BigInteger.valueOf(456)); - benFamilyDTO.toString(); - fDTOs.add(benFamilyDTO); - identityDTO.setBenFamilyDTOs(fDTOs); - identityDTO.setIsPermAddrSameAsCurrAddr(true); - identityDTO.setIsPermAddrSameAsEmerAddr(true); - identityDTO.setIsEmerAddrSameAsCurrAddr(true); - identityDTO.setIsEmerAddrSameAsPermAddr(true); - Address address = new Address(); - address.setAddressValue("Home"); - address.setAddrLine1("R1"); - address.setCountry("India"); - address.setCountryId(1); - address.toString(); - identityDTO.setCurrentAddress(address); - identityDTO.setEmergencyAddress(address); - identityDTO.setPermanentAddress(address); - List findTop10000ByProvisionedAndReserved = new ArrayList<>(); - MBeneficiaryregidmapping mBeneficiaryregidmapping2 = new MBeneficiaryregidmapping(); - mBeneficiaryregidmapping2.setBeneficiaryID(BigInteger.valueOf(987)); - findTop10000ByProvisionedAndReserved.add(mBeneficiaryregidmapping2); - when(benRegIdMappingRepo.findTop10000ByProvisionedAndReserved(false, false)) - .thenReturn(findTop10000ByProvisionedAndReserved); - MBeneficiaryaddress mAddr = new MBeneficiaryaddress(); - - MBeneficiaryaddress mAddrequal = new MBeneficiaryaddress(); - mAddr.equals(mAddrequal); - mAddr.hashCode(); - // when(identityMapper.identityDTOToMBeneficiaryaddress(any())).thenReturn(mAddr); - // when(addressRepo.save(mAddr)).thenReturn(mAddr); - - MBeneficiaryconsent beneficiaryconsent = new MBeneficiaryconsent(); - beneficiaryconsent.setBenConsentID(BigInteger.valueOf(987)); - beneficiaryconsent.toString(); - when(identityMapper.identityDTOToDefaultMBeneficiaryconsent(any(), anyBoolean(), anyBoolean())) - .thenReturn(beneficiaryconsent); - when(consentRepo.save(beneficiaryconsent)).thenReturn(beneficiaryconsent); - - MBeneficiarycontact beneficiarycontact = new MBeneficiarycontact(); - beneficiarycontact.hashCode(); - beneficiarycontact.equals(beneficiarycontact); - beneficiarycontact.toString(); - // when(identityMapper.identityDTOToMBeneficiarycontact(any())).thenReturn(beneficiarycontact); - when(contactRepo.save(beneficiarycontact)).thenReturn(beneficiarycontact); - - MBeneficiarydetail mDetl = new MBeneficiarydetail(); - MBeneficiarydetail mDet2 = new MBeneficiarydetail(); - mDetl.equals(mDet2); - mDetl.hashCode(); - mDetl.toString(); - // when(identityMapper.identityDTOToMBeneficiarydetail(any())).thenReturn(mDetl); - when(detailRepo.save(mDetl)).thenReturn(mDetl); - - MBeneficiaryAccount bankOBJ = new MBeneficiaryAccount(); - bankOBJ.toString(); - when(identityMapper.identityDTOToMBeneficiaryAccount(any())).thenReturn(bankOBJ); - when(accountRepo.save(any())).thenReturn(bankOBJ); - - MBeneficiaryImage benImageOBJ = new MBeneficiaryImage(); - benImageOBJ.toString(); - when(identityMapper.identityDTOToMBeneficiaryImage(any())).thenReturn(benImageOBJ); - when(imageRepo.save(any())).thenReturn(benImageOBJ); - - MBeneficiarymapping benMapping = new MBeneficiarymapping(); - MBeneficiarymapping benMappingDuplicate = new MBeneficiarymapping(); - benMapping.equals(benMappingDuplicate); - benMapping.hashCode(); - benMapping.toString(); - when(identityMapper.identityDTOToMBeneficiarymapping(any())).thenReturn(benMapping); - when(mappingRepo.save(any())).thenReturn(benMapping); - - List fIdenList = new ArrayList(); - MBeneficiaryfamilymapping mBeneficiaryfamilymapping = new MBeneficiaryfamilymapping(); - mBeneficiaryfamilymapping.setVanID(123); - mBeneficiaryfamilymapping.toString(); - fIdenList.add(mBeneficiaryfamilymapping); - when(identityMapper.identityDTOListToMBeneficiaryfamilymappingList(any())).thenReturn(fIdenList); - - when(familyMapRepo.saveAll(anyList())).thenReturn(fIdenList); - - MBeneficiaryservicemapping sMap = new MBeneficiaryservicemapping(); - sMap.toString(); - when(identityMapper.identityDTOToMBeneficiaryservicemapping(any())).thenReturn(sMap); - when(serviceMapRepo.save(sMap)).thenReturn(sMap); - - List mIdenList = new ArrayList<>(); - MBeneficiaryidentity mBeneficiaryidentity2 = new MBeneficiaryidentity(); - mBeneficiaryidentity2.toString(); - mIdenList.add(mBeneficiaryidentity2); - when(identityMapper.identityDTOListToMBeneficiaryidentityList(any())).thenReturn(mIdenList); - when(identityRepo.save(any())).thenReturn(mBeneficiaryidentity2); - - BeneficiaryCreateResp resp = new BeneficiaryCreateResp(); - resp.toString(); - resp.setBenId(BigInteger.valueOf(987)); - when(partialMapper.mBeneficiarymappingToBeneficiaryCreateResp(any())).thenReturn(resp); - - BeneficiaryCreateResp createIdentity = identityService.createIdentity(identityDTO); - Assertions.assertNotNull(createIdentity); - - } - - @Test - @Description("Tests the getBeneficiaryByHealthID method to verify accurate retrieval of beneficiary information linked to a health ID in Abha.") - void testgetBeneficiaryByHealthIDAbhaAddress() throws NoResultException, QueryTimeoutException, Exception { - - List list = new ArrayList<>(); - list.add(BigInteger.valueOf(987)); - - List mappinglist = new ArrayList<>(); - List mBeneficiarymappinglist = new ArrayList<>(); - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenAccountID(BigInteger.valueOf(987)); - mBeneficiarymappinglist.add(mBeneficiarymapping); - String mappingJson = new Gson().toJson(mBeneficiarymapping); - mappinglist.add(mappingJson); - List listOdObject = new ArrayList<>(); - MBeneficiarymapping[] benMap = new MBeneficiarymapping[1]; - when(mappingRepo.getBenMappingByRegID(any())).thenReturn(listOdObject); - when(v_BenAdvanceSearchRepo.getBenRegIDByHealthIDAbhaAddress("123")).thenReturn(list); - identityService.getBeneficiaryByHealthIDAbhaAddress("123"); - - } - - @Test - @Description("Tests the getBeneficiaryImage method to verify the accurate retrieval of beneficiary images, validating the functionality of image retrieval and presentation within the application.") - void getBeneficiaryImageTest() throws ParseException { - String req = " {\"beneficiaryRegID\": \"987\"}"; - beneficiarymapping.setBenImageId(BigInteger.valueOf(98)); - beneficiarymapping.setVanID(7); - when(mappingRepo.getBenImageIdByBenRegID(any())).thenReturn(beneficiarymapping); - MBeneficiaryImage image = new MBeneficiaryImage(); - image.setBenBiometric(""); - String resp = identityService.getBeneficiaryImage(req); - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(resp); - String status = (String) json.get("status"); - Assertions.assertEquals("Success", status); - } - - @Test - @Description("Tests the handling of exceptions in the getBeneficiaryImage method, ensuring robust error management when retrieving beneficiary images.") - void getBeneficiaryImageExceptionTest() throws ParseException { - String req = " {\"beneficiaryRegID\": \"987\"}"; - beneficiarymapping.setBenImageId(BigInteger.valueOf(98)); - beneficiarymapping.setVanID(7); - when(mappingRepo.getBenImageIdByBenRegID(any())).thenThrow(NullPointerException.class); - - String resp = identityService.getBeneficiaryImage(req); - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(resp); - Integer status = (Integer) json.get("statusCode"); - Assertions.assertEquals(5005, status); - } - - @Test - @Description("Tests the editIdentityEducationOrCommunity method to verify its functionality in updating education or community-related information within an identity record.") - void editIdentityEducationOrCommunitytest() throws MissingMandatoryFieldsException { - IdentityEditDTO identity = new IdentityEditDTO(); - identity.setCommunityId(4); - identity.setEducationId(3); - identity.setBeneficiaryRegId(BigInteger.valueOf(98)); - - MBeneficiarymapping benmapping = new MBeneficiarymapping(); - benmapping.setBenDetailsId(BigInteger.valueOf(987)); - benmapping.setVanID(5); - when(mappingRepo.findByBenRegIdOrderByBenMapIdAsc(identity.getBeneficiaryRegId())).thenReturn(benmapping); - identityService.editIdentityEducationOrCommunity(identity); - Assertions.assertNotNull(benmapping); - } - - @Test - @Description("Tests the functionality of importing beneficiary IDs to a local server, ensuring successful transfer and integration of beneficiary data for local processing or storage.") - void testimportBenIdToLocalServer() { - List benIdImportDTOList = new ArrayList<>(); - BenIdImportDTO benIdImportDTO = new BenIdImportDTO(); - benIdImportDTOList.add(benIdImportDTO); - ArrayList list = new ArrayList<>(); - MBeneficiaryregidmapping mBeneficiaryregidmapping = new MBeneficiaryregidmapping(); - mBeneficiaryregidmapping.setBeneficiaryID(BigInteger.valueOf(987)); - list.add(mBeneficiaryregidmapping); - when(benIdImportMapper.benIdImportDTOToMBeneficiaryregidmappings(any())).thenReturn(list); - int[] intArray = new int[2]; - intArray[0] = 1; - intArray[1] = 2; - // when(jdbcTemplate.batchUpdate(any(), anyList())).thenReturn(intArray ); -// Assertions.assertThrows(CannotGetJdbcConnectionException.class, -// () -> identityService.importBenIdToLocalServer(benIdImportDTOList)); - int importBenIdToLocalServer = identityService.importBenIdToLocalServer(benIdImportDTOList); - assertTrue(importBenIdToLocalServer > 0); - } - - @Test - @Description("Tests the searchBeneficiaryByFamilyId method to ensure accurate retrieval of beneficiaries based on a family ID parameter.") - void testsearhBeneficiaryByFamilyId() { - String familyId = "2"; - List benDetailsList = new ArrayList<>(); - MBeneficiarydetail mBeneficiarydetail = new MBeneficiarydetail(); - mBeneficiarydetail.setVanSerialNo(BigInteger.valueOf(9l)); - mBeneficiarydetail.setVanID(1); - benDetailsList.add(mBeneficiarydetail); - - Object[] elements = new Object[4]; - elements[0] = 987; - elements[1] = 1; - elements[2] = 2; - elements[3] = new Timestamp(System.currentTimeMillis()); - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - when(mappingRepo.getBenMappingByBenDetailsIds(any(), any())).thenReturn(null); - when(detailRepo.searchByFamilyId(familyId)).thenReturn(benDetailsList); - List searhBeneficiaryByFamilyId = identityService.searhBeneficiaryByFamilyId(familyId); - - Assertions.assertTrue(searhBeneficiaryByFamilyId.isEmpty()); - } - - @Test - @Description("Tests the searchBeneficiaryByGovIdentity method to ensure accurate retrieval of beneficiaries based on a government-issued identity parameter.") - void testsearhBeneficiaryByGovIdentity() { - String govtID = "govtID"; - List benIdentityList = new ArrayList<>(); - MBeneficiaryidentity mBeneficiaryidentity2 = new MBeneficiaryidentity(); - benIdentityList.add(mBeneficiaryidentity2); - when(identityRepo.searchByIdentityNo(govtID)).thenReturn(benIdentityList); - - Object[] elements = new Object[4]; - elements[0] = 987; - elements[1] = 1; - elements[2] = 2; - elements[3] = new Timestamp(System.currentTimeMillis()); - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - when(mappingRepo.getBenMappingByVanSerialNo(any(), any())).thenReturn(objArraylist); - List searhBeneficiaryByGovIdentity = identityService.searhBeneficiaryByGovIdentity(govtID); - Assertions.assertTrue(searhBeneficiaryByGovIdentity.isEmpty()); - } - - @Test - @Description("Tests the countBeneficiaryByVillageIdAndLastModifyDate method to verify its accuracy in counting beneficiaries based on a specified village ID and last modification date.") - void testcountBeneficiaryByVillageIdAndLastModifyDate() { - - List villageIDs = new ArrayList<>(); - Timestamp lastModifiedDate = new Timestamp(System.currentTimeMillis()); - when(mappingRepo.getBeneficiaryCountsByVillageIDAndLastModifyDate(any(), any())).thenReturn(9l); - Long resp = identityService.countBeneficiaryByVillageIdAndLastModifyDate(villageIDs, lastModifiedDate); - Assertions.assertEquals(9l, resp); - } -} diff --git a/src/test/java/com/iemr/common/identity/service/familyTagging/FamilyTagServiceImplTest.java b/src/test/java/com/iemr/common/identity/service/familyTagging/FamilyTagServiceImplTest.java deleted file mode 100644 index 80ee2b0..0000000 --- a/src/test/java/com/iemr/common/identity/service/familyTagging/FamilyTagServiceImplTest.java +++ /dev/null @@ -1,537 +0,0 @@ -package com.iemr.common.identity.service.familyTagging; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.api.function.Executable; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.annotation.Description; - -import com.google.gson.Gson; -import com.iemr.common.identity.data.familyTagging.BenFamilyMapping; -import com.iemr.common.identity.domain.MBeneficiarydetail; -import com.iemr.common.identity.domain.MBeneficiarymapping; -import com.iemr.common.identity.exception.IEMRException; -import com.iemr.common.identity.repo.BenDetailRepo; -import com.iemr.common.identity.repo.BenMappingRepo; -import com.iemr.common.identity.repo.familyTag.FamilyTagRepo; - -@ExtendWith(MockitoExtension.class) -class FamilyTagServiceImplTest { - - @InjectMocks - private FamilyTagServiceImpl familyTagServiceImpl; - - @Mock - private BenMappingRepo benMappingRepo; - @Mock - private BenDetailRepo benDetailRepo; - @Mock - private FamilyTagRepo familyTagRepo; - - @Test - @Description("Verifies successful addition of a family tag.") - void testAddTag_Success() throws IEMRException { - // Test Case ID: TC_ADD_TAG_001 - - // Mocking input data - BenFamilyMapping requestObj = new BenFamilyMapping(); - requestObj.setBeneficiaryRegId(1234456L); - requestObj.setIsHeadOfTheFamily(true); - requestObj.setFamilyId("FAM001"); // Unique family ID - requestObj.setModifiedBy("admin"); - requestObj.setMemberName("John Doe"); // Example member name - String request = new Gson().toJson(requestObj); - - MBeneficiarymapping mapping = new MBeneficiarymapping(); - mapping.setBenMapId(BigInteger.valueOf(123)); - mapping.setBenDetailsId(BigInteger.valueOf(456)); - mapping.setVanID(98); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(requestObj.getBeneficiaryRegId()))).thenReturn(mapping); - - // Mocking repository behavior for update and search operations - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(requestObj.getFamilyId()); - benFamilyMapping.setNoOfmembers(4); - when(familyTagRepo.searchFamilyByFamilyId(requestObj.getFamilyId())).thenReturn(benFamilyMapping); - - // Executing the service method - String resp = familyTagServiceImpl.addTag(request); - - // Verify behavior and assert results - Assertions.assertEquals("Family tagging completed successfully", resp); - - // Verify that save method was called on familyTagRepo - verify(familyTagRepo, times(1)).save(any(BenFamilyMapping.class)); - - // Additional assertions to validate specific updates - Assertions.assertEquals(5, benFamilyMapping.getNoOfmembers()); // Expected incremented members count - Assertions.assertEquals("John Doe", benFamilyMapping.getFamilyHeadName()); // Expected family head name - } - - @Test - @Description("Verifies handling of scenario where beneficiary is not found during family tagging.") - void testAddTag_BeneficiaryNotFound() { - // Test Case ID: TC_ADD_TAG_002 - - // Mocking input data - BenFamilyMapping requestObj = new BenFamilyMapping(); - requestObj.setBeneficiaryRegId(9999999L); // Non-existent beneficiary ID - String request = new Gson().toJson(requestObj); - - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(requestObj.getBeneficiaryRegId()))).thenReturn(null); - - // Executing the service method and expecting an exception - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.addTag(request), - "Beneficiary is not found while doing family tagging. Please contact the administrator"); - } - - @Test - @Description("Verifies handling of scenario where an invalid family ID is encountered during family tagging.") - void testAddTag_InvalidFamilyId() { - // Test Case ID: TC_ADD_TAG_003 - - // Mocking input data - BenFamilyMapping requestObj = new BenFamilyMapping(); - requestObj.setBeneficiaryRegId(1234456L); - requestObj.setIsHeadOfTheFamily(true); - requestObj.setFamilyId("InvalidFamilyID"); // Invalid family ID - String request = new Gson().toJson(requestObj); - - MBeneficiarymapping mapping = new MBeneficiarymapping(); - mapping.setBenMapId(BigInteger.valueOf(123)); - mapping.setBenDetailsId(BigInteger.valueOf(456)); - mapping.setVanID(98); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(requestObj.getBeneficiaryRegId()))).thenReturn(mapping); - - // Mocking repository behavior for update and search operations - when(familyTagRepo.searchFamilyByFamilyId(requestObj.getFamilyId())).thenReturn(null); - - // Executing the service method and expecting an exception - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.addTag(request), - "Invalid family ID while searching family"); - } - - @Test - @Description("Test case to verify the functionality of untagging a family member from a document.") - void testDoFamilyUntag_Success() throws IEMRException, JSONException { - // Test Case ID: TC_DO_FAMILY_UNTAG_001 - - // Mocking input JSON request - JSONObject benFamilymap = new JSONObject(); - benFamilymap.put("benFamilyTagId", Long.valueOf(123)); - benFamilymap.put("beneficiaryRegId", Long.valueOf(456)); - benFamilymap.put("familyId", "789"); // String type for familyId - benFamilymap.put("isHeadOfTheFamily", true); - JSONArray memberList = new JSONArray(); - memberList.put(benFamilymap); - JSONObject requestJson = new JSONObject(); - requestJson.put("memberList", memberList); - String request = requestJson.toString(); - - // Mocking repository responses - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenDetailsId(BigInteger.valueOf(456)); - mBeneficiarymapping.setVanID(98); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(456))).thenReturn(mBeneficiarymapping); - - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId("789"); - benFamilyMapping.setNoOfmembers(4); - when(familyTagRepo.searchFamilyByFamilyId("789")).thenReturn(benFamilyMapping); - - // Executing the service method - String resp = familyTagServiceImpl.doFamilyUntag(request); - - // Verify behavior and assert results - Assertions.assertEquals("Beneficiary untagged successfully", resp); - - verify(familyTagRepo, times(1)).save(any(BenFamilyMapping.class)); - } - - @Test - @Description("Test case to verify the handling of an invalid member list in the request during family member untagging.") - void testDoFamilyUntag_InvalidMemberList() throws JSONException { - // Test Case ID: TC_DO_FAMILY_UNTAG_002 - - // Mocking input JSON request with missing memberList - JSONObject requestJson = new JSONObject(); - requestJson.put("invalidKey", "value"); // No memberList key - String request = requestJson.toString(); - - // Executing the service method and expecting an exception - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.doFamilyUntag(request), - "Invalid request. Member-list is NULL"); - } - - @Test - @Description("Test case to verify the handling of an invalid family ID during family member untagging.") - void testDoFamilyUntag_InvalidFamilyId() throws JSONException { - // Test Case ID: TC_DO_FAMILY_UNTAG_003 - - // Mocking input JSON request with invalid familyId - JSONObject benFamilymap = new JSONObject(); - benFamilymap.put("benFamilyTagId", Long.valueOf(123)); - benFamilymap.put("beneficiaryRegId", Long.valueOf(456)); - benFamilymap.put("familyId", "InvalidFamilyID"); // Invalid familyId - benFamilymap.put("isHeadOfTheFamily", true); - JSONArray memberList = new JSONArray(); - memberList.put(benFamilymap); - JSONObject requestJson = new JSONObject(); - requestJson.put("memberList", memberList); - String request = requestJson.toString(); - - // Mocking repository responses - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenDetailsId(BigInteger.valueOf(456)); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(456))).thenReturn(mBeneficiarymapping); - - when(familyTagRepo.searchFamilyByFamilyId("InvalidFamilyID")).thenReturn(null); - - // Executing the service method and expecting an exception - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.doFamilyUntag(request), - "Invalid family ID while searching family"); - } - - @Test - @Description("Test case to verify the handling of an invalid or null family ID during family member untagging.") - void testDoFamilyUntag_InvalidFamilyIdOrNull() throws JSONException { - // Test Case ID: TC_DO_FAMILY_UNTAG_004 - - // Mocking input JSON request with invalid familyId or null - JSONObject benFamilymap = new JSONObject(); - benFamilymap.put("benFamilyTagId", 123); - benFamilymap.put("beneficiaryRegId", 456); - benFamilymap.put("familyId", JSONObject.NULL); // Setting familyId to null - benFamilymap.put("isHeadOfTheFamily", true); - - JSONArray memberList = new JSONArray(); - memberList.put(benFamilymap); - - JSONObject requestJson = new JSONObject(); - requestJson.put("memberList", memberList); - - String request = requestJson.toString(); - - // Mocking repository responses - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenDetailsId(BigInteger.valueOf(456)); - - // Mocking Gson conversion - Gson gsonMock = mock(Gson.class); - BenFamilyMapping[] benFamilyMappings = new BenFamilyMapping[1]; - benFamilyMappings[0] = new BenFamilyMapping(); - - // Executing the service method and expecting an exception - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.doFamilyUntag(request), - "Invalid family ID / NULL"); - - // Verify interactions - verify(benDetailRepo, never()).untagFamily(Mockito.anyString(), any(BigInteger.class), Mockito.anyInt()); // Ensure - // untagFamily() - // is - // never - // called - verify(familyTagRepo, never()).searchFamilyByFamilyId(Mockito.anyString()); // Ensure searchFamilyByFamilyId() - // is never called - } - - @Test - @Description("Verify exception handling when editing family member details with null request") - void testEditFamilyDetailsCatchblock() { - // Test Case ID: TC_Edit_Family_Details_001 - // Arrange - String nullRequest = null; - - // Act + Assert - IEMRException exception = Assertions.assertThrows(IEMRException.class, - () -> familyTagServiceImpl.editFamilyDetails(nullRequest)); - Assertions.assertTrue(exception.getMessage().contains("Error while editing family tagging details")); - } - - @Test - @Description("Verify successful editing of family member details") - void testEditFamilyDetails() throws IEMRException { - // Test Case ID: TC_Edit_Family_Details_002 - // Arrange - String familyId = "123"; - String memberName = "memberName"; - BenFamilyMapping benFamilyMapping = createBenFamilyMapping(familyId, true, memberName); - - String jsonRequest = new Gson().toJson(benFamilyMapping); - - when(familyTagRepo.searchFamilyByFamilyId(familyId)).thenReturn(benFamilyMapping); - MBeneficiarymapping mBeneficiaryMapping = createMBeneficiaryMapping(benFamilyMapping.getBeneficiaryRegId()); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))) - .thenReturn(mBeneficiaryMapping); - - // Act - String result = familyTagServiceImpl.editFamilyDetails(jsonRequest); - - // Assert - Assertions.assertEquals("Beneficiary family tagging updateed successfully", result); - Assertions.assertEquals(memberName, benFamilyMapping.getFamilyHeadName()); - } - - @Test - @Description("Verify behavior when BenFamilyMapping is null") - void testEditFamilyDetails_If_BenFamilyMapping_Null() { - // Test Case ID: TC_Edit_Family_Details_003 - // Arrange - String familyId = "123"; - BenFamilyMapping benFamilyMapping = createBenFamilyMapping(familyId, true, "memberName"); - - String jsonRequest = new Gson().toJson(benFamilyMapping); - - when(familyTagRepo.searchFamilyByFamilyId(familyId)).thenReturn(null); - - // Act + Assert - IEMRException exception = Assertions.assertThrows(IEMRException.class, - () -> familyTagServiceImpl.editFamilyDetails(jsonRequest)); - Assertions.assertTrue(exception.getMessage().contains("Invalid Family ID")); - } - - @Test - @Description("Verify behavior when MBeneficiarymapping is null") - void testEditFamilyDetailsIfMBeneficiarymappingNull() { - // Test Case ID: TC_Edit_Family_Details_004 - // Arrange - String familyId = "123"; - BenFamilyMapping benFamilyMapping = createBenFamilyMapping(familyId, true, "memberName"); - - String jsonRequest = new Gson().toJson(benFamilyMapping); - - when(familyTagRepo.searchFamilyByFamilyId(familyId)).thenReturn(benFamilyMapping); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))) - .thenReturn(null); - - // Act + Assert - IEMRException exception = Assertions.assertThrows(IEMRException.class, - () -> familyTagServiceImpl.editFamilyDetails(jsonRequest)); - Assertions.assertTrue(exception.getMessage().contains("Error in getting beneficiary details")); - } - - private BenFamilyMapping createBenFamilyMapping(String familyId, boolean isHead, String memberName) { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(familyId); - benFamilyMapping.setIsHeadOfTheFamily(isHead); - benFamilyMapping.setMemberName(memberName); - benFamilyMapping.setFamilyHeadName("familyHeadName"); // Assuming this is set in the service method - benFamilyMapping.setBeneficiaryRegId(123L); // Sample value, adjust as per your needs - return benFamilyMapping; - } - - private MBeneficiarymapping createMBeneficiaryMapping(long beneficiaryRegId) { - MBeneficiarymapping mBeneficiaryMapping = new MBeneficiarymapping(); - mBeneficiaryMapping.setBenDetailsId(BigInteger.valueOf(986)); - mBeneficiaryMapping.setVanID(123); - return mBeneficiaryMapping; - } - - @Test - @Description("Test Case for Exception Handling in Family Search (TC_Search_Family_Details_001)") - void testSearchFamilyCatchblock() throws IEMRException { - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.searchFamily(null)); - } - - @Test - @Description("Test Case for Family Search Functionality (TC_Search_Family_Details_002)") - void testSearchFamily() throws IEMRException { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId("123"); - benFamilyMapping.setIsHeadOfTheFamily(true); - benFamilyMapping.setMemberName("memberName"); - benFamilyMapping.setFamilyHeadName("familyHeadName"); - String json = new Gson().toJson(benFamilyMapping); - List list = new ArrayList<>(); - list.add(benFamilyMapping); - when(familyTagRepo.searchFamilyWithFamilyId(benFamilyMapping.getFamilyName(), benFamilyMapping.getVillageId(), - benFamilyMapping.getFamilyId())).thenReturn(list); - Assertions.assertNotNull(familyTagServiceImpl.searchFamily(json)); - } - - @Test - @Description("Test Case for Handling Null FamilyID in Family Search (TC_Search_Family_Details_003)") - void testSearchFamily_If_FamilyID_NULL() throws IEMRException { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(null); - benFamilyMapping.setIsHeadOfTheFamily(true); - benFamilyMapping.setMemberName("memberName"); - benFamilyMapping.setFamilyHeadName("familyHeadName"); - String json = new Gson().toJson(benFamilyMapping); - List list = new ArrayList<>(); - list.add(benFamilyMapping); - when(familyTagRepo.searchFamily(benFamilyMapping.getFamilyName(), benFamilyMapping.getVillageId())) - .thenReturn(list); - Assertions.assertNotNull(familyTagServiceImpl.searchFamily(json)); - } - - @Test - @Description("Test Case for Handling Null RESP Parameter in Family Search (TC_Search_Family_Details_004)") - void testSearchFamily_If_RESP_NULL() throws IEMRException { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(null); - benFamilyMapping.setIsHeadOfTheFamily(true); - benFamilyMapping.setMemberName("memberName"); - benFamilyMapping.setFamilyHeadName("familyHeadName"); - String json = new Gson().toJson(benFamilyMapping); - - when(familyTagRepo.searchFamily(benFamilyMapping.getFamilyName(), benFamilyMapping.getVillageId())) - .thenReturn(null); - Assertions.assertNotNull(familyTagServiceImpl.searchFamily(json)); - } - - @Test - @Description("Test Case for exception handling in createFamily method") - void testCreateFamilyCatchBlock() throws IEMRException { - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.createFamily(null)); - } - - @Test - @Description("Test Case for handling null family tagged ID in createFamily method") - void testCreateFamilyFamilyTaggedIDNull() throws IEMRException { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(null); - benFamilyMapping.setIsHeadOfTheFamily(true); - benFamilyMapping.setMemberName("memberName"); - benFamilyMapping.setFamilyHeadName("familyHeadName"); - benFamilyMapping.setCreatedBy("Admin"); - benFamilyMapping.setBeneficiaryRegId(Long.valueOf(1234)); - String json = new Gson().toJson(benFamilyMapping); - - when(familyTagRepo.getUserId("Admin")).thenReturn(123); - when(familyTagRepo.save(any())).thenReturn(benFamilyMapping); - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenDetailsId(BigInteger.valueOf(987)); - mBeneficiarymapping.setVanID(765); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))) - .thenReturn(mBeneficiarymapping); - - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.createFamily(json)); - } - - @Test - @Description("Test Case for creating a family in the system") - void testCreateFamily() throws IEMRException { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(null); - benFamilyMapping.setIsHeadOfTheFamily(true); - benFamilyMapping.setMemberName("memberName"); - benFamilyMapping.setFamilyHeadName("familyHeadName"); - benFamilyMapping.setCreatedBy("Admin"); - benFamilyMapping.setBeneficiaryRegId(Long.valueOf(1234)); - benFamilyMapping.setBenFamilyTagId(Long.valueOf(987)); - String json = new Gson().toJson(benFamilyMapping); - - when(familyTagRepo.getUserId("Admin")).thenReturn(123); - when(familyTagRepo.save(any())).thenReturn(benFamilyMapping); - MBeneficiarymapping mBeneficiarymapping = new MBeneficiarymapping(); - mBeneficiarymapping.setBenDetailsId(BigInteger.valueOf(987)); - mBeneficiarymapping.setVanID(765); - when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))) - .thenReturn(mBeneficiarymapping); - - String resp = familyTagServiceImpl.createFamily(json); - Assertions.assertNotNull(resp); - } - - @Test - @Description("Positive scenario for retrieving a family ID (TC_GET_FAMILY_ID_001)") - void testGetFamilyId_validUsername() throws IEMRException { - // Given - String username = "validUsername"; - - // When - String familyId = familyTagServiceImpl.getFamilyId(username); - - // Then - Assertions.assertNotNull(familyId, "Family ID should not be null"); - Assertions.assertEquals(16, familyId.length(), "Family ID should be 16 characters long"); - Assertions.assertTrue(familyId.matches("\\d{13}\\d{3}"), "Family ID format should be timestamp + userId"); - } - - @Test - @Description("Exception handling scenario (TC_GET_FAMILY_ID_002)") - void testGetFamilyId_exceptionHandling() { - // Given - String username = "testUser"; - Mockito.when(familyTagRepo.getUserId(username)).thenThrow(new RuntimeException("Simulated Repository Exception")); - - // When & Then - IEMRException exception = Assertions.assertThrows(IEMRException.class, () -> { - familyTagServiceImpl.getFamilyId(username); - }); - - // Assert the exception message contains the expected substring - Assertions.assertTrue(exception.getMessage().contains("Simulated Repository Exception")); - } - - @Test - @Description("Test Case for handling invalid username in getFamilyId (TC_GET_FAMILY_ID_003)") - void testGetFamilyId_invalidUsername() { - // Arrange (Given) - String username = "invalidUsername"; - Mockito.when(familyTagRepo.getUserId(username)).thenReturn(null); // Simulate user not found - - // Act (When) - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.getFamilyId(username)); - } - - - @Test - @Description("Test Case for exception handling in getFamilyDetails method") - void testGetFamilyDetailsCatchBlock() throws IEMRException { - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.getFamilyDetails(null)); - } - - @Test - @Description("Test Case for retrieving family details") - void testGetFamilyDetails() throws IEMRException { - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(null); - benFamilyMapping.setFamilyId("123"); - benFamilyMapping.setIsHeadOfTheFamily(true); - benFamilyMapping.setMemberName("memberName"); - benFamilyMapping.setFamilyHeadName("familyHeadName"); - benFamilyMapping.setCreatedBy("Admin"); - benFamilyMapping.setBeneficiaryRegId(Long.valueOf(1234)); - String json = new Gson().toJson(benFamilyMapping); - - List list = new ArrayList<>(); - MBeneficiarydetail mBeneficiarydetail = new MBeneficiarydetail(); - mBeneficiarydetail.setOther("other"); - list.add(mBeneficiarydetail); - when(benMappingRepo.getBenRegId(any(), any())).thenReturn(BigInteger.valueOf(987)); - when(benDetailRepo.getFamilyDetails(any())).thenReturn(list); - String resp = familyTagServiceImpl.getFamilyDetails(json); - Assertions.assertNotNull(resp); - } - - @Test - @Description("Test Case for exception handling in getFamilyDetails when familyId is null") - void testGetFamilyDetailsEmptyFamilyId() { - // Arrange - BenFamilyMapping benFamilyMapping = new BenFamilyMapping(); - benFamilyMapping.setFamilyId(null); // Set familyId to null - - // Act and Assert - Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.getFamilyDetails(new Gson().toJson(benFamilyMapping))); - } -} diff --git a/src/test/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImplTest.java b/src/test/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImplTest.java deleted file mode 100644 index 021f3d9..0000000 --- a/src/test/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImplTest.java +++ /dev/null @@ -1,907 +0,0 @@ -package com.iemr.common.identity.service.rmnch; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.when; - -import java.math.BigInteger; -import java.sql.Timestamp; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.annotation.Description; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.test.util.ReflectionTestUtils; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.iemr.common.identity.data.rmnch.GetBenRequestHandler; -import com.iemr.common.identity.data.rmnch.RMNCHBeneficiaryDetailsRmnch; -import com.iemr.common.identity.data.rmnch.RMNCHBornBirthDetails; -import com.iemr.common.identity.data.rmnch.RMNCHCBACdetails; -import com.iemr.common.identity.data.rmnch.RMNCHHouseHoldDetails; -import com.iemr.common.identity.data.rmnch.RMNCHMBeneficiaryAccount; -import com.iemr.common.identity.data.rmnch.RMNCHMBeneficiaryImage; -import com.iemr.common.identity.data.rmnch.RMNCHMBeneficiaryaddress; -import com.iemr.common.identity.data.rmnch.RMNCHMBeneficiarycontact; -import com.iemr.common.identity.data.rmnch.RMNCHMBeneficiarydetail; -import com.iemr.common.identity.data.rmnch.RMNCHMBeneficiarymapping; -import com.iemr.common.identity.repo.rmnch.RMNCHBenAccountRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBenAddressRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBenContactRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBenDetailsRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBenImageRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBeneficiaryDetailsRmnchRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHBornBirthDetailsRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHCBACDetailsRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHHouseHoldDetailsRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHMBenMappingRepo; -import com.iemr.common.identity.repo.rmnch.RMNCHMBenRegIdMapRepo; - -import net.minidev.json.JSONObject; -import net.minidev.json.parser.JSONParser; -import net.minidev.json.parser.ParseException; - -@ExtendWith(MockitoExtension.class) -class RmnchDataSyncServiceImplTest { - @InjectMocks - RmnchDataSyncServiceImpl rmnchDataSyncServiceImpl; - - @Mock - private RMNCHBeneficiaryDetailsRmnchRepo rMNCHBeneficiaryDetailsRmnchRepo; - @Mock - private RMNCHBornBirthDetailsRepo rMNCHBornBirthDetailsRepo; - @Mock - private RMNCHCBACDetailsRepo rMNCHCBACDetailsRepo; - @Mock - private RMNCHHouseHoldDetailsRepo rMNCHHouseHoldDetailsRepo; - - @Mock - private RMNCHBenAddressRepo rMNCHBenAddressRepo; - @Mock - private RMNCHMBenMappingRepo rMNCHMBenMappingRepo; - @Mock - private RMNCHBenDetailsRepo rMNCHBenDetailsRepo; - @Mock - private RMNCHBenAccountRepo rMNCHBenAccountRepo; - @Mock - private RMNCHBenImageRepo rMNCHBenImageRepo; - @Mock - private RMNCHBenContactRepo rMNCHBenContactRepo; - @Mock - private RMNCHMBenRegIdMapRepo rMNCHMBenRegIdMapRepo; - @Mock - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ2; - - @Test - @Description("Test Case for syncing data to amrit (TC_SYNC_DATA_001)") - void testSyncDataToAmrit() throws Exception { - RMNCHBeneficiaryDetailsRmnch rMNCHBeneficiaryDetailsRmnch = new RMNCHBeneficiaryDetailsRmnch(); - RMNCHBeneficiaryDetailsRmnch rMNCHBeneficiaryDetailsRmnch2 = new RMNCHBeneficiaryDetailsRmnch(); - - Long[] ids = { Long.valueOf(123), Long.valueOf(456) }; - rMNCHBeneficiaryDetailsRmnch.setRelatedBeneficiaryIds(ids); - rMNCHBeneficiaryDetailsRmnch.hashCode(); - - rMNCHBeneficiaryDetailsRmnch2.setRelatedBeneficiaryIds(ids); - rMNCHBeneficiaryDetailsRmnch.equals(rMNCHBeneficiaryDetailsRmnch2); - rMNCHBeneficiaryDetailsRmnch.toString(); - String json = new Gson().toJson(rMNCHBeneficiaryDetailsRmnch); - - JSONObject jsonObject = new JSONObject(); - - List list = new ArrayList<>(); - list.add(json); - char s = '"'; - String t = s + "["; - String r = "]" + s; - jsonObject.put("beneficiaryDetails", list); - - List birthlist = new ArrayList<>(); - List rMNCHBornBirthDetailslist = new ArrayList<>(); - RMNCHBornBirthDetails rMNCHBornBirthDetails = new RMNCHBornBirthDetails(); - RMNCHBornBirthDetails rMNCHBornBirthDetails2 = new RMNCHBornBirthDetails(); - - rMNCHBornBirthDetails.hashCode(); - rMNCHBornBirthDetails.equals(rMNCHBornBirthDetails2); - rMNCHBornBirthDetails.toString(); - rMNCHBornBirthDetailslist.add(rMNCHBornBirthDetails); - String birthJson = new Gson().toJson(rMNCHBornBirthDetails); - birthlist.add(birthJson); - jsonObject.put("bornBirthDeatils", birthlist); - - List cbaclist = new ArrayList<>(); - List rMNCHCBACdetailslist = new ArrayList<>(); - RMNCHCBACdetails rMNCHCBACdetails = new RMNCHCBACdetails(); - rMNCHCBACdetails.setBenficieryid(BigInteger.valueOf(987)); - rMNCHCBACdetails.hashCode(); - rMNCHCBACdetails.equals(rMNCHCBACdetails); - rMNCHCBACdetails.toString(); - - rMNCHCBACdetailslist.add(rMNCHCBACdetails); - cbaclist.add(birthJson); - jsonObject.put("cBACDetails", cbaclist); - - List householdlist = new ArrayList<>(); - List rMNCHHouseHoldDetailslist = new ArrayList<>(); - RMNCHHouseHoldDetails rMNCHHouseHoldDetails = new RMNCHHouseHoldDetails(); - rMNCHHouseHoldDetails.setHouseoldId(Long.valueOf(987)); - rMNCHHouseHoldDetails.hashCode(); - - RMNCHHouseHoldDetails rMNCHHouseHoldDetails2 = new RMNCHHouseHoldDetails(); - rMNCHHouseHoldDetails2.setHouseoldId(Long.valueOf(987)); - - rMNCHHouseHoldDetails.equals(rMNCHHouseHoldDetails2); - rMNCHHouseHoldDetails.toString(); - rMNCHHouseHoldDetailslist.add(rMNCHHouseHoldDetails); - String householdJson = new Gson().toJson(rMNCHHouseHoldDetails); - householdlist.add(householdJson); - jsonObject.put("houseHoldDetails", householdlist); - - String json1 = jsonObject.toString(); - - String json2 = "{\"cBACDetails\":[{\"Processed\":\"N\"}],\"bornBirthDeatils\":[{\"Processed\":\"N\"}],\"houseHoldDetails\":[{\"houseoldId\":987,\"Processed\":\"N\"}],\"beneficiaryDetails\":[{\"Processed\":\"N\",\"relatedBeneficiaryIds\":[123,456]}]}"; - // String replace = json1.replace(t, "[").replace(r, "]"); - String replace2 = json2.replace("\\", ""); - - when(rMNCHHouseHoldDetailsRepo.saveAll(anyList())).thenReturn(rMNCHHouseHoldDetailslist); - when(rMNCHHouseHoldDetailsRepo.getByHouseHoldID(Long.valueOf(987))).thenReturn(rMNCHHouseHoldDetails); - when(rMNCHCBACDetailsRepo.saveAll(anyList())).thenReturn(rMNCHCBACdetailslist); - when(rMNCHCBACDetailsRepo.getByRegID(any())).thenReturn(rMNCHCBACdetails); - when(rMNCHMBenRegIdMapRepo.getRegID(any())).thenReturn(BigInteger.valueOf(987)); - when(rMNCHBornBirthDetailsRepo.saveAll(anyList())).thenReturn(rMNCHBornBirthDetailslist); - when(rMNCHBornBirthDetailsRepo.getByRegID(any())).thenReturn(rMNCHBornBirthDetails); - when(rMNCHMBenRegIdMapRepo.getRegID(any())).thenReturn(BigInteger.valueOf(987)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(any())).thenReturn(rMNCHBeneficiaryDetailsRmnch); - when(rMNCHMBenRegIdMapRepo.getRegID(any())).thenReturn(BigInteger.valueOf(987)); - RMNCHMBeneficiarydetail rmnchBenDetails = new RMNCHMBeneficiarydetail(); - when(rMNCHBenDetailsRepo.getByBenRegID(any())).thenReturn(rmnchBenDetails); - - String syncDataToAmrit = rmnchDataSyncServiceImpl.syncDataToAmrit(replace2); - Assertions.assertNotNull(syncDataToAmrit); - } - - @Test - @Description("Test Case for handling empty request object (TC_SYNC_DATA_002)") - void testSyncDataToAmrit_emptyRequest() { - // Arrange (Given) - String requestOBJ = null; - - // Act (When) - Assertions.assertThrows(Exception.class, () -> rmnchDataSyncServiceImpl.syncDataToAmrit(requestOBJ)); - } - - @Test - @Description("Test Case for handling empty beneficiary request data (TC_SYNC_DATA_003)") - void testSyncDataToAmrit_emptyBeneficiaryDetails() throws Exception { - // Arrange (Given) - JsonObject jsnOBJ = new JsonObject(); - String requestOBJ = new Gson().toJson(jsnOBJ); - - // Act (When) - Assertions.assertThrows(Exception.class, () -> rmnchDataSyncServiceImpl.syncDataToAmrit(requestOBJ)); - } - - @Test - @Description("Test Case for handling empty beneficiary details array (TC_SYNC_DATA_004)") - void testSyncDataToAmrit_emptyBeneficiaryDetailsArray() throws Exception { - // Arrange (Given) - JsonObject jsnOBJ = new JsonObject(); - jsnOBJ.add("beneficiaryDetails", new JsonArray()); // Empty beneficiary details array - String requestOBJ = new Gson().toJson(jsnOBJ); - - // Act (When) - Assertions.assertThrows(Exception.class, () -> rmnchDataSyncServiceImpl.syncDataToAmrit(requestOBJ)); - } - - @Test - @Description("Test Case for getting beneficiary data for general OPD with beneficiary details (TC_GET_BEN_DATA_001)") - void testgetBenDataForGeneralOPDCase() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - - RMNCHMBeneficiaryaddress b = new RMNCHMBeneficiaryaddress(); - b.setCountyid(4); - b.setId(BigInteger.valueOf(8)); - b.setVanID(8); - a.equals(b); - a.hashCode(); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - - benDetailsOBJ.setCommunity("Community"); - benDetailsOBJ.setCommunityId(5); - benDetailsOBJ.setDob(null); - benDetailsOBJ.setFirstName("R"); - benDetailsOBJ.setFatherName("Father"); - benDetailsOBJ.setGender("M"); - benDetailsOBJ.setGenderId(1); - benDetailsOBJ.setMaritalstatus("Single"); - benDetailsOBJ.setMaritalstatusId(3); - benDetailsOBJ.setMarriageDate(null); - benDetailsOBJ.setReligion("H"); - benDetailsOBJ.setReligionID(BigInteger.valueOf(9)); - benDetailsOBJ.setSpousename("S"); - benDetailsOBJ.setDob(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.setMarriageDate(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.setUser_image("image"); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "General OPD"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - when(rMNCHCBACDetailsRepo.getDiagnosisProvidedCommon(any(), any())).thenReturn(listOfObject); - - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - } - - @Test - @Description("Test Case for getting beneficiary data for general OPD QC with beneficiary details (TC_GET_BEN_DATA_002)") - void testgetBenDataForGeneralOPDQCCase() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "General OPD (QC)"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - ; - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - when(rMNCHCBACDetailsRepo.getDiagnosisProvidedCommon(any(), any())).thenReturn(listOfObject); - - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - } - - @Test - @Description("Test Case for getting beneficiary data for PNC with beneficiary details (TC_GET_BEN_DATA_003)") - void testgetBenDataForPNCCase() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - getBenRequestHandler.hashCode(); - getBenRequestHandler.equals(getBenRequestHandler); - getBenRequestHandler.toString(); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - a.hashCode(); - a.equals(a); - a.toString(); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.hashCode(); - m.equals(m); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - benDetailsOBJ.setGenderId(1); - benDetailsOBJ.setGender("female"); - benDetailsOBJ.setMotherName("mother"); - benDetailsOBJ.setLiteracyStatus("Educated"); - benDetailsOBJ.setCommunity("Community"); - benDetailsOBJ.setCommunityId(5); - benDetailsOBJ.setDob(null); - benDetailsOBJ.setFirstName("R"); - benDetailsOBJ.setFatherName("Father"); - benDetailsOBJ.setGender("M"); - benDetailsOBJ.setGenderId(1); - benDetailsOBJ.setMaritalstatus("Single"); - benDetailsOBJ.setMaritalstatusId(3); - benDetailsOBJ.setMarriageDate(null); - benDetailsOBJ.setReligion("H"); - benDetailsOBJ.setReligionID(BigInteger.valueOf(9)); - benDetailsOBJ.setSpousename("S"); - benDetailsOBJ.hashCode(); - benDetailsOBJ.equals(benDetailsOBJ); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.setNameOfBank("HDFC"); - benAccountOBJ.setBranchName("Hyd"); - benAccountOBJ.setIfscCode("IFSC"); - benAccountOBJ.setBankAccount("Account"); - benAccountOBJ.hashCode(); - benAccountOBJ.equals(benAccountOBJ); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.setUser_image("image"); - benImageOBJ.hashCode(); - benImageOBJ.equals(benImageOBJ); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.setCountyid(2); - benAddressOBJ.setPermCountry("India"); - benAddressOBJ.setStatePerm(2); - benAddressOBJ.setPermState("TS"); - benAddressOBJ.setDistrictidPerm(9); - benAddressOBJ.setDistrictnamePerm("RR"); - benAddressOBJ.setPermSubDistrictId(8); - benAddressOBJ.setPermSubDistrict("RR"); - benAddressOBJ.setVillageidPerm(7); - benAddressOBJ.setVillagenamePerm("KPHB"); - benAddressOBJ.setPermServicePointId(7); - benAddressOBJ.setPermServicePoint("Service"); - benAddressOBJ.setPermZoneID(5); - benAddressOBJ.setPermZone("EAST"); - benAddressOBJ.setPermAddrLine1("A1"); - benAddressOBJ.setPermAddrLine2("A2"); - benAddressOBJ.setPermAddrLine3("A3"); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - benContactOBJ.setPreferredPhoneNum("9876543210"); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.setRelatedBeneficiaryIdsDB("RelatedDB"); - - benDetailsRMNCHOBJ.setHouseoldId(9l); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "PNC"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - ; - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - when(rMNCHCBACDetailsRepo.getDiagnosisProvidedPNC(any(), any())).thenReturn(listOfObject); - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - } - - @Test - @Description("Test Case for getting beneficiary data for ANC with beneficiary details (TC_GET_BEN_DATA_004)") - void testgetBenDataForANCCase() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - RMNCHMBeneficiarycontact benContactOBJDuplicate = new RMNCHMBeneficiarycontact(); - benContactOBJ.equals(benContactOBJDuplicate); - benContactOBJ.hashCode(); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "ANC"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - ; - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - - } - - @Test - @Description("Test Case for getting beneficiary data for NCD Care with beneficiary details (TC_GET_BEN_DATA_005)") - void testgetBenDataForNCDcare() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - - benDetailsOBJ.setCommunity("Community"); - benDetailsOBJ.setCommunityId(5); - benDetailsOBJ.setDob(null); - benDetailsOBJ.setFirstName("R"); - benDetailsOBJ.setFatherName("Father"); - benDetailsOBJ.setGender("M"); - benDetailsOBJ.setGenderId(1); - benDetailsOBJ.setMaritalstatus("Single"); - benDetailsOBJ.setMaritalstatusId(3); - benDetailsOBJ.setMarriageDate(null); - benDetailsOBJ.setReligion("H"); - benDetailsOBJ.setReligionID(BigInteger.valueOf(9)); - benDetailsOBJ.setSpousename("S"); - benDetailsOBJ.setDob(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.setMarriageDate(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.setUser_image("image"); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - RMNCHCBACdetails benCABCRMNCHROBJ2 = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.equals(benCABCRMNCHROBJ2); - benCABCRMNCHROBJ.hashCode(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "NCD care"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - ; - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - // when(rMNCHCBACDetailsRepo.getDiagnosisProvidedCommon(any(), - // any())).thenReturn(listOfObject); - - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - } - - @Test - @Description("Test Case for getting beneficiary data for NCD Screening with beneficiary details (TC_GET_BEN_DATA_006)") - void testgetBenDataForNCDscreening() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - - benDetailsOBJ.setCommunity("Community"); - benDetailsOBJ.setCommunityId(5); - benDetailsOBJ.setDob(null); - benDetailsOBJ.setFirstName("R"); - benDetailsOBJ.setFatherName("Father"); - benDetailsOBJ.setGender("M"); - benDetailsOBJ.setGenderId(1); - benDetailsOBJ.setMaritalstatus("Single"); - benDetailsOBJ.setMaritalstatusId(3); - benDetailsOBJ.setMarriageDate(null); - benDetailsOBJ.setReligion("H"); - benDetailsOBJ.setReligionID(BigInteger.valueOf(9)); - benDetailsOBJ.setSpousename("S"); - benDetailsOBJ.setDob(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.setMarriageDate(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.setUser_image("image"); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "NCD screening"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - ; - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - when(rMNCHCBACDetailsRepo.getDiagnosisProvidedCommon(any(), any())).thenReturn(listOfObject); - - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - } - - @Test - @Description("Test Case for getting beneficiary data for COVID 19 Screening with beneficiary details (TC_GET_BEN_DATA_007)") - void testgetBenDataForCOVID19Screening() throws Exception { - ReflectionTestUtils.setField(rmnchDataSyncServiceImpl, "door_to_door_page_size", "1"); - GetBenRequestHandler getBenRequestHandler = new GetBenRequestHandler(); - getBenRequestHandler.setAshaId(9); - getBenRequestHandler.setVillageID(8); - getBenRequestHandler.setPageNo(7); - String json = new Gson().toJson(getBenRequestHandler); - List list = new ArrayList<>(); - RMNCHMBeneficiaryaddress a = new RMNCHMBeneficiaryaddress(); - a.setCountyid(4); - a.setId(BigInteger.valueOf(8)); - a.setVanID(8); - list.add(a); - Page pagermnch = new PageImpl<>(list); - when(rMNCHBenAddressRepo.getBenData(any(), any())).thenReturn(pagermnch); - - RMNCHMBeneficiarymapping m = new RMNCHMBeneficiarymapping(); - m.setBenDetailsId(BigInteger.valueOf(9)); - m.setBenAccountID(BigInteger.valueOf(9)); - m.setBenImageId(BigInteger.valueOf(9)); - m.setBenAddressId(BigInteger.valueOf(9)); - m.setBenConsentId(BigInteger.valueOf(9)); - m.setBenRegId(BigInteger.valueOf(9)); - m.toString(); - RMNCHMBeneficiarydetail benDetailsOBJ = new RMNCHMBeneficiarydetail(); - - benDetailsOBJ.setCommunity("Community"); - benDetailsOBJ.setCommunityId(5); - benDetailsOBJ.setDob(null); - benDetailsOBJ.setFirstName("R"); - benDetailsOBJ.setFatherName("Father"); - benDetailsOBJ.setGender("M"); - benDetailsOBJ.setGenderId(1); - benDetailsOBJ.setMaritalstatus("Single"); - benDetailsOBJ.setMaritalstatusId(3); - benDetailsOBJ.setMarriageDate(null); - benDetailsOBJ.setReligion("H"); - benDetailsOBJ.setReligionID(BigInteger.valueOf(9)); - benDetailsOBJ.setSpousename("S"); - benDetailsOBJ.setDob(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.setMarriageDate(Timestamp.valueOf("2011-10-02 18:48:05.123")); - benDetailsOBJ.toString(); - RMNCHMBeneficiaryAccount benAccountOBJ = new RMNCHMBeneficiaryAccount(); - benAccountOBJ.toString(); - RMNCHMBeneficiaryImage benImageOBJ = new RMNCHMBeneficiaryImage(); - benImageOBJ.setUser_image("image"); - benImageOBJ.toString(); - RMNCHMBeneficiaryaddress benAddressOBJ = new RMNCHMBeneficiaryaddress(); - benAddressOBJ.toString(); - RMNCHMBeneficiarycontact benContactOBJ = new RMNCHMBeneficiarycontact(); - benContactOBJ.toString(); - RMNCHBeneficiaryDetailsRmnch benDetailsRMNCHOBJ = new RMNCHBeneficiaryDetailsRmnch(); - benDetailsRMNCHOBJ.toString(); - - RMNCHBornBirthDetails benBotnBirthRMNCHROBJ = new RMNCHBornBirthDetails(); - benBotnBirthRMNCHROBJ.toString(); - - RMNCHCBACdetails benCABCRMNCHROBJ = new RMNCHCBACdetails(); - benCABCRMNCHROBJ.toString(); - - Object[] elements = new Object[4]; - elements[0] = BigInteger.valueOf(987); - elements[1] = "COVID-19 Screening"; - elements[2] = 2; - elements[3] = 3; - List objArraylist = new ArrayList<>(); - objArraylist.add(elements); - - List listOfObject = new ArrayList<>(); - listOfObject.add("Tuberculosis||Diabetes mellitus"); - ; - when(rMNCHBenDetailsRepo.getByIdAndVanID(m.getBenDetailsId(), a.getVanID())).thenReturn(benDetailsOBJ); - when(rMNCHBenAccountRepo.getByIdAndVanID(m.getBenAccountID(), a.getVanID())).thenReturn(benAccountOBJ); - when(rMNCHBenImageRepo.getByIdAndVanID(m.getBenImageId().longValue(), a.getVanID())).thenReturn(benImageOBJ); - when(rMNCHBenAddressRepo.getByIdAndVanID(m.getBenAddressId(), a.getVanID())).thenReturn(benAddressOBJ); - // when(rMNCHBenContactRepo.getByIdAndVanID(m.getBenContactsId(), - // a.getVanID())).thenReturn(benContactOBJ); - when(rMNCHMBenRegIdMapRepo.getBenIdFromRegID(m.getBenRegId().longValue())).thenReturn(BigInteger.valueOf(9)); - when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(m.getBenRegId())).thenReturn(benDetailsRMNCHOBJ); - when(rMNCHBornBirthDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benBotnBirthRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getByRegID(m.getBenRegId())).thenReturn(benCABCRMNCHROBJ); - when(rMNCHCBACDetailsRepo.getVisitDetailsbyRegID(any())).thenReturn(objArraylist); - - when(rMNCHCBACDetailsRepo.getDiagnosisProvidedCommon(any(), any())).thenReturn(listOfObject); - - when(rMNCHMBenMappingRepo.getByAddressIDAndVanID(a.getId(), a.getVanID())).thenReturn(m); - String resp = rmnchDataSyncServiceImpl.getBenData(json, null); - JSONParser parser = new JSONParser(); - JSONObject jsonResp = (JSONObject) parser.parse(resp); - String string = jsonResp.getAsString("totalPage"); - Integer valueOf = Integer.valueOf(string); - Assertions.assertTrue(valueOf > 0); - } - - private String getData(String resp, String status) throws ParseException { - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(resp); - JSONObject object = (JSONObject) json.get("response"); - String actualresp = object.getAsString(status); - return actualresp; - } -}