Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.annotation.Description;

import com.google.common.collect.Lists;
import com.google.gson.Gson;
Expand All @@ -56,7 +57,6 @@
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;


@ExtendWith(MockitoExtension.class)
class IdentityControllerTest {
@InjectMocks
Expand All @@ -65,17 +65,18 @@ class IdentityControllerTest {
IdentityService svc;

@Test
@Description("Tests successful retrieval of all beneficiaries. (TC_GetBeneficiaries_Success_001)")
void testGetBeneficiaries() throws NoResultException, QueryTimeoutException, Exception {
IdentitySearchDTO searchParams = new IdentitySearchDTO();

BeneficiariesDTO a1 = new BeneficiariesDTO();
makeBeneficiariesDTO(a1);
List<BeneficiariesDTO> 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);
// when(svc.getBeneficiaries(searchParams)).thenReturn(any()).thenReturn(bdList);
String resp = identityController.getBeneficiaries(req);
Assertions.assertNotNull(resp);

Expand Down Expand Up @@ -103,17 +104,17 @@ private void makeBeneficiariesDTO(BeneficiariesDTO dto) {
benFamilyDTO.setRelationshipID(null);
benFamilyDTO.setRelationshipToSelf(null);
benFamilyDTO.setVanID(null);

tags.add(benFamilyDTO);
dto.setBeneficiaryFamilyTags(tags);
List<BenIdentityDTO> identity = new ArrayList<>();
BenIdentityDTO benIdentityDTO= new BenIdentityDTO();
BenIdentityDTO benIdentityDTO = new BenIdentityDTO();
benIdentityDTO.toString();
identity.add(benIdentityDTO);
dto.setBeneficiaryIdentites(identity);

List<BenServiceDTO> service = new ArrayList<>();
BenServiceDTO benServiceDTO= new BenServiceDTO();
BenServiceDTO benServiceDTO = new BenServiceDTO();
benServiceDTO.toString();
service.add(benServiceDTO);
dto.setBeneficiaryServiceMap(service);
Expand Down Expand Up @@ -160,102 +161,122 @@ private void makeBeneficiariesDTO(BeneficiariesDTO dto) {
}

@Test
@Description("Tests successful retrieval of beneficiaries by beneficiary registration ID. (TC_GetBeneficiariesByBeneficiaryRegId_Success_001)")
void testGetBeneficiariesByBeneficiaryRegId() {
String resp = identityController.getBeneficiariesByBeneficiaryRegId("123");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests exception handling within the getBeneficiariesByBeneficiaryRegId method. (TC_GetBeneficiariesByBeneficiaryRegId_Exception_002)")
void testGetBeneficiariesByBeneficiaryRegIdCatchBlock() throws NoResultException, QueryTimeoutException, Exception {
when(svc.getBeneficiariesByBenRegId(any())).thenThrow(NoResultException.class);
String resp = identityController.getBeneficiariesByBeneficiaryRegId("123");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of beneficiaries by beneficiary ID. (TC_GetBeneficiariesByBeneficiaryId_Success_001)")
void testGetBeneficiariesByBeneficiaryId() {
String resp = identityController.getBeneficiariesByBeneficiaryId("987");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests exception handling within the getBeneficiariesByBeneficiaryId method. (TC_GetBeneficiariesByBeneficiaryId_Exception_002)")
void testGetBeneficiariesByBeneficiaryIdCatchBlock() throws NoResultException, QueryTimeoutException, Exception {
when(svc.getBeneficiariesByBenId(any())).thenThrow(NoResultException.class);
String resp = identityController.getBeneficiariesByBeneficiaryId("987");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of beneficiaries by phone number. (TC_GetBeneficiariesByPhoneNum_Success_001)")
void testGetBeneficiariesByPhoneNum() {
String resp = identityController.getBeneficiariesByPhoneNum("9988776655");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests exception handling within the getBeneficiariesByPhoneNum method. (TC_GetBeneficiariesByPhoneNum_Exception_002)")
void testGetBeneficiariesByPhoneNumCatchblock() throws NoResultException, QueryTimeoutException, Exception {
when(svc.getBeneficiariesByPhoneNum(any())).thenThrow(NoResultException.class);
String resp = identityController.getBeneficiariesByPhoneNum("9988776655");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of beneficiaries by ABHA address. (TC_SearhBeneficiaryByABHAAddress_Success_001)")
void testSearhBeneficiaryByABHAAddress() {
String resp = identityController.searhBeneficiaryByABHAAddress("9876");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests exception handling within the searchBeneficiaryByABHAAddress method. (TC_SearhBeneficiaryByABHAAddress_Exception_002)")
void testSearhBeneficiaryByABHAAddressCatchblock() throws NoResultException, QueryTimeoutException, Exception {
when(svc.getBeneficiaryByHealthIDAbhaAddress(any())).thenThrow(NoResultException.class);
String resp = identityController.searhBeneficiaryByABHAAddress("9876");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of beneficiaries by ABHA ID. (TC_SearhBeneficiaryByABHAIdNo_Success_001)")
void testSearhBeneficiaryByABHAIdNo() {
String resp = identityController.searhBeneficiaryByABHAIdNo("9876");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests exception handling within the searchBeneficiaryByABHAIdNo method. (TC_SearhBeneficiaryByABHAIdNo_Exception_002)")
void testSearhBeneficiaryByABHAIdNoCatchblock() throws NoResultException, QueryTimeoutException, Exception {
when(svc.getBeneficiaryByHealthIDNoAbhaIdNo(any())).thenThrow(NoResultException.class);
String resp = identityController.searhBeneficiaryByABHAIdNo("9876");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of beneficiaries by family ID. (TC_SearhBeneficiaryByFamilyId_Success_001)")
void testSearhBeneficiaryByFamilyId() {
String resp = identityController.searhBeneficiaryByFamilyId("9876");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests exception handling within the searchBeneficiaryByFamilyId method. (TC_SearhBeneficiaryByFamilyId_Exception_002)")
void testSearhBeneficiaryByFamilyIdCatchblock() throws NoResultException, QueryTimeoutException, Exception {
when(svc.searhBeneficiaryByFamilyId(any())).thenThrow(NoResultException.class);
String resp = identityController.searhBeneficiaryByFamilyId("9876");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of beneficiaries by block ID and last modified date. (TC_SearchBeneficiaryByBlockIdAndLastModDate_Success_001)")
void testSearchBeneficiaryByBlockIdAndLastModDate() {
BeneficiariesDTO a1 = new BeneficiariesDTO();
List<BeneficiariesDTO> 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);
// when(svc.searchBeneficiaryByBlockIdAndLastModifyDate(any(),
// any())).thenReturn(bdList);

String resp = identityController.searchBeneficiaryByVillageIdAndLastModDate(req);

Assertions.assertNotNull(resp);
}



@Test
@Description("Tests the behavior of the reserveIdentity method when an empty identity object is provided. (TC_ReserveIdentityEmptyIdentity_001)")
void testReserveIdentityEmptyIdentity() throws ParseException {
String resp = identityController.reserveIdentity("String");
String status = getData(resp, "statusMessage");
Assertions.assertNotEquals("Null/Empty Identity Create Data.", status);
}

@Test
@Description("Tests successful reservation of an identity. (TC_ReserveIdentity_Success_002)")
void testReserveIdentity() throws ParseException {
ReserveIdentityDTO reserveIdentityDTO = new ReserveIdentityDTO();
String req = new Gson().toJson(reserveIdentityDTO);
Expand All @@ -265,13 +286,16 @@ void testReserveIdentity() throws ParseException {
}

@Test
@Description("Tests the behavior of the unreserveIdentity method when an empty identity object is provided. (TC_UnreserveIdentityEmptyIdentity_001)")
void testUnreserveIdentityEmptyIdentity() throws ParseException {
String resp = identityController.unreserveIdentity("String");
String status = getData(resp, "statusMessage");
Assertions.assertNotEquals("Null/Empty Identity Create Data.", status);

}

@Test
@Description("Tests successful unreservation of an identity. (TC_UnreserveIdentity_Success_002)")
void testUnreserveIdentity() throws ParseException {
ReserveIdentityDTO reserveIdentityDTO = new ReserveIdentityDTO();
String req = new Gson().toJson(reserveIdentityDTO);
Expand All @@ -280,26 +304,25 @@ void testUnreserveIdentity() throws ParseException {
Assertions.assertEquals("success", status);
}

//@Test
void testGetJsonAsString() {
//identityController.
}

@Test
@Description("Tests exception handling within the getFiniteBeneficiaries method when an invalid JSON is provided. (TC_GetFiniteBeneficiariesCatchblockIfInvalidJSON_001)")
void testGetFiniteBeneficiariesCatchblockIfInvalidJSON() {
String resp = identityController.getFiniteBeneficiaries("String");
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful retrieval of a finite number of beneficiaries. (TC_GetFiniteBeneficiaries_Success_002)")
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
@Description("Tests the handling of a NoResultException within the getFiniteBeneficiaries method. (TC_GetFiniteBeneficiariesNoResultException_003)")
void testGetFiniteBeneficiariesNoResultException() throws NoResultException, QueryTimeoutException, Exception {
IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO();
String req = new Gson().toJson(identitySearchDTO);
Expand All @@ -308,7 +331,9 @@ void testGetFiniteBeneficiariesNoResultException() throws NoResultException, Que
String status = getData(resp, "statusMessage");
Assertions.assertEquals("failure", status);
}

@Test
@Description("Tests the handling of a QueryTimeoutException within the getFiniteBeneficiaries method. (TC_GetFiniteBeneficiariesQueryTimeoutException_004)")
void testGetFiniteBeneficiariesQueryTimeoutException() throws NoResultException, QueryTimeoutException, Exception {
IdentitySearchDTO identitySearchDTO = new IdentitySearchDTO();
String req = new Gson().toJson(identitySearchDTO);
Expand All @@ -317,55 +342,60 @@ void testGetFiniteBeneficiariesQueryTimeoutException() throws NoResultException,
String status = getData(resp, "statusMessage");
Assertions.assertEquals("failure", status);
}


@Test
@Description("Tests successful retrieval of beneficiary image by beneficiary registration ID. (TC_GetBeneficiaryImageByBenRegID_Success_001)")
void testGetBeneficiaryImageByBenRegID() {
String resp = identityController.getBeneficiaryImageByBenRegID("String");
Assertions.assertNull(resp);
}

@Test
@Description("Tests successful editing of identity information related to education or community details. (TC_EditIdentityEducationOrCommunity_Success_001)")
void testEditIdentityEducationOrCommunity() throws ParseException {
IdentityEditDTO identityEditDTO = new IdentityEditDTO();
String req = new Gson().toJson(identityEditDTO);
String resp = identityController.editIdentityEducationOrCommunity(req);
String actualresp = getData(resp,"data");
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);

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
@Description("Tests exception handling within the editIdentityEducationOrCommunity method. (TC_EditIdentityEducationOrCommunity_Exception_002)")
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");
String actualresp = getData(resp, "data");
Assertions.assertNotEquals("Updated successfully", actualresp);
}

@Test
@Description("Tests the availability of a beneficiary ID on the local server. (TC_CheckAvailablBenIDLocalServer_Success_001)")
void testCheckAvailablBenIDLocalServer() {
String resp = identityController.checkAvailablBenIDLocalServer();
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests successful saving of a generated beneficiary ID to the local server. (TC_SaveGeneratedBenIDToLocalServer_Success_001)")
void testSaveGeneratedBenIDToLocalServer() {
String resp = identityController.saveGeneratedBenIDToLocalServer(null);
Assertions.assertNotNull(resp);
}

@Test
@Description("Tests counting beneficiaries based on village ID and last modified date. (TC_countBeneficiaryByVillageIdAndLastModDate_Success_001)")
public void testcountBeneficiaryByVillageIdAndLastModDate() {
SearchSyncDTO searchSyncDTO = new SearchSyncDTO();
searchSyncDTO.setLastModifiedDate(9l);
Expand Down
Loading