diff --git a/pom.xml b/pom.xml index 557b3ab..d3a5f77 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,10 @@ target/classes/common_${environment}.properties true target + 127.0.0.1 + 9990 + + @@ -41,7 +45,24 @@ org.springframework.boot spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-logging + + + org.springframework.boot spring-boot-starter-web @@ -52,11 +73,13 @@ spring-boot-devtools runtime - - mysql - mysql-connector-java - 8.0.33 - + + + com.mysql + mysql-connector-j + 8.2.0 + + org.projectlombok lombok @@ -83,6 +106,13 @@ org.springframework.boot spring-boot-starter-test test + + + jakarta.xml.bind + jakarta.xml.bind-api + + + org.springframework.security @@ -109,19 +139,13 @@ com.fasterxml.jackson.core jackson-databind + 2.16.1 com.fasterxml.jackson.core jackson-core - - org.quartz-scheduler - quartz - - - org.quartz-scheduler - quartz-jobs - + org.springframework.boot spring-boot-starter-cache @@ -135,25 +159,12 @@ org.springframework.boot spring-boot-starter-mail - - com.sun.jersey - jersey-client - 1.19.4 - - - javax.ws.rs - javax.ws.rs-api - 2.1.1 - + com.sun.jersey.contribs jersey-multipart 1.19.4 - - org.glassfish.jersey.media - jersey-media-multipart - org.springframework.boot @@ -178,6 +189,23 @@ guava 33.0.0-jre + + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.slf4j + slf4j-api + @@ -197,23 +225,7 @@ identity-0.0.1 - - org.owasp - dependency-check-maven - 9.0.8 - - HTML - nvd - ${NVD_API_KEY} - - - - - check - - - - + org.codehaus.mojo versions-maven-plugin @@ -323,6 +335,7 @@ + diff --git a/src/main/java/com/iemr/common/identity/IdentityApplication.java b/src/main/java/com/iemr/common/identity/IdentityApplication.java index 24a1fa5..2b6ac32 100644 --- a/src/main/java/com/iemr/common/identity/IdentityApplication.java +++ b/src/main/java/com/iemr/common/identity/IdentityApplication.java @@ -26,25 +26,21 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; -import org.springframework.transaction.annotation.EnableTransactionManagement; import com.iemr.common.identity.utils.IEMRApplBeans; @SpringBootApplication -@EnableTransactionManagement public class IdentityApplication extends SpringBootServletInitializer { public static void main(String[] args) { - SpringApplication.run(applicationClass, args); + SpringApplication.run(IdentityApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(applicationClass); + return application.sources(IdentityApplication.class); } - private static Class applicationClass = IdentityApplication.class; - @Bean public IEMRApplBeans instantiateBeans(){ diff --git a/src/main/java/com/iemr/common/identity/controller/IdentityController.java b/src/main/java/com/iemr/common/identity/controller/IdentityController.java index 6b633d7..3250211 100644 --- a/src/main/java/com/iemr/common/identity/controller/IdentityController.java +++ b/src/main/java/com/iemr/common/identity/controller/IdentityController.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Objects; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -114,25 +115,13 @@ public String getBeneficiaries( @Operation(summary = "Search beneficiary based on beneficiary registration id") @PostMapping(path = "/getByBenRegId", headers = "Authorization") public String getBeneficiariesByBeneficiaryRegId( - @Param(value = "\"Integer\"") @RequestParam String benRegId) { - logger.info("IdentityController.getBeneficiary - start. benId = " + benRegId); + @Param(value = "\"Integer\"") @RequestParam("benRegId") String benRegId) { String response; try { - String benRegIdValue = ""; - JsonElement json = JsonParser.parseString(benRegId); - - if (json instanceof JsonNull) { + if (null == benRegId || StringUtils.isEmpty(benRegId)) { return getErrorResponseString("Null/Empty Beneficiary Id.", 5000, "failure", ""); - } - - if (json instanceof JsonPrimitive) { - benRegIdValue = benRegId; - } else { - benRegIdValue = InputMapper.getInstance().gson().fromJson(json, String.class); - } - - List list = svc.getBeneficiariesByBenRegId(new BigInteger(benRegIdValue)); + List list = svc.getBeneficiariesByBenRegId(new BigInteger(benRegId)); list.removeIf(Objects::isNull); Collections.sort(list); response = getSuccessResponseString(list, 200, "success", "getBeneficiariesByBeneficiaryRegId"); @@ -151,9 +140,7 @@ public String getBeneficiariesByBeneficiaryRegId( @Operation(summary = "Search identity based on beneficiary registration id") @PostMapping(path = "/getByBenId", headers = "Authorization") public String getBeneficiariesByBeneficiaryId( - @Param(value = "\"Integer\"") @RequestParam String benId) { - logger.info("IdentityController.getBeneficiary - start. benId = " + benId); - + @Param(value = "\"Integer\"") @RequestParam("benId") String benId) { String response; try { String benIdValue = ""; @@ -188,8 +175,7 @@ public String getBeneficiariesByBeneficiaryId( @Operation(summary = "Search beneficiary based on phone number") @PostMapping(path = "/getByPhoneNum", headers = "Authorization") public String getBeneficiariesByPhoneNum( - @Param(value = "\"String\"") @RequestParam String phoneNum) { - logger.info("IdentityController.getBeneficiary - start. phoneNum = " + phoneNum); + @Param(value = "\"String\"") @RequestParam("phoneNum") String phoneNum) { String response; try { String phoneNumValue = ""; @@ -220,8 +206,7 @@ public String getBeneficiariesByPhoneNum( @Operation(summary = "Search beneficiary based on health ID / ABHA Address") @PostMapping(path = "/getByAbhaAddress", headers = "Authorization") public String searhBeneficiaryByABHAAddress( - @Param(value = "\"String\"") @RequestParam String healthID) { - logger.info("IdentityController.getBeneficiary - start. Health ID / ABHA Address = " + healthID); + @Param(value = "\"String\"") @RequestParam("healthID") String healthID) { String response; try { String healthIDValue = ""; @@ -253,8 +238,7 @@ public String searhBeneficiaryByABHAAddress( @Operation(summary = "Search beneficiary based on health ID number / ABHA ID number") @PostMapping(path = "/getByAbhaIdNo", headers = "Authorization") public String searhBeneficiaryByABHAIdNo( - @Param(value = "\"String\"") @RequestParam String healthIDNo) { - logger.info("IdentityController.getBeneficiary - start. HealthIDNo / ABHA Id No = " + healthIDNo); + @Param(value = "\"String\"") @RequestParam("healthIDNo") String healthIDNo) { String response; try { String healthIDNoValue = ""; @@ -286,8 +270,7 @@ public String searhBeneficiaryByABHAIdNo( @Operation(summary = "Search beneficiary based on family id") @PostMapping(path = "/searchByFamilyId", headers = "Authorization") public String searhBeneficiaryByFamilyId( - @Param(value = "\"String\"") @RequestParam String familyId) { - logger.info("IdentityController.getBeneficiary - start. family id = " + familyId); + @Param(value = "\"String\"") @RequestParam("familyId") String familyId) { String response; try { @@ -342,8 +325,7 @@ public String searchBeneficiaryByBlockIdAndLastModDate( @Operation(summary = "Search beneficiary based on government identity number") @PostMapping(path = "/searhByGovIdentity", headers = "Authorization") public String searhBeneficiaryByGovIdentity( - @Param(value = "\"String\"") @RequestParam String identity) { - logger.info("IdentityController.getBeneficiary - start. Gov Identity = " + identity); + @Param(value = "\"String\"") @RequestParam("identity") String identity) { String response; try { diff --git a/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHMBeneficiarycontact.java b/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHMBeneficiarycontact.java index be46ae4..fa356de 100644 --- a/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHMBeneficiarycontact.java +++ b/src/main/java/com/iemr/common/identity/data/rmnch/RMNCHMBeneficiarycontact.java @@ -25,6 +25,8 @@ import java.math.BigInteger; import java.sql.Timestamp; +import com.google.gson.annotations.Expose; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -32,11 +34,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Transient; - -import org.hibernate.validator.constraints.Email; - -import com.google.gson.annotations.Expose; - +import jakarta.validation.constraints.Email; import lombok.Data; @Entity diff --git a/src/main/java/com/iemr/common/identity/domain/MBeneficiarycontact.java b/src/main/java/com/iemr/common/identity/domain/MBeneficiarycontact.java index a51763a..32e34a1 100644 --- a/src/main/java/com/iemr/common/identity/domain/MBeneficiarycontact.java +++ b/src/main/java/com/iemr/common/identity/domain/MBeneficiarycontact.java @@ -25,6 +25,9 @@ import java.math.BigInteger; import java.sql.Timestamp; + +import com.google.gson.annotations.Expose; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -32,11 +35,7 @@ import jakarta.persistence.Id; import jakarta.persistence.NamedQuery; import jakarta.persistence.Table; - -import org.hibernate.validator.constraints.Email; - -import com.google.gson.annotations.Expose; - +import jakarta.validation.constraints.Email; import lombok.Data; /** diff --git a/src/main/java/com/iemr/common/identity/domain/MBeneficiarydetail.java b/src/main/java/com/iemr/common/identity/domain/MBeneficiarydetail.java index 6fd66da..a4d723c 100644 --- a/src/main/java/com/iemr/common/identity/domain/MBeneficiarydetail.java +++ b/src/main/java/com/iemr/common/identity/domain/MBeneficiarydetail.java @@ -41,7 +41,6 @@ import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; @Entity @Table(name = "i_beneficiarydetails") diff --git a/src/main/java/com/iemr/common/identity/service/IdentityService.java b/src/main/java/com/iemr/common/identity/service/IdentityService.java index 1340421..c7b0c97 100644 --- a/src/main/java/com/iemr/common/identity/service/IdentityService.java +++ b/src/main/java/com/iemr/common/identity/service/IdentityService.java @@ -88,7 +88,6 @@ 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 com.iemr.common.identity.utils.mapper.OutputMapper; import com.iemr.common.identity.utils.response.OutputResponse; diff --git a/src/main/java/com/iemr/common/identity/utils/http/HTTPRequestInterceptor.java b/src/main/java/com/iemr/common/identity/utils/http/HTTPRequestInterceptor.java index 37673bc..6a22ff3 100644 --- a/src/main/java/com/iemr/common/identity/utils/http/HTTPRequestInterceptor.java +++ b/src/main/java/com/iemr/common/identity/utils/http/HTTPRequestInterceptor.java @@ -21,6 +21,7 @@ */ package com.iemr.common.identity.utils.http; + import javax.ws.rs.core.MediaType; import org.slf4j.Logger; diff --git a/src/main/java/com/iemr/common/identity/utils/http/HttpUtils.java b/src/main/java/com/iemr/common/identity/utils/http/HttpUtils.java index 591eb4c..67f856a 100644 --- a/src/main/java/com/iemr/common/identity/utils/http/HttpUtils.java +++ b/src/main/java/com/iemr/common/identity/utils/http/HttpUtils.java @@ -41,6 +41,7 @@ import com.sun.jersey.multipart.FormDataBodyPart; import com.sun.jersey.multipart.FormDataMultiPart; + @Component public class HttpUtils { public static final String AUTHORIZATION = "Authorization"; @@ -126,8 +127,7 @@ public String uploadFile(String uri, String data, Map header) th try(FormDataMultiPart multiPart = new FormDataMultiPart(); FileInputStream is = new FileInputStream(data)) { - FormDataBodyPart filePart = new FormDataBodyPart("content", is, - MediaType.APPLICATION_OCTET_STREAM_TYPE); + FormDataBodyPart filePart = new FormDataBodyPart(); multiPart.bodyPart(filePart); multiPart.field("docPath", data); headers.add("Content-Type", MediaType.APPLICATION_JSON); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f1f07eb..78302a2 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -17,7 +17,6 @@ - %d %-5p [%X{sessionId}] [%X{userId}] %C{1}.%M:%L] %m%n diff --git a/src/test/java/com/iemr/common/identity/IdentityApplicationTests.java b/src/test/java/com/iemr/common/identity/IdentityApplicationTests.java index d573d28..eb74d98 100644 --- a/src/test/java/com/iemr/common/identity/IdentityApplicationTests.java +++ b/src/test/java/com/iemr/common/identity/IdentityApplicationTests.java @@ -22,7 +22,7 @@ package com.iemr.common.identity; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -36,6 +36,6 @@ class IdentityApplicationTests { IdentityApplication identityApplication; @Test void contextLoads() { - Assert.assertNotNull(identityApplication.toString()); + Assertions.assertNotNull(identityApplication.toString()); } } diff --git a/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java b/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java index cf5b385..8b7d8d3 100644 --- a/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java +++ b/src/test/java/com/iemr/common/identity/controller/IdentityControllerTest.java @@ -28,11 +28,9 @@ import java.math.BigInteger; import java.util.List; -import org.junit.Assert; 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; @@ -49,7 +47,6 @@ 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; @@ -74,79 +71,79 @@ void testGetBeneficiaries() throws NoResultException, QueryTimeoutException, Exc String req = new Gson().toJson(searchParams); //when(svc.getBeneficiaries(searchParams)).thenReturn(any()).thenReturn(bdList); String resp = identityController.getBeneficiaries(req); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetBeneficiariesByBeneficiaryRegId() { String resp = identityController.getBeneficiariesByBeneficiaryRegId("123"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetBeneficiariesByBeneficiaryRegIdCatchBlock() throws NoResultException, QueryTimeoutException, Exception { when(svc.getBeneficiariesByBenRegId(any())).thenThrow(NoResultException.class); String resp = identityController.getBeneficiariesByBeneficiaryRegId("123"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetBeneficiariesByBeneficiaryId() { String resp = identityController.getBeneficiariesByBeneficiaryId("987"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetBeneficiariesByBeneficiaryIdCatchBlock() throws NoResultException, QueryTimeoutException, Exception { when(svc.getBeneficiariesByBenId(any())).thenThrow(NoResultException.class); String resp = identityController.getBeneficiariesByBeneficiaryId("987"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetBeneficiariesByPhoneNum() { String resp = identityController.getBeneficiariesByPhoneNum("9988776655"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetBeneficiariesByPhoneNumCatchblock() throws NoResultException, QueryTimeoutException, Exception { when(svc.getBeneficiariesByPhoneNum(any())).thenThrow(NoResultException.class); String resp = identityController.getBeneficiariesByPhoneNum("9988776655"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSearhBeneficiaryByABHAAddress() { String resp = identityController.searhBeneficiaryByABHAAddress("9876"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSearhBeneficiaryByABHAAddressCatchblock() throws NoResultException, QueryTimeoutException, Exception { when(svc.getBeneficiaryByHealthIDAbhaAddress(any())).thenThrow(NoResultException.class); String resp = identityController.searhBeneficiaryByABHAAddress("9876"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSearhBeneficiaryByABHAIdNo() { String resp = identityController.searhBeneficiaryByABHAIdNo("9876"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSearhBeneficiaryByABHAIdNoCatchblock() throws NoResultException, QueryTimeoutException, Exception { when(svc.getBeneficiaryByHealthIDNoAbhaIdNo(any())).thenThrow(NoResultException.class); String resp = identityController.searhBeneficiaryByABHAIdNo("9876"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSearhBeneficiaryByFamilyId() { String resp = identityController.searhBeneficiaryByFamilyId("9876"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSearhBeneficiaryByFamilyIdCatchblock() throws NoResultException, QueryTimeoutException, Exception { when(svc.searhBeneficiaryByFamilyId(any())).thenThrow(NoResultException.class); String resp = identityController.searhBeneficiaryByFamilyId("9876"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test @@ -159,8 +156,8 @@ void testSearchBeneficiaryByBlockIdAndLastModDate() { String req = new Gson().toJson(searchSyncDTO); //when(svc.searchBeneficiaryByBlockIdAndLastModifyDate(any(), any())).thenReturn(bdList); String resp = identityController.searchBeneficiaryByBlockIdAndLastModDate(req); - Assert.assertNotNull(resp); - //Assert.assertThrows(Exception.class, () -> + Assertions.assertNotNull(resp); + //Assertions.assertThrows(Exception.class, () -> } @@ -169,7 +166,7 @@ void testSearchBeneficiaryByBlockIdAndLastModDate() { void testReserveIdentityEmptyIdentity() throws ParseException { String resp = identityController.reserveIdentity("String"); String status = getData(resp, "statusMessage"); - Assert.assertNotEquals("Null/Empty Identity Create Data.", status); + Assertions.assertNotEquals("Null/Empty Identity Create Data.", status); } @Test @@ -178,14 +175,14 @@ void testReserveIdentity() throws ParseException { String req = new Gson().toJson(reserveIdentityDTO); String resp = identityController.reserveIdentity(req); String status = getData(resp, "statusMessage"); - Assert.assertEquals("success", status); + Assertions.assertEquals("success", status); } @Test void testUnreserveIdentityEmptyIdentity() throws ParseException { String resp = identityController.unreserveIdentity("String"); String status = getData(resp, "statusMessage"); - Assert.assertNotEquals("Null/Empty Identity Create Data.", status); + Assertions.assertNotEquals("Null/Empty Identity Create Data.", status); } @Test @@ -194,7 +191,7 @@ void testUnreserveIdentity() throws ParseException { String req = new Gson().toJson(reserveIdentityDTO); String resp = identityController.unreserveIdentity(req); String status = getData(resp, "statusMessage"); - Assert.assertEquals("success", status); + Assertions.assertEquals("success", status); } //@Test @@ -205,7 +202,7 @@ void testGetJsonAsString() { @Test void testGetFiniteBeneficiariesCatchblockIfInvalidJSON() { String resp = identityController.getFiniteBeneficiaries("String"); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetFiniteBeneficiaries() throws ParseException { @@ -213,7 +210,7 @@ void testGetFiniteBeneficiaries() throws ParseException { String req = new Gson().toJson(identitySearchDTO); String resp = identityController.getFiniteBeneficiaries(req); String status = getData(resp, "statusMessage"); - Assert.assertEquals("success", status); + Assertions.assertEquals("success", status); } @Test @@ -223,7 +220,7 @@ void testGetFiniteBeneficiariesNoResultException() throws NoResultException, Que when(svc.getBeneficiaries(identitySearchDTO)).thenThrow(NoResultException.class); String resp = identityController.getFiniteBeneficiaries(req); String status = getData(resp, "statusMessage"); - Assert.assertEquals("failure", status); + Assertions.assertEquals("failure", status); } @Test void testGetFiniteBeneficiariesQueryTimeoutException() throws NoResultException, QueryTimeoutException, Exception { @@ -232,14 +229,14 @@ void testGetFiniteBeneficiariesQueryTimeoutException() throws NoResultException, when(svc.getBeneficiaries(identitySearchDTO)).thenThrow(QueryTimeoutException.class); String resp = identityController.getFiniteBeneficiaries(req); String status = getData(resp, "statusMessage"); - Assert.assertEquals("failure", status); + Assertions.assertEquals("failure", status); } @Test void testGetBeneficiaryImageByBenRegID() { String resp = identityController.getBeneficiaryImageByBenRegID("String"); - Assert.assertNull(resp); + Assertions.assertNull(resp); } @Test @@ -248,7 +245,7 @@ void testEditIdentityEducationOrCommunity() throws ParseException { String req = new Gson().toJson(identityEditDTO); String resp = identityController.editIdentityEducationOrCommunity(req); String actualresp = getData(resp,"data"); - Assert.assertEquals("Updated successfully", actualresp); + Assertions.assertEquals("Updated successfully", actualresp); } @@ -268,18 +265,18 @@ void testEditIdentityEducationOrCommunityCatchblock() throws MissingMandatoryFie svc.editIdentityEducationOrCommunity(any()); String resp = identityController.editIdentityEducationOrCommunity(req); String actualresp = getData(resp,"data"); - Assert.assertNotEquals("Updated successfully", actualresp); + Assertions.assertNotEquals("Updated successfully", actualresp); } @Test void testCheckAvailablBenIDLocalServer() { String resp = identityController.checkAvailablBenIDLocalServer(); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testSaveGeneratedBenIDToLocalServer() { String resp = identityController.saveGeneratedBenIDToLocalServer(null); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } } diff --git a/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java b/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java index 51dac73..f8d9d81 100644 --- a/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java +++ b/src/test/java/com/iemr/common/identity/service/IdentityServiceTest.java @@ -21,8 +21,7 @@ */ package com.iemr.common.identity.service; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -37,13 +36,14 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.google.common.collect.Lists; @@ -93,7 +93,7 @@ import jakarta.persistence.NoResultException; import jakarta.persistence.QueryTimeoutException; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(MockitoExtension.class) public class IdentityServiceTest { @InjectMocks @@ -468,7 +468,7 @@ public void getBeneficiariesPartialDeatilsByBenRegIdListTest1() { when(mappingRepo.getBenMappingByRegIDList(BenRegIds)).thenReturn(list); List dtoList = identityService .getBeneficiariesPartialDeatilsByBenRegIdList(BenRegIds); - Assert.assertTrue(dtoList.size() > 0); + Assertions.assertTrue(dtoList.size() > 0); } @Test @@ -705,7 +705,7 @@ public void testcreateIdentity() throws IEMRException { when(partialMapper.mBeneficiarymappingToBeneficiaryCreateResp(any())).thenReturn(resp); BeneficiaryCreateResp createIdentity = identityService.createIdentity(identityDTO); - Assert.assertNotNull(createIdentity); + Assertions.assertNotNull(createIdentity); } @Test 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 index f0c2fad..b6e6dcd 100644 --- a/src/test/java/com/iemr/common/identity/service/familyTagging/FamilyTagServiceImplTest.java +++ b/src/test/java/com/iemr/common/identity/service/familyTagging/FamilyTagServiceImplTest.java @@ -10,7 +10,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -59,7 +59,7 @@ void testAddTag() throws IEMRException { benFamilyMapping.setNoOfmembers(4); when(familyTagRepo.searchFamilyByFamilyId(requestObj.getFamilyId())).thenReturn(benFamilyMapping ); String resp = familyTagServiceImpl.addTag(request); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test @@ -80,12 +80,12 @@ void testDoFamilyUntag() throws IEMRException, JSONException { benFamilyMapping.setNoOfmembers(4); when(familyTagRepo.searchFamilyByFamilyId("789")).thenReturn(benFamilyMapping); String resp = familyTagServiceImpl.doFamilyUntag(string); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testEditFamilyDetailsCatchblock() throws IEMRException { - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.editFamilyDetails(null)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.editFamilyDetails(null)); } @Test @@ -104,7 +104,7 @@ void testEditFamilyDetails() throws IEMRException { when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))).thenReturn(mBeneficieryMapping); String editFamilyDetails = familyTagServiceImpl.editFamilyDetails(json); - Assert.assertNotNull(editFamilyDetails); + Assertions.assertNotNull(editFamilyDetails); } @Test void testEditFamilyDetails_If_BenFamilyMapping_Null() throws IEMRException { @@ -117,7 +117,7 @@ void testEditFamilyDetails_If_BenFamilyMapping_Null() throws IEMRException { String json = new Gson().toJson(benFamilyMapping); when(familyTagRepo.searchFamilyByFamilyId(benFamilyMapping.getFamilyId())).thenReturn(null); - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.editFamilyDetails(json)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.editFamilyDetails(json)); } @Test void testEditFamilyDetailsIfMBeneficiarymappingNull() throws IEMRException { @@ -134,12 +134,12 @@ void testEditFamilyDetailsIfMBeneficiarymappingNull() throws IEMRException { mBeneficieryMapping.setVanID(123); when(benMappingRepo.getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))).thenReturn(null); - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.editFamilyDetails(json)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.editFamilyDetails(json)); } @Test void testSearchFamilyCatchblock() throws IEMRException { - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.searchFamily(null)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.searchFamily(null)); } @Test @@ -154,7 +154,7 @@ void testSearchFamily() throws IEMRException { list.add(benFamilyMapping); when(familyTagRepo.searchFamilyWithFamilyId(benFamilyMapping.getFamilyName(), benFamilyMapping.getVillageId(), benFamilyMapping.getFamilyId())).thenReturn(list); - Assert.assertNotNull(familyTagServiceImpl.searchFamily(json)); + Assertions.assertNotNull(familyTagServiceImpl.searchFamily(json)); } @Test @@ -169,7 +169,7 @@ void testSearchFamily_If_FamilyID_NULL() throws IEMRException { list.add(benFamilyMapping); when(familyTagRepo.searchFamily(benFamilyMapping.getFamilyName(), benFamilyMapping.getVillageId())).thenReturn(list); - Assert.assertNotNull(familyTagServiceImpl.searchFamily(json)); + Assertions.assertNotNull(familyTagServiceImpl.searchFamily(json)); } @Test void testSearchFamily_If_RESP_NULL() throws IEMRException { @@ -182,12 +182,12 @@ void testSearchFamily_If_RESP_NULL() throws IEMRException { when(familyTagRepo.searchFamily(benFamilyMapping.getFamilyName(), benFamilyMapping.getVillageId())).thenReturn(null); - Assert.assertNotNull(familyTagServiceImpl.searchFamily(json)); + Assertions.assertNotNull(familyTagServiceImpl.searchFamily(json)); } @Test void testCreateFamilyCatchBlock() throws IEMRException { - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.createFamily(null)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.createFamily(null)); } @Test void testCreateFamilyFamilyTaggedIDNull() throws IEMRException { @@ -208,7 +208,7 @@ void testCreateFamilyFamilyTaggedIDNull() throws IEMRException { when(benMappingRepo .getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))).thenReturn(mBeneficiarymapping); - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.createFamily(json)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.createFamily(json)); } @Test void testCreateFamily() throws IEMRException { @@ -231,19 +231,19 @@ void testCreateFamily() throws IEMRException { .getBenDetailsId(BigInteger.valueOf(benFamilyMapping.getBeneficiaryRegId()))).thenReturn(mBeneficiarymapping); String resp = familyTagServiceImpl.createFamily(json); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetFamilyId() throws IEMRException { String resp = familyTagServiceImpl.getFamilyId(""); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test void testGetFamilyDetailsCatchBlock() throws IEMRException { - Assert.assertThrows(IEMRException.class, () -> familyTagServiceImpl.getFamilyDetails(null)); + Assertions.assertThrows(IEMRException.class, () -> familyTagServiceImpl.getFamilyDetails(null)); } @Test @@ -265,6 +265,6 @@ void testGetFamilyDetails() throws IEMRException { when(benMappingRepo.getBenRegId(any(), any())).thenReturn(BigInteger.valueOf(987)); when(benDetailRepo.getFamilyDetails(any())).thenReturn(list); String resp = familyTagServiceImpl.getFamilyDetails(json); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } } 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 index 3057e6d..983410d 100644 --- a/src/test/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImplTest.java +++ b/src/test/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImplTest.java @@ -1,34 +1,25 @@ package com.iemr.common.identity.service.rmnch; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.when; -import java.sql.Timestamp; -import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.json.JSONObject; -import org.junit.Assert; +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 org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import com.google.gson.Gson; -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.RMNCHMBeneficiaryaddress; import com.iemr.common.identity.repo.rmnch.RMNCHBenAccountRepo; import com.iemr.common.identity.repo.rmnch.RMNCHBenAddressRepo; import com.iemr.common.identity.repo.rmnch.RMNCHBenContactRepo; @@ -97,7 +88,6 @@ void testSyncDataToAmrit() throws Exception { RMNCHCBACdetails rMNCHCBACdetails = new RMNCHCBACdetails(); rMNCHCBACdetails.setBenficieryid(Long.valueOf(987)); rMNCHCBACdetailslist.add(rMNCHCBACdetails); - String cbacJson = new Gson().toJson(rMNCHCBACdetails); cbaclist.add(birthJson); jsonObject.put("cBACDetails", cbaclist); @@ -125,7 +115,7 @@ void testSyncDataToAmrit() throws Exception { when(rMNCHBeneficiaryDetailsRmnchRepo.getByRegID(any())).thenReturn(rMNCHBeneficiaryDetailsRmnch); when(rMNCHMBenRegIdMapRepo.getRegID(any())).thenReturn(Long.valueOf(987)); String syncDataToAmrit = rmnchDataSyncServiceImpl.syncDataToAmrit(replace2); - Assert.assertNotNull(syncDataToAmrit); + Assertions.assertNotNull(syncDataToAmrit); } /*