From 8bfe8a64f90d4afea73a2f60ce167d3ec79eefd9 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 13:49:29 +0530 Subject: [PATCH 01/11] updated package --- .../impl => constant}/UISchemaTypes.java | 4 +- .../ResidentCredentialController.java | 3 +- .../io/mosip/resident/util/TemplateUtil.java | 2 +- .../resident/validator/RequestValidator.java | 56 ++++++++++--------- 4 files changed, 32 insertions(+), 33 deletions(-) rename resident/resident-service/src/main/java/io/mosip/resident/{service/impl => constant}/UISchemaTypes.java (94%) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/UISchemaTypes.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/UISchemaTypes.java similarity index 94% rename from resident/resident-service/src/main/java/io/mosip/resident/service/impl/UISchemaTypes.java rename to resident/resident-service/src/main/java/io/mosip/resident/constant/UISchemaTypes.java index f85d2e59adf..c89f681daea 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/UISchemaTypes.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/UISchemaTypes.java @@ -1,11 +1,9 @@ -package io.mosip.resident.service.impl; +package io.mosip.resident.constant; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import io.mosip.resident.constant.RequestType; - public enum UISchemaTypes { UPDATE_DEMOGRAPHICS("update-demographics", RequestType.UPDATE_MY_UIN), PERSONALIZED_CARD("personalized-card", RequestType.DOWNLOAD_PERSONALIZED_CARD), diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java index 9d1d8e6c5e8..b29dbfcca03 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java @@ -28,8 +28,8 @@ import io.mosip.kernel.core.http.ResponseFilter; import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.RequestIdType; -import io.mosip.resident.constant.RequestType; import io.mosip.resident.constant.ResidentConstants; +import io.mosip.resident.constant.UISchemaTypes; import io.mosip.resident.dto.CredentialCancelRequestResponseDto; import io.mosip.resident.dto.CredentialRequestStatusResponseDto; import io.mosip.resident.dto.CredentialTypeResponse; @@ -44,7 +44,6 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.service.ResidentCredentialService; import io.mosip.resident.service.impl.ResidentConfigServiceImpl; -import io.mosip.resident.service.impl.UISchemaTypes; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.EventEnum; import io.mosip.resident.validator.RequestValidator; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java index 817b6254ef2..a504b3f276c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java @@ -30,6 +30,7 @@ import io.mosip.resident.constant.ServiceType; import io.mosip.resident.constant.TemplateType; import io.mosip.resident.constant.TemplateVariablesConstants; +import io.mosip.resident.constant.UISchemaTypes; import io.mosip.resident.dto.NotificationTemplateVariableDTO; import io.mosip.resident.entity.ResidentTransactionEntity; import io.mosip.resident.exception.ApisResourceAccessException; @@ -41,7 +42,6 @@ import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.service.impl.ProxyPartnerManagementServiceImpl; import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.service.impl.UISchemaTypes; import reactor.util.function.Tuple2; import reactor.util.function.Tuples; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index f39c6b71144..86604785c5d 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -1,6 +1,34 @@ package io.mosip.resident.validator; +import static io.mosip.resident.constant.RegistrationConstants.MESSAGE_CODE; +import static io.mosip.resident.service.impl.ResidentOtpServiceImpl.EMAIL_CHANNEL; +import static io.mosip.resident.service.impl.ResidentOtpServiceImpl.PHONE_CHANNEL; + +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.annotation.PostConstruct; +import javax.validation.Valid; + +import org.json.simple.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + import com.fasterxml.jackson.databind.ObjectMapper; + import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.kernel.core.idvalidator.exception.InvalidIDException; import io.mosip.kernel.core.idvalidator.spi.RidValidator; @@ -19,6 +47,7 @@ import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.constant.ServiceType; import io.mosip.resident.constant.TemplateVariablesConstants; +import io.mosip.resident.constant.UISchemaTypes; import io.mosip.resident.dto.AidStatusRequestDTO; import io.mosip.resident.dto.AuthHistoryRequestDTO; import io.mosip.resident.dto.AuthLockOrUnLockRequestDto; @@ -55,38 +84,11 @@ import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.ProxyMasterdataService; import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ProxyMasterdataServiceImpl; import io.mosip.resident.service.impl.ResidentConfigServiceImpl; import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.service.impl.UISchemaTypes; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.EventEnum; import io.mosip.resident.util.Utilities; -import org.json.simple.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.validation.Valid; -import java.io.IOException; -import java.time.Instant; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static io.mosip.resident.constant.RegistrationConstants.MESSAGE_CODE; -import static io.mosip.resident.service.impl.ResidentOtpServiceImpl.EMAIL_CHANNEL; -import static io.mosip.resident.service.impl.ResidentOtpServiceImpl.PHONE_CHANNEL; @Component public class RequestValidator { From 7e12634147808cd639bc8ce821c8653aa2258f6c Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 13:54:14 +0530 Subject: [PATCH 02/11] updated package of validation test calsses --- .../RequestHandlerRequestValidatorTest.java | 1009 ++++++++--------- .../validator/RequestValidatorTest.java | 54 +- 2 files changed, 531 insertions(+), 532 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/validator/RequestHandlerRequestValidatorTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/validator/RequestValidatorTest.java (99%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestHandlerRequestValidatorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestHandlerRequestValidatorTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java index 9fe2c5d5fb0..c85a331d961 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestHandlerRequestValidatorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java @@ -1,505 +1,504 @@ -package io.mosip.resident.test.validator; - -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.assertj.core.util.Lists; -import org.json.simple.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import io.mosip.kernel.core.exception.BaseCheckedException; -import io.mosip.kernel.core.exception.ServiceError; -import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.kernel.core.idvalidator.exception.InvalidIDException; -import io.mosip.kernel.core.idvalidator.spi.UinValidator; -import io.mosip.kernel.core.idvalidator.spi.VidValidator; -import io.mosip.resident.constant.CardType; -import io.mosip.resident.dto.LogDescription; -import io.mosip.resident.dto.MachineDto; -import io.mosip.resident.dto.MachineResponseDto; -import io.mosip.resident.dto.RegistrationCenterDto; -import io.mosip.resident.dto.RegistrationCenterResponseDto; -import io.mosip.resident.dto.RegistrationType; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.IdRepoAppException; -import io.mosip.resident.exception.RequestHandlerValidationException; -import io.mosip.resident.exception.VidCreationException; -import io.mosip.resident.util.ResidentServiceRestClient; -import io.mosip.resident.util.Utilities; -import io.mosip.resident.validator.RequestHandlerRequestValidator; - -@RunWith(SpringRunner.class) -public class RequestHandlerRequestValidatorTest { - - @InjectMocks - private RequestHandlerRequestValidator requestHandlerRequestValidator; - - /** The rest client service. */ - @Mock - private ResidentServiceRestClient restClientService; - - /** The mapper. */ - @Mock - private ObjectMapper mapper = new ObjectMapper(); - - @Mock - private UinValidator uinValidatorImpl; - - /** The vid validator impl. */ - @Mock - private VidValidator vidValidatorImpl; - - /** The utilities. */ - @Mock - private Utilities utilities; - - @Mock - private Environment env; - - private static final String ID = "110011"; - - @Before - public void setup() throws ApisResourceAccessException, IOException { - Mockito.when(env.getProperty("mosip.mandatory-languages")).thenReturn("eng"); - Mockito.when(restClientService.getApi(any(), any(), anyString(), anyString(), any(Class.class))).thenReturn(new ResponseWrapper<>()); - Mockito.when(mapper.writeValueAsString(any())).thenReturn("String"); - } - - @Test(expected = RequestHandlerValidationException.class) - public void testValidateWithRequestHandlerValidationException() throws RequestHandlerValidationException { - requestHandlerRequestValidator.validate(ID); - } - - @Test(expected = RequestHandlerValidationException.class) - public void testValidateNullId() throws RequestHandlerValidationException { - requestHandlerRequestValidator.validate(null); - } - - @Test - public void testIsValidCenter() throws BaseCheckedException, IOException { - RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); - RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); - rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); - - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); - - boolean result = requestHandlerRequestValidator.isValidCenter(ID); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCenterNestedElse() throws BaseCheckedException, IOException { - RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); - rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); - - requestHandlerRequestValidator.isValidCenter(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCenterElse() throws BaseCheckedException, IOException { - requestHandlerRequestValidator.isValidCenter(""); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCenterElse2() throws BaseCheckedException, IOException { - requestHandlerRequestValidator.isValidCenter(null); - } - - @Test - public void testIsValidCenterWithApisResourceAccessException() throws BaseCheckedException, IOException { - RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); - rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error")); -// when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error", new HttpClientErrorException(HttpStatus.OK))); -// Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenThrow(ApisResourceAccessException.class); - - requestHandlerRequestValidator.isValidCenter(ID); - } - - @Test - public void testIsValidMachine() throws BaseCheckedException, IOException { - MachineDto registrationCenterDto = new MachineDto(); - MachineResponseDto machinedto = new MachineResponseDto(); - machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); - - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); - - boolean result = requestHandlerRequestValidator.isValidMachine(ID); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidMachineNestedElse() throws BaseCheckedException, IOException{ - MachineDto registrationCenterDto = new MachineDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - MachineResponseDto machinedto = new MachineResponseDto(); - machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); - - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); - - requestHandlerRequestValidator.isValidMachine(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidMachineElse() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidMachine(null); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidMachineElse2() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidMachine(""); - } - - @Test - public void testIsValidMachineWithApisResourceAccessException() throws BaseCheckedException, IOException{ - MachineDto registrationCenterDto = new MachineDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - MachineResponseDto machinedto = new MachineResponseDto(); - machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); - - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error")); -// when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error", new HttpClientErrorException(HttpStatus.OK))); -// Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenThrow(ApisResourceAccessException.class); - - requestHandlerRequestValidator.isValidMachine(ID); - } - - @Test - public void testIsValidUin() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); - - boolean result = requestHandlerRequestValidator.isValidUin("1234"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinElse1() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinElse2() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - when(uinValidatorImpl.validateId(anyString())).thenReturn(false); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithInvalidIDException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithIdRepoAppException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithNumberFormatException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new NumberFormatException("errorcode")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithApisResourceAccessException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new ApisResourceAccessException("errorcode")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithIOException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IOException("errorcode")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test - public void testIsValidRePrintRegistrationType() throws BaseCheckedException, IOException { - boolean result = requestHandlerRequestValidator.isValidRePrintRegistrationType(RegistrationType.RES_REPRINT.name()); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRePrintRegistrationTypeElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidRePrintRegistrationType("LOST"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRePrintRegistrationTypeElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidRePrintRegistrationType(null); - } - - @Test - public void testIsValidRegistrationTypeAndUinNestedNestedIf11() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - JSONObject idObject=new JSONObject(); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(idObject); - boolean result=requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedNestedIf12() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedNestedIf13() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("any status"); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(new JSONObject()); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test - public void testIsValidRegistrationTypeAndUinNestedNestedIf21() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - boolean result=requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.DEACTIVATED.name(), "1234"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedNestedElse21() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedElse() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(false); - - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinElse1() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(null, "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinElse2() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidRegistrationTypeAndUin("any registration", "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinWithInvalidIDException() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinWithNumberFormatException() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new NumberFormatException("message")); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test - public void testIsValidVid() throws BaseCheckedException, IOException{ - String str="vid"; - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenReturn(str); - boolean result=requestHandlerRequestValidator.isValidVid(ID); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidElse() throws BaseCheckedException, IOException{ - String str="vid"; - when(vidValidatorImpl.validateId(anyString())).thenReturn(false); - when(utilities.getUinByVid(anyString())).thenReturn(str); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidElse2() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenReturn(null); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithInvalidIDException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithIdRepoAppException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithNumberFormatException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new NumberFormatException("message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithApisResourceAccessException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new ApisResourceAccessException("message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithVidCreationException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new VidCreationException("message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test - public void testIsValidIdType() throws Exception{ - boolean result=requestHandlerRequestValidator.isValidIdType("UIN"); - assertTrue(result); - } - - @Test - public void testIsValidIdType2() throws BaseCheckedException { - boolean result = requestHandlerRequestValidator.isValidIdType("VID"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidIdTypeElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidIdType(null); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidIdTypeElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidIdType(""); - } - - @Test - public void testIsValidCardType() throws BaseCheckedException, IOException { - boolean result = requestHandlerRequestValidator.isValidCardType(CardType.MASKED_UIN.name()); - assertTrue(result); - } - - @Test - public void testIsValidCardType2() throws BaseCheckedException, IOException { - boolean result = requestHandlerRequestValidator.isValidCardType(CardType.UIN.name()); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCardTypeElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidCardType("voter-id"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCardTypeElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidCardType(""); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCardTypeElse3() throws BaseCheckedException { - requestHandlerRequestValidator.isValidCardType(null); - } - - @Test - public void testIsValidContact() throws BaseCheckedException, IOException { - String EMAIL = "Email"; - boolean result = requestHandlerRequestValidator.isValidContactType(EMAIL, new LogDescription()); - assertTrue(result); - } - - @Test - public void testIsValidContact2() throws BaseCheckedException, IOException { - String PHONE = "Phone"; - boolean result = requestHandlerRequestValidator.isValidContactType(PHONE, new LogDescription()); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidContactElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidContactType("whatsapp", new LogDescription()); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidContactElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidContactType(null, new LogDescription()); - } -} +package io.mosip.resident.validator; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.assertj.core.util.Lists; +import org.json.simple.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.mosip.kernel.core.exception.BaseCheckedException; +import io.mosip.kernel.core.exception.ServiceError; +import io.mosip.kernel.core.http.ResponseWrapper; +import io.mosip.kernel.core.idvalidator.exception.InvalidIDException; +import io.mosip.kernel.core.idvalidator.spi.UinValidator; +import io.mosip.kernel.core.idvalidator.spi.VidValidator; +import io.mosip.resident.constant.CardType; +import io.mosip.resident.dto.LogDescription; +import io.mosip.resident.dto.MachineDto; +import io.mosip.resident.dto.MachineResponseDto; +import io.mosip.resident.dto.RegistrationCenterDto; +import io.mosip.resident.dto.RegistrationCenterResponseDto; +import io.mosip.resident.dto.RegistrationType; +import io.mosip.resident.exception.ApisResourceAccessException; +import io.mosip.resident.exception.IdRepoAppException; +import io.mosip.resident.exception.RequestHandlerValidationException; +import io.mosip.resident.exception.VidCreationException; +import io.mosip.resident.util.ResidentServiceRestClient; +import io.mosip.resident.util.Utilities; + +@RunWith(SpringRunner.class) +public class RequestHandlerRequestValidatorTest { + + @InjectMocks + private RequestHandlerRequestValidator requestHandlerRequestValidator; + + /** The rest client service. */ + @Mock + private ResidentServiceRestClient restClientService; + + /** The mapper. */ + @Mock + private ObjectMapper mapper = new ObjectMapper(); + + @Mock + private UinValidator uinValidatorImpl; + + /** The vid validator impl. */ + @Mock + private VidValidator vidValidatorImpl; + + /** The utilities. */ + @Mock + private Utilities utilities; + + @Mock + private Environment env; + + private static final String ID = "110011"; + + @Before + public void setup() throws ApisResourceAccessException, IOException { + Mockito.when(env.getProperty("mosip.mandatory-languages")).thenReturn("eng"); + Mockito.when(restClientService.getApi(any(), any(), anyString(), anyString(), any(Class.class))).thenReturn(new ResponseWrapper<>()); + Mockito.when(mapper.writeValueAsString(any())).thenReturn("String"); + } + + @Test(expected = RequestHandlerValidationException.class) + public void testValidateWithRequestHandlerValidationException() throws RequestHandlerValidationException { + requestHandlerRequestValidator.validate(ID); + } + + @Test(expected = RequestHandlerValidationException.class) + public void testValidateNullId() throws RequestHandlerValidationException { + requestHandlerRequestValidator.validate(null); + } + + @Test + public void testIsValidCenter() throws BaseCheckedException, IOException { + RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); + RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); + rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); + + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); + + boolean result = requestHandlerRequestValidator.isValidCenter(ID); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCenterNestedElse() throws BaseCheckedException, IOException { + RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); + ServiceError error=new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList=new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper=new ResponseWrapper<>(); + wrapper.setErrors(errorList); + RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); + rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); + + requestHandlerRequestValidator.isValidCenter(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCenterElse() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidCenter(""); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCenterElse2() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidCenter(null); + } + + @Test + public void testIsValidCenterWithApisResourceAccessException() throws BaseCheckedException, IOException { + RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); + ServiceError error=new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList=new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper=new ResponseWrapper<>(); + wrapper.setErrors(errorList); + RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); + rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error")); +// when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error", new HttpClientErrorException(HttpStatus.OK))); +// Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenThrow(ApisResourceAccessException.class); + + requestHandlerRequestValidator.isValidCenter(ID); + } + + @Test + public void testIsValidMachine() throws BaseCheckedException, IOException { + MachineDto registrationCenterDto = new MachineDto(); + MachineResponseDto machinedto = new MachineResponseDto(); + machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); + + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); + + boolean result = requestHandlerRequestValidator.isValidMachine(ID); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidMachineNestedElse() throws BaseCheckedException, IOException{ + MachineDto registrationCenterDto = new MachineDto(); + ServiceError error=new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList=new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper=new ResponseWrapper<>(); + wrapper.setErrors(errorList); + MachineResponseDto machinedto = new MachineResponseDto(); + machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); + + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); + + requestHandlerRequestValidator.isValidMachine(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidMachineElse() throws BaseCheckedException, IOException{ + requestHandlerRequestValidator.isValidMachine(null); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidMachineElse2() throws BaseCheckedException, IOException{ + requestHandlerRequestValidator.isValidMachine(""); + } + + @Test + public void testIsValidMachineWithApisResourceAccessException() throws BaseCheckedException, IOException{ + MachineDto registrationCenterDto = new MachineDto(); + ServiceError error=new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList=new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper=new ResponseWrapper<>(); + wrapper.setErrors(errorList); + MachineResponseDto machinedto = new MachineResponseDto(); + machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); + + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error")); +// when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error", new HttpClientErrorException(HttpStatus.OK))); +// Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenThrow(ApisResourceAccessException.class); + + requestHandlerRequestValidator.isValidMachine(ID); + } + + @Test + public void testIsValidUin() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); + + boolean result = requestHandlerRequestValidator.isValidUin("1234"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinElse1() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinElse2() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + when(uinValidatorImpl.validateId(anyString())).thenReturn(false); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithInvalidIDException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithIdRepoAppException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithNumberFormatException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new NumberFormatException("errorcode")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithApisResourceAccessException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new ApisResourceAccessException("errorcode")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithIOException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IOException("errorcode")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test + public void testIsValidRePrintRegistrationType() throws BaseCheckedException, IOException { + boolean result = requestHandlerRequestValidator.isValidRePrintRegistrationType(RegistrationType.RES_REPRINT.name()); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRePrintRegistrationTypeElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidRePrintRegistrationType("LOST"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRePrintRegistrationTypeElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidRePrintRegistrationType(null); + } + + @Test + public void testIsValidRegistrationTypeAndUinNestedNestedIf11() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + JSONObject idObject=new JSONObject(); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(idObject); + boolean result=requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedNestedIf12() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedNestedIf13() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("any status"); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(new JSONObject()); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test + public void testIsValidRegistrationTypeAndUinNestedNestedIf21() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + boolean result=requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.DEACTIVATED.name(), "1234"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedNestedElse21() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedElse() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(false); + + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinElse1() throws BaseCheckedException, IOException{ + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(null, "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinElse2() throws BaseCheckedException, IOException{ + requestHandlerRequestValidator.isValidRegistrationTypeAndUin("any registration", "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinWithInvalidIDException() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinWithNumberFormatException() throws BaseCheckedException, IOException{ + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new NumberFormatException("message")); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test + public void testIsValidVid() throws BaseCheckedException, IOException{ + String str="vid"; + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenReturn(str); + boolean result=requestHandlerRequestValidator.isValidVid(ID); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidElse() throws BaseCheckedException, IOException{ + String str="vid"; + when(vidValidatorImpl.validateId(anyString())).thenReturn(false); + when(utilities.getUinByVid(anyString())).thenReturn(str); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidElse2() throws BaseCheckedException, IOException{ + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenReturn(null); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithInvalidIDException() throws BaseCheckedException, IOException{ + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithIdRepoAppException() throws BaseCheckedException, IOException{ + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithNumberFormatException() throws BaseCheckedException, IOException{ + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new NumberFormatException("message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithApisResourceAccessException() throws BaseCheckedException, IOException{ + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new ApisResourceAccessException("message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithVidCreationException() throws BaseCheckedException, IOException{ + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new VidCreationException("message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test + public void testIsValidIdType() throws Exception{ + boolean result=requestHandlerRequestValidator.isValidIdType("UIN"); + assertTrue(result); + } + + @Test + public void testIsValidIdType2() throws BaseCheckedException { + boolean result = requestHandlerRequestValidator.isValidIdType("VID"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidIdTypeElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidIdType(null); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidIdTypeElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidIdType(""); + } + + @Test + public void testIsValidCardType() throws BaseCheckedException, IOException { + boolean result = requestHandlerRequestValidator.isValidCardType(CardType.MASKED_UIN.name()); + assertTrue(result); + } + + @Test + public void testIsValidCardType2() throws BaseCheckedException, IOException { + boolean result = requestHandlerRequestValidator.isValidCardType(CardType.UIN.name()); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCardTypeElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidCardType("voter-id"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCardTypeElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidCardType(""); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCardTypeElse3() throws BaseCheckedException { + requestHandlerRequestValidator.isValidCardType(null); + } + + @Test + public void testIsValidContact() throws BaseCheckedException, IOException { + String EMAIL = "Email"; + boolean result = requestHandlerRequestValidator.isValidContactType(EMAIL, new LogDescription()); + assertTrue(result); + } + + @Test + public void testIsValidContact2() throws BaseCheckedException, IOException { + String PHONE = "Phone"; + boolean result = requestHandlerRequestValidator.isValidContactType(PHONE, new LogDescription()); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidContactElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidContactType("whatsapp", new LogDescription()); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidContactElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidContactType(null, new LogDescription()); + } +} diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestValidatorTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/validator/RequestValidatorTest.java index 98e0202dfc0..b5fbaa0dc69 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestValidatorTest.java @@ -1,4 +1,30 @@ -package io.mosip.resident.test.validator; +package io.mosip.resident.validator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.joda.time.DateTime; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; import io.mosip.kernel.core.idvalidator.exception.InvalidIDException; import io.mosip.kernel.core.idvalidator.spi.RidValidator; @@ -52,32 +78,6 @@ import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.Utilities; -import io.mosip.resident.validator.RequestValidator; -import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.when; @RunWith(SpringRunner.class) public class RequestValidatorTest { From 384a6e3abc05ef8858c9db391542b00af7c8991e Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 13:59:53 +0530 Subject: [PATCH 03/11] updated --- .../resident/validator/RequestHandlerRequestValidatorTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java index c85a331d961..c3653a5df41 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java @@ -41,6 +41,7 @@ import io.mosip.resident.exception.VidCreationException; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilities; +import io.mosip.resident.validator.RequestHandlerRequestValidator; @RunWith(SpringRunner.class) public class RequestHandlerRequestValidatorTest { From 2a44e77ec9b09f4dabfc62bcc9b00c335e4ec312 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:01:14 +0530 Subject: [PATCH 04/11] formatting --- .../RequestHandlerRequestValidatorTest.java | 893 +++++++++--------- 1 file changed, 450 insertions(+), 443 deletions(-) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java index c3653a5df41..64383100983 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/validator/RequestHandlerRequestValidatorTest.java @@ -41,465 +41,472 @@ import io.mosip.resident.exception.VidCreationException; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilities; -import io.mosip.resident.validator.RequestHandlerRequestValidator; @RunWith(SpringRunner.class) public class RequestHandlerRequestValidatorTest { - @InjectMocks - private RequestHandlerRequestValidator requestHandlerRequestValidator; + @InjectMocks + private RequestHandlerRequestValidator requestHandlerRequestValidator; - /** The rest client service. */ - @Mock - private ResidentServiceRestClient restClientService; + /** The rest client service. */ + @Mock + private ResidentServiceRestClient restClientService; - /** The mapper. */ - @Mock - private ObjectMapper mapper = new ObjectMapper(); + /** The mapper. */ + @Mock + private ObjectMapper mapper = new ObjectMapper(); - @Mock - private UinValidator uinValidatorImpl; + @Mock + private UinValidator uinValidatorImpl; - /** The vid validator impl. */ - @Mock - private VidValidator vidValidatorImpl; + /** The vid validator impl. */ + @Mock + private VidValidator vidValidatorImpl; - /** The utilities. */ - @Mock - private Utilities utilities; + /** The utilities. */ + @Mock + private Utilities utilities; - @Mock - private Environment env; + @Mock + private Environment env; - private static final String ID = "110011"; + private static final String ID = "110011"; - @Before - public void setup() throws ApisResourceAccessException, IOException { + @Before + public void setup() throws ApisResourceAccessException, IOException { Mockito.when(env.getProperty("mosip.mandatory-languages")).thenReturn("eng"); - Mockito.when(restClientService.getApi(any(), any(), anyString(), anyString(), any(Class.class))).thenReturn(new ResponseWrapper<>()); - Mockito.when(mapper.writeValueAsString(any())).thenReturn("String"); - } - - @Test(expected = RequestHandlerValidationException.class) - public void testValidateWithRequestHandlerValidationException() throws RequestHandlerValidationException { - requestHandlerRequestValidator.validate(ID); - } - - @Test(expected = RequestHandlerValidationException.class) - public void testValidateNullId() throws RequestHandlerValidationException { - requestHandlerRequestValidator.validate(null); - } - - @Test - public void testIsValidCenter() throws BaseCheckedException, IOException { - RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); - RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); - rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); - - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); - - boolean result = requestHandlerRequestValidator.isValidCenter(ID); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCenterNestedElse() throws BaseCheckedException, IOException { - RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); - rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); - - requestHandlerRequestValidator.isValidCenter(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCenterElse() throws BaseCheckedException, IOException { - requestHandlerRequestValidator.isValidCenter(""); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCenterElse2() throws BaseCheckedException, IOException { - requestHandlerRequestValidator.isValidCenter(null); - } - - @Test - public void testIsValidCenterWithApisResourceAccessException() throws BaseCheckedException, IOException { - RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); - rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error")); + Mockito.when(restClientService.getApi(any(), any(), anyString(), anyString(), any(Class.class))) + .thenReturn(new ResponseWrapper<>()); + Mockito.when(mapper.writeValueAsString(any())).thenReturn("String"); + } + + @Test(expected = RequestHandlerValidationException.class) + public void testValidateWithRequestHandlerValidationException() throws RequestHandlerValidationException { + requestHandlerRequestValidator.validate(ID); + } + + @Test(expected = RequestHandlerValidationException.class) + public void testValidateNullId() throws RequestHandlerValidationException { + requestHandlerRequestValidator.validate(null); + } + + @Test + public void testIsValidCenter() throws BaseCheckedException, IOException { + RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); + RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); + rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); + + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); + + boolean result = requestHandlerRequestValidator.isValidCenter(ID); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCenterNestedElse() throws BaseCheckedException, IOException { + RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); + ServiceError error = new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList = new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper = new ResponseWrapper<>(); + wrapper.setErrors(errorList); + RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); + rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(rcpdto); + + requestHandlerRequestValidator.isValidCenter(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCenterElse() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidCenter(""); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCenterElse2() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidCenter(null); + } + + @Test + public void testIsValidCenterWithApisResourceAccessException() throws BaseCheckedException, IOException { + RegistrationCenterDto registrationCenterDto = new RegistrationCenterDto(); + ServiceError error = new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList = new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper = new ResponseWrapper<>(); + wrapper.setErrors(errorList); + RegistrationCenterResponseDto rcpdto = new RegistrationCenterResponseDto(); + rcpdto.setRegistrationCenters(Lists.newArrayList(registrationCenterDto)); + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())) + .thenThrow(new ApisResourceAccessException("error")); // when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error", new HttpClientErrorException(HttpStatus.OK))); // Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenThrow(ApisResourceAccessException.class); - - requestHandlerRequestValidator.isValidCenter(ID); - } - - @Test - public void testIsValidMachine() throws BaseCheckedException, IOException { - MachineDto registrationCenterDto = new MachineDto(); - MachineResponseDto machinedto = new MachineResponseDto(); - machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); - - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); - - boolean result = requestHandlerRequestValidator.isValidMachine(ID); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidMachineNestedElse() throws BaseCheckedException, IOException{ - MachineDto registrationCenterDto = new MachineDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - MachineResponseDto machinedto = new MachineResponseDto(); - machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); - - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); - Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); - - requestHandlerRequestValidator.isValidMachine(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidMachineElse() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidMachine(null); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidMachineElse2() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidMachine(""); - } - - @Test - public void testIsValidMachineWithApisResourceAccessException() throws BaseCheckedException, IOException{ - MachineDto registrationCenterDto = new MachineDto(); - ServiceError error=new ServiceError(); - error.setErrorCode("invalid-101"); - error.setMessage("invalid center"); - List errorList=new ArrayList(); - errorList.add(error); - ResponseWrapper wrapper=new ResponseWrapper<>(); - wrapper.setErrors(errorList); - MachineResponseDto machinedto = new MachineResponseDto(); - machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); - - when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error")); + + requestHandlerRequestValidator.isValidCenter(ID); + } + + @Test + public void testIsValidMachine() throws BaseCheckedException, IOException { + MachineDto registrationCenterDto = new MachineDto(); + MachineResponseDto machinedto = new MachineResponseDto(); + machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); + + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); + + boolean result = requestHandlerRequestValidator.isValidMachine(ID); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidMachineNestedElse() throws BaseCheckedException, IOException { + MachineDto registrationCenterDto = new MachineDto(); + ServiceError error = new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList = new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper = new ResponseWrapper<>(); + wrapper.setErrors(errorList); + MachineResponseDto machinedto = new MachineResponseDto(); + machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); + + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenReturn(wrapper); + Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenReturn(machinedto); + + requestHandlerRequestValidator.isValidMachine(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidMachineElse() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidMachine(null); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidMachineElse2() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidMachine(""); + } + + @Test + public void testIsValidMachineWithApisResourceAccessException() throws BaseCheckedException, IOException { + MachineDto registrationCenterDto = new MachineDto(); + ServiceError error = new ServiceError(); + error.setErrorCode("invalid-101"); + error.setMessage("invalid center"); + List errorList = new ArrayList(); + errorList.add(error); + ResponseWrapper wrapper = new ResponseWrapper<>(); + wrapper.setErrors(errorList); + MachineResponseDto machinedto = new MachineResponseDto(); + machinedto.setMachines(Lists.newArrayList(registrationCenterDto)); + + when(restClientService.getApi(any(), any(), anyString(), anyString(), any())) + .thenThrow(new ApisResourceAccessException("error")); // when(restClientService.getApi(any(), any(), anyString(), anyString(), any())).thenThrow(new ApisResourceAccessException("error", new HttpClientErrorException(HttpStatus.OK))); // Mockito.when(mapper.readValue(anyString(), any(Class.class))).thenThrow(ApisResourceAccessException.class); - requestHandlerRequestValidator.isValidMachine(ID); - } - - @Test - public void testIsValidUin() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); - - boolean result = requestHandlerRequestValidator.isValidUin("1234"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinElse1() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinElse2() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - when(uinValidatorImpl.validateId(anyString())).thenReturn(false); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithInvalidIDException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithIdRepoAppException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithNumberFormatException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new NumberFormatException("errorcode")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithApisResourceAccessException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new ApisResourceAccessException("errorcode")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidUinWithIOException() throws BaseCheckedException, IOException { - JSONObject jsonObject = new JSONObject(); - Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IOException("errorcode")); - - requestHandlerRequestValidator.isValidUin("1234"); - } - - @Test - public void testIsValidRePrintRegistrationType() throws BaseCheckedException, IOException { - boolean result = requestHandlerRequestValidator.isValidRePrintRegistrationType(RegistrationType.RES_REPRINT.name()); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRePrintRegistrationTypeElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidRePrintRegistrationType("LOST"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRePrintRegistrationTypeElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidRePrintRegistrationType(null); - } - - @Test - public void testIsValidRegistrationTypeAndUinNestedNestedIf11() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - JSONObject idObject=new JSONObject(); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(idObject); - boolean result=requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedNestedIf12() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedNestedIf13() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("any status"); - when(utilities.retrieveIdrepoJson(anyString())).thenReturn(new JSONObject()); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test - public void testIsValidRegistrationTypeAndUinNestedNestedIf21() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - boolean result=requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.DEACTIVATED.name(), "1234"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedNestedElse21() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinNestedElse() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(false); - - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinElse1() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(null, "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinElse2() throws BaseCheckedException, IOException{ - requestHandlerRequestValidator.isValidRegistrationTypeAndUin("any registration", "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinWithInvalidIDException() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidRegistrationTypeAndUinWithNumberFormatException() throws BaseCheckedException, IOException{ - when(uinValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new NumberFormatException("message")); - requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); - } - - @Test - public void testIsValidVid() throws BaseCheckedException, IOException{ - String str="vid"; - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenReturn(str); - boolean result=requestHandlerRequestValidator.isValidVid(ID); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidElse() throws BaseCheckedException, IOException{ - String str="vid"; - when(vidValidatorImpl.validateId(anyString())).thenReturn(false); - when(utilities.getUinByVid(anyString())).thenReturn(str); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidElse2() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenReturn(null); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithInvalidIDException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithIdRepoAppException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithNumberFormatException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new NumberFormatException("message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithApisResourceAccessException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new ApisResourceAccessException("message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidVidWithVidCreationException() throws BaseCheckedException, IOException{ - when(vidValidatorImpl.validateId(anyString())).thenReturn(true); - when(utilities.getUinByVid(anyString())).thenThrow(new VidCreationException("message")); - requestHandlerRequestValidator.isValidVid(ID); - } - - @Test - public void testIsValidIdType() throws Exception{ - boolean result=requestHandlerRequestValidator.isValidIdType("UIN"); - assertTrue(result); - } - - @Test - public void testIsValidIdType2() throws BaseCheckedException { - boolean result = requestHandlerRequestValidator.isValidIdType("VID"); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidIdTypeElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidIdType(null); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidIdTypeElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidIdType(""); - } - - @Test - public void testIsValidCardType() throws BaseCheckedException, IOException { - boolean result = requestHandlerRequestValidator.isValidCardType(CardType.MASKED_UIN.name()); - assertTrue(result); - } - - @Test - public void testIsValidCardType2() throws BaseCheckedException, IOException { - boolean result = requestHandlerRequestValidator.isValidCardType(CardType.UIN.name()); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCardTypeElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidCardType("voter-id"); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCardTypeElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidCardType(""); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidCardTypeElse3() throws BaseCheckedException { - requestHandlerRequestValidator.isValidCardType(null); - } - - @Test - public void testIsValidContact() throws BaseCheckedException, IOException { - String EMAIL = "Email"; - boolean result = requestHandlerRequestValidator.isValidContactType(EMAIL, new LogDescription()); - assertTrue(result); - } - - @Test - public void testIsValidContact2() throws BaseCheckedException, IOException { - String PHONE = "Phone"; - boolean result = requestHandlerRequestValidator.isValidContactType(PHONE, new LogDescription()); - assertTrue(result); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidContactElse() throws BaseCheckedException { - requestHandlerRequestValidator.isValidContactType("whatsapp", new LogDescription()); - } - - @Test(expected = BaseCheckedException.class) - public void testIsValidContactElse2() throws BaseCheckedException { - requestHandlerRequestValidator.isValidContactType(null, new LogDescription()); - } + requestHandlerRequestValidator.isValidMachine(ID); + } + + @Test + public void testIsValidUin() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); + + boolean result = requestHandlerRequestValidator.isValidUin("1234"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinElse1() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinElse2() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + when(uinValidatorImpl.validateId(anyString())).thenReturn(false); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(jsonObject); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithInvalidIDException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())) + .thenThrow(new InvalidIDException("errorcode", "message")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithIdRepoAppException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())) + .thenThrow(new IdRepoAppException("errorcode", "message")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithNumberFormatException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new NumberFormatException("errorcode")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithApisResourceAccessException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new ApisResourceAccessException("errorcode")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidUinWithIOException() throws BaseCheckedException, IOException { + JSONObject jsonObject = new JSONObject(); + Mockito.when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + Mockito.when(utilities.retrieveIdrepoJson(anyString())).thenThrow(new IOException("errorcode")); + + requestHandlerRequestValidator.isValidUin("1234"); + } + + @Test + public void testIsValidRePrintRegistrationType() throws BaseCheckedException, IOException { + boolean result = requestHandlerRequestValidator + .isValidRePrintRegistrationType(RegistrationType.RES_REPRINT.name()); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRePrintRegistrationTypeElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidRePrintRegistrationType("LOST"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRePrintRegistrationTypeElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidRePrintRegistrationType(null); + } + + @Test + public void testIsValidRegistrationTypeAndUinNestedNestedIf11() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + JSONObject idObject = new JSONObject(); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(idObject); + boolean result = requestHandlerRequestValidator + .isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedNestedIf12() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(null); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedNestedIf13() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("any status"); + when(utilities.retrieveIdrepoJson(anyString())).thenReturn(new JSONObject()); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test + public void testIsValidRegistrationTypeAndUinNestedNestedIf21() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + boolean result = requestHandlerRequestValidator + .isValidRegistrationTypeAndUin(RegistrationType.DEACTIVATED.name(), "1234"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedNestedElse21() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenReturn("ACTIVATED"); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinNestedElse() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(false); + + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.ACTIVATED.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinElse1() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(null, "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinElse2() throws BaseCheckedException, IOException { + requestHandlerRequestValidator.isValidRegistrationTypeAndUin("any registration", "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinWithInvalidIDException() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidRegistrationTypeAndUinWithNumberFormatException() throws BaseCheckedException, IOException { + when(uinValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.retrieveIdrepoJsonStatus(anyString())).thenThrow(new NumberFormatException("message")); + requestHandlerRequestValidator.isValidRegistrationTypeAndUin(RegistrationType.RES_UPDATE.name(), "1234"); + } + + @Test + public void testIsValidVid() throws BaseCheckedException, IOException { + String str = "vid"; + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenReturn(str); + boolean result = requestHandlerRequestValidator.isValidVid(ID); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidElse() throws BaseCheckedException, IOException { + String str = "vid"; + when(vidValidatorImpl.validateId(anyString())).thenReturn(false); + when(utilities.getUinByVid(anyString())).thenReturn(str); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidElse2() throws BaseCheckedException, IOException { + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenReturn(null); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithInvalidIDException() throws BaseCheckedException, IOException { + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new InvalidIDException("errorcode", "message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithIdRepoAppException() throws BaseCheckedException, IOException { + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new IdRepoAppException("errorcode", "message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithNumberFormatException() throws BaseCheckedException, IOException { + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new NumberFormatException("message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithApisResourceAccessException() throws BaseCheckedException, IOException { + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new ApisResourceAccessException("message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidVidWithVidCreationException() throws BaseCheckedException, IOException { + when(vidValidatorImpl.validateId(anyString())).thenReturn(true); + when(utilities.getUinByVid(anyString())).thenThrow(new VidCreationException("message")); + requestHandlerRequestValidator.isValidVid(ID); + } + + @Test + public void testIsValidIdType() throws Exception { + boolean result = requestHandlerRequestValidator.isValidIdType("UIN"); + assertTrue(result); + } + + @Test + public void testIsValidIdType2() throws BaseCheckedException { + boolean result = requestHandlerRequestValidator.isValidIdType("VID"); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidIdTypeElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidIdType(null); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidIdTypeElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidIdType(""); + } + + @Test + public void testIsValidCardType() throws BaseCheckedException, IOException { + boolean result = requestHandlerRequestValidator.isValidCardType(CardType.MASKED_UIN.name()); + assertTrue(result); + } + + @Test + public void testIsValidCardType2() throws BaseCheckedException, IOException { + boolean result = requestHandlerRequestValidator.isValidCardType(CardType.UIN.name()); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCardTypeElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidCardType("voter-id"); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCardTypeElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidCardType(""); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidCardTypeElse3() throws BaseCheckedException { + requestHandlerRequestValidator.isValidCardType(null); + } + + @Test + public void testIsValidContact() throws BaseCheckedException, IOException { + String EMAIL = "Email"; + boolean result = requestHandlerRequestValidator.isValidContactType(EMAIL, new LogDescription()); + assertTrue(result); + } + + @Test + public void testIsValidContact2() throws BaseCheckedException, IOException { + String PHONE = "Phone"; + boolean result = requestHandlerRequestValidator.isValidContactType(PHONE, new LogDescription()); + assertTrue(result); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidContactElse() throws BaseCheckedException { + requestHandlerRequestValidator.isValidContactType("whatsapp", new LogDescription()); + } + + @Test(expected = BaseCheckedException.class) + public void testIsValidContactElse2() throws BaseCheckedException { + requestHandlerRequestValidator.isValidContactType(null, new LogDescription()); + } } From 140ece57c408b3c5d2afed05e3331ec568ca92bb Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:12:08 +0530 Subject: [PATCH 05/11] updated packages of controller test classes --- .../AcknowledgmentControllerTest.java | 50 +- ...AuthTransactionCallbackControllerTest.java | 48 +- .../controller/DocumentControllerTest.java | 4 +- .../DownloadCardControllerTest.java | 58 +- .../DownloadMasterdataControllerTest.java | 50 +- .../controller/GrievanceControllerTest.java | 54 +- .../controller/IdAuthControllerTest.java | 5 +- .../controller/IdentityControllerTest.java | 5 +- .../controller/OrderCardControllerTest.java | 2 +- .../controller/PinStatusControllerTest.java | 3 +- .../controller/ProxyAuditControllerTest.java | 6 +- .../controller/ProxyConfigControllerTest.java | 7 +- .../ProxyMasterdataControllerTest.java | 4 +- .../controller/ProxyOtpControllerTest.java | 5 +- .../ProxyPartnerManagementControllerTest.java | 3 +- .../controller/ResidentControllerTest.java | 9 +- .../ResidentCredentialControllerTest.java | 3 +- .../controller/ResidentOtpControllerTest.java | 57 +- .../ResidentVerificationControllerTest.java | 3 +- .../controller/ResidentVidControllerTest.java | 1020 ++++++++--------- .../TransliterationControllerTest.java | 3 +- ...bCredentialStatusUpdateControllerTest.java | 6 +- .../WebSubUpdateAuthTypeControllerTest.java | 4 +- 23 files changed, 694 insertions(+), 715 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/AcknowledgmentControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/AuthTransactionCallbackControllerTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/DownloadCardControllerTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/DownloadMasterdataControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/GrievanceControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/IdAuthControllerTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/IdentityControllerTest.java (95%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/OrderCardControllerTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/PinStatusControllerTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ProxyAuditControllerTest.java (94%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ProxyConfigControllerTest.java (92%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ProxyMasterdataControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ProxyOtpControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ProxyPartnerManagementControllerTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ResidentControllerTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ResidentCredentialControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ResidentOtpControllerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ResidentVerificationControllerTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/ResidentVidControllerTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/TransliterationControllerTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/WebSubCredentialStatusUpdateControllerTest.java (94%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/controller/WebSubUpdateAuthTypeControllerTest.java (96%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/AcknowledgmentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/AcknowledgmentControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/AcknowledgmentControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/AcknowledgmentControllerTest.java index d4280b6a6cf..697e7a5eb5a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/AcknowledgmentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/AcknowledgmentControllerTest.java @@ -1,20 +1,15 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; -import io.mosip.resident.constant.RequestType; -import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.controller.AcknowledgementController; -import io.mosip.resident.exception.InvalidInputException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.AcknowledgementService; -import io.mosip.resident.service.IdAuthService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentVidServiceImpl; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.TemplateUtil; -import io.mosip.resident.util.Utility; -import io.mosip.resident.validator.RequestValidator; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,15 +26,20 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.client.RestTemplate; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; +import io.mosip.resident.constant.RequestType; +import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.exception.InvalidInputException; +import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; +import io.mosip.resident.helper.ObjectStoreHelper; +import io.mosip.resident.service.AcknowledgementService; +import io.mosip.resident.service.IdAuthService; +import io.mosip.resident.service.impl.IdentityServiceImpl; +import io.mosip.resident.service.impl.ResidentVidServiceImpl; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.TemplateUtil; +import io.mosip.resident.util.Utility; +import io.mosip.resident.validator.RequestValidator; /** * Acknowledgment Controller Test diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/AuthTransactionCallbackControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/AuthTransactionCallbackControllerTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/AuthTransactionCallbackControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/AuthTransactionCallbackControllerTest.java index 9903493ad2c..ea6e8b70763 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/AuthTransactionCallbackControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/AuthTransactionCallbackControllerTest.java @@ -1,23 +1,12 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; + +import java.time.LocalDateTime; +import java.util.Map; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.mosip.kernel.core.websub.model.Event; -import io.mosip.kernel.core.websub.model.EventModel; -import io.mosip.resident.controller.AuthTransactionCallbackController; -import io.mosip.resident.controller.VerificationController; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.AuthTransactionCallBackService; -import io.mosip.resident.service.DocumentService; -import io.mosip.resident.service.IdAuthService; -import io.mosip.resident.service.ProxyIdRepoService; -import io.mosip.resident.service.ResidentVidService; -import io.mosip.resident.service.VerificationService; -import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.service.impl.VerificationServiceImpl; -import io.mosip.resident.test.ResidentTestBootApplication; -import io.mosip.resident.util.AuditUtil; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,12 +26,23 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.client.RestTemplate; -import java.time.LocalDateTime; -import java.util.Map; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; +import io.mosip.kernel.core.websub.model.Event; +import io.mosip.kernel.core.websub.model.EventModel; +import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; +import io.mosip.resident.helper.ObjectStoreHelper; +import io.mosip.resident.service.AuthTransactionCallBackService; +import io.mosip.resident.service.DocumentService; +import io.mosip.resident.service.IdAuthService; +import io.mosip.resident.service.ProxyIdRepoService; +import io.mosip.resident.service.ResidentVidService; +import io.mosip.resident.service.VerificationService; +import io.mosip.resident.service.impl.ResidentServiceImpl; +import io.mosip.resident.service.impl.VerificationServiceImpl; +import io.mosip.resident.test.ResidentTestBootApplication; +import io.mosip.resident.util.AuditUtil; /** * Web-Sub Update Controller Test diff --git a/resident/resident-service/src/test/java/io/mosip/resident/controller/DocumentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/DocumentControllerTest.java index b3bad6e89bf..a766b3a4ef2 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/controller/DocumentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/DocumentControllerTest.java @@ -10,8 +10,6 @@ import java.io.IOException; import java.util.List; -import io.mosip.resident.exception.InvalidInputException; -import io.mosip.resident.exception.ResidentServiceException; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -26,7 +24,9 @@ import io.mosip.resident.dto.DocumentDTO; import io.mosip.resident.dto.DocumentResponseDTO; import io.mosip.resident.dto.ResponseDTO; +import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.DocumentService; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.validator.DocumentValidator; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/DownloadCardControllerTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/DownloadCardControllerTest.java index 0c5e9ddf378..dda60562a6a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/DownloadCardControllerTest.java @@ -1,25 +1,14 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.security.PrivateKey; +import java.security.PublicKey; + +import javax.crypto.SecretKey; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; -import io.mosip.resident.controller.DownloadCardController; -import io.mosip.resident.dto.CheckStatusResponseDTO; -import io.mosip.resident.dto.DownloadCardRequestDTO; -import io.mosip.resident.dto.DownloadPersonalizedCardDto; -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.dto.ResponseWrapper; -import io.mosip.resident.dto.VidDownloadCardResponseDto; -import io.mosip.resident.exception.InvalidInputException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.DownloadCardService; -import io.mosip.resident.service.ResidentVidService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.test.ResidentTestBootApplication; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.Utility; -import io.mosip.resident.validator.RequestValidator; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,15 +29,28 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.client.RestTemplate; -import reactor.util.function.Tuples; -import javax.crypto.SecretKey; -import java.security.PrivateKey; -import java.security.PublicKey; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; +import io.mosip.resident.dto.CheckStatusResponseDTO; +import io.mosip.resident.dto.DownloadCardRequestDTO; +import io.mosip.resident.dto.DownloadPersonalizedCardDto; +import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.dto.ResponseWrapper; +import io.mosip.resident.dto.VidDownloadCardResponseDto; +import io.mosip.resident.exception.InvalidInputException; +import io.mosip.resident.helper.ObjectStoreHelper; +import io.mosip.resident.service.DownloadCardService; +import io.mosip.resident.service.ResidentVidService; +import io.mosip.resident.service.impl.IdentityServiceImpl; +import io.mosip.resident.service.impl.ResidentServiceImpl; +import io.mosip.resident.test.ResidentTestBootApplication; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.Utility; +import io.mosip.resident.validator.RequestValidator; +import reactor.util.function.Tuples; /** * @author Kamesh Shekhar Prasad diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadMasterdataControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/DownloadMasterdataControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadMasterdataControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/DownloadMasterdataControllerTest.java index 9c63b230df2..5335d40f0e7 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadMasterdataControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/DownloadMasterdataControllerTest.java @@ -1,21 +1,15 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.ByteArrayInputStream; +import java.security.PrivateKey; +import java.security.PublicKey; + +import javax.crypto.SecretKey; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; -import io.mosip.resident.controller.DownLoadMasterDataController; -import io.mosip.resident.dto.DownloadCardRequestDTO; -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.exception.InvalidInputException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.DownLoadMasterDataService; -import io.mosip.resident.service.ResidentVidService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.test.ResidentTestBootApplication; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.Utility; -import io.mosip.resident.validator.RequestValidator; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,14 +30,22 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.client.RestTemplate; -import javax.crypto.SecretKey; -import java.io.ByteArrayInputStream; -import java.security.PrivateKey; -import java.security.PublicKey; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; +import io.mosip.resident.dto.DownloadCardRequestDTO; +import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.exception.InvalidInputException; +import io.mosip.resident.helper.ObjectStoreHelper; +import io.mosip.resident.service.DownLoadMasterDataService; +import io.mosip.resident.service.ResidentVidService; +import io.mosip.resident.service.impl.IdentityServiceImpl; +import io.mosip.resident.service.impl.ResidentServiceImpl; +import io.mosip.resident.test.ResidentTestBootApplication; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.Utility; +import io.mosip.resident.validator.RequestValidator; /** * @author Kamesh Shekhar Prasad diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/GrievanceControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/GrievanceControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/GrievanceControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/GrievanceControllerTest.java index 7ae4c7f1c6e..ba1dd60fce8 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/GrievanceControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/GrievanceControllerTest.java @@ -1,23 +1,15 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; + +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.HashMap; +import java.util.UUID; + +import javax.crypto.SecretKey; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; -import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.kernel.core.util.DateUtils; -import io.mosip.resident.controller.GrievanceController; -import io.mosip.resident.dto.GrievanceRequestDTO; -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.exception.InvalidInputException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.GrievanceService; -import io.mosip.resident.service.ResidentVidService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.test.ResidentTestBootApplication; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.Utility; -import io.mosip.resident.validator.RequestValidator; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -36,14 +28,24 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.client.RestTemplate; -import javax.crypto.SecretKey; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.util.HashMap; -import java.util.UUID; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; +import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; +import io.mosip.kernel.core.http.ResponseWrapper; +import io.mosip.kernel.core.util.DateUtils; +import io.mosip.resident.dto.GrievanceRequestDTO; +import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.exception.InvalidInputException; +import io.mosip.resident.helper.ObjectStoreHelper; +import io.mosip.resident.service.GrievanceService; +import io.mosip.resident.service.ResidentVidService; +import io.mosip.resident.service.impl.IdentityServiceImpl; +import io.mosip.resident.service.impl.ResidentServiceImpl; +import io.mosip.resident.test.ResidentTestBootApplication; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.Utility; +import io.mosip.resident.validator.RequestValidator; /** * @author Kamesh Shekhar Prasad diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/IdAuthControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/IdAuthControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java index 6ec5e9d3948..e00d3c0a430 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/IdAuthControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java @@ -1,8 +1,7 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import io.mosip.resident.exception.OtpValidationFailedException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,9 +24,9 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import io.mosip.resident.controller.IdAuthController; import io.mosip.resident.dto.IdAuthRequestDto; import io.mosip.resident.dto.RequestWrapper; +import io.mosip.resident.exception.OtpValidationFailedException; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DocumentService; import io.mosip.resident.service.ProxyIdRepoService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/IdentityControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/IdentityControllerTest.java similarity index 95% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/IdentityControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/IdentityControllerTest.java index d4f7800773e..8224cb34f8b 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/IdentityControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/IdentityControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -31,9 +31,6 @@ import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.resident.controller.DocumentController; -import io.mosip.resident.controller.IdAuthController; -import io.mosip.resident.controller.IdentityController; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceCheckedException; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/OrderCardControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/OrderCardControllerTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/OrderCardControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/OrderCardControllerTest.java index 4dbfa255ce3..55dc2ed7804 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/OrderCardControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/OrderCardControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/PinStatusControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/PinStatusControllerTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/PinStatusControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/PinStatusControllerTest.java index 8af474969ce..f52d045edf6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/PinStatusControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/PinStatusControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.junit.Assert.assertEquals; @@ -13,7 +13,6 @@ import org.springframework.test.context.ContextConfiguration; import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.resident.controller.PinStatusController; import io.mosip.resident.dto.ResponseDTO; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.service.PinUnpinStatusService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyAuditControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyAuditControllerTest.java similarity index 94% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyAuditControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyAuditControllerTest.java index 471bcf26557..45f408e8de4 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyAuditControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyAuditControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -29,10 +29,6 @@ import com.google.gson.GsonBuilder; import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; -import io.mosip.resident.controller.AuthTransactionCallbackController; -import io.mosip.resident.controller.DocumentController; -import io.mosip.resident.controller.IdAuthController; -import io.mosip.resident.controller.ProxyAuditController; import io.mosip.resident.dto.AuthenticatedAuditRequestDto; import io.mosip.resident.dto.UnauthenticatedAuditRequestDto; import io.mosip.resident.helper.ObjectStoreHelper; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyConfigControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyConfigControllerTest.java similarity index 92% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyConfigControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyConfigControllerTest.java index be2160d6bf1..b373845f26b 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyConfigControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyConfigControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -26,11 +26,6 @@ import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.resident.controller.DocumentController; -import io.mosip.resident.controller.IdAuthController; -import io.mosip.resident.controller.IdentityController; -import io.mosip.resident.controller.ProxyConfigController; -import io.mosip.resident.controller.ResidentController; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.ProxyIdRepoService; import io.mosip.resident.service.ResidentVidService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterdataControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterdataControllerTest.java index f05e7c95319..1d382e15492 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterdataControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -27,8 +27,6 @@ import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.resident.controller.AcknowledgementController; -import io.mosip.resident.controller.ProxyMasterdataController; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DocumentService; import io.mosip.resident.service.ProxyIdRepoService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyOtpControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyOtpControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyOtpControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyOtpControllerTest.java index a50e6eb1c58..de8f09772bb 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyOtpControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyOtpControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.mockito.Mockito.doThrow; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -8,7 +8,6 @@ import javax.crypto.SecretKey; -import io.mosip.resident.exception.ApisResourceAccessException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,11 +37,11 @@ import io.mosip.kernel.core.authmanager.model.AuthNResponse; import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; import io.mosip.preregistration.application.constant.PreRegLoginConstant; -import io.mosip.resident.controller.ProxyOtpController; import io.mosip.resident.dto.MainRequestDTO; import io.mosip.resident.dto.MainResponseDTO; import io.mosip.resident.dto.OtpRequestDTOV2; import io.mosip.resident.dto.OtpRequestDTOV3; +import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.helper.ObjectStoreHelper; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyPartnerManagementControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyPartnerManagementControllerTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyPartnerManagementControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyPartnerManagementControllerTest.java index b6c7a9eaac5..342133a488a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyPartnerManagementControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyPartnerManagementControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -28,7 +28,6 @@ import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.resident.controller.ProxyPartnerManagementController; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DocumentService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java index 8d4c99241ec..c5f9556aa1b 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; @@ -24,9 +24,6 @@ import javax.crypto.SecretKey; -import io.mosip.resident.exception.CardNotReadyException; -import io.mosip.resident.exception.InvalidInputException; -import io.mosip.resident.exception.ResidentServiceException; import org.json.simple.JSONObject; import org.junit.Before; import org.junit.Test; @@ -66,7 +63,6 @@ import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.constant.ServiceType; -import io.mosip.resident.controller.ResidentController; import io.mosip.resident.dto.AidStatusRequestDTO; import io.mosip.resident.dto.AidStatusResponseDTO; import io.mosip.resident.dto.AuthHistoryRequestDTO; @@ -93,7 +89,10 @@ import io.mosip.resident.dto.UnreadNotificationDto; import io.mosip.resident.dto.UserInfoDto; import io.mosip.resident.exception.ApisResourceAccessException; +import io.mosip.resident.exception.CardNotReadyException; +import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DocumentService; import io.mosip.resident.service.ProxyIdRepoService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentCredentialControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentCredentialControllerTest.java index f286523fee6..ea3088ee31c 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentCredentialControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -33,7 +33,6 @@ import io.mosip.kernel.cbeffutil.impl.CbeffImpl; import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; -import io.mosip.resident.controller.ResidentCredentialController; import io.mosip.resident.dto.CredentialCancelRequestResponseDto; import io.mosip.resident.dto.CredentialRequestStatusResponseDto; import io.mosip.resident.dto.PartnerCredentialTypePolicyDto; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentOtpControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentOtpControllerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentOtpControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentOtpControllerTest.java index 634fb85a51e..5c1e5e747bb 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentOtpControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentOtpControllerTest.java @@ -1,8 +1,35 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithUserDetails; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.client.RestTemplate; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import io.mosip.resident.controller.ResidentOtpController; + import io.mosip.resident.dto.IndividualIdOtpRequestDTO; import io.mosip.resident.dto.IndividualIdResponseDto; import io.mosip.resident.dto.OtpRequestDTO; @@ -24,32 +51,6 @@ import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utility; import io.mosip.resident.validator.RequestValidator; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithUserDetails; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.client.RestTemplate; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringRunner.class) @SpringBootTest(classes = ResidentTestBootApplication.class) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentVerificationControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentVerificationControllerTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentVerificationControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentVerificationControllerTest.java index c70ff4302cf..a3d5b20fa7a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentVerificationControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentVerificationControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -21,7 +21,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.client.RestTemplate; -import io.mosip.resident.controller.VerificationController; import io.mosip.resident.dto.VerificationResponseDTO; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DocumentService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentVidControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentVidControllerTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentVidControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentVidControllerTest.java index 0bf54354114..6ce12d495fe 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentVidControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentVidControllerTest.java @@ -1,510 +1,510 @@ -package io.mosip.resident.test.controller; - -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.core.env.Environment; -import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithUserDetails; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.web.client.RestTemplate; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import io.mosip.kernel.core.util.DateUtils; -import io.mosip.resident.dto.BaseVidRequestDto; -import io.mosip.resident.dto.RequestWrapper; -import io.mosip.resident.dto.ResidentVidRequestDto; -import io.mosip.resident.dto.ResponseWrapper; -import io.mosip.resident.dto.VidRequestDto; -import io.mosip.resident.dto.VidResponseDto; -import io.mosip.resident.dto.VidRevokeRequestDTO; -import io.mosip.resident.dto.VidRevokeResponseDTO; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.OtpValidationFailedException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.VidCreationException; -import io.mosip.resident.exception.VidRevocationException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.DocumentService; -import io.mosip.resident.service.ProxyIdRepoService; -import io.mosip.resident.service.impl.IdAuthServiceImpl; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.service.impl.ResidentVidServiceImpl; -import io.mosip.resident.test.ResidentTestBootApplication; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.ResidentServiceRestClient; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ResidentTestBootApplication.class) -@AutoConfigureMockMvc -@TestPropertySource(locations = "classpath:application.properties") -public class ResidentVidControllerTest { - - @MockBean - private ProxyIdRepoService proxyIdRepoService; - - @MockBean - private ResidentVidServiceImpl residentVidService; - - @MockBean - private IdAuthServiceImpl idAuthService; - - @MockBean - private IdentityServiceImpl identityServiceImpl; - - @MockBean - private ResidentServiceImpl residentService; - - @MockBean - @Qualifier("restClientWithPlainRestTemplate") - private ResidentServiceRestClient residentServiceRestClient; - - @MockBean - private DocumentService docService; - - @MockBean - private ObjectStoreHelper objectStore; - - @MockBean - @Qualifier("selfTokenRestTemplate") - private RestTemplate residentRestTemplate; - - @Mock - private Environment env; - - @Autowired - private MockMvc mockMvc; - - @Mock - private AuditUtil audit; - - @Before - public void setup() throws ApisResourceAccessException { - MockitoAnnotations.initMocks(this); - Mockito.doNothing().when(audit).setAuditRequestDto(Mockito.any()); - Mockito.when(identityServiceImpl.getResidentIndvidualIdFromSession()).thenReturn(null); - } - - @Test - @WithUserDetails("resident") - public void vidCreationSuccessTest() throws Exception { - - VidResponseDto dto = new VidResponseDto(); - dto.setVid("12345"); - dto.setMessage("Successful"); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(dto); - - Mockito.when(residentVidService.generateVid(Mockito.any(), Mockito.anyString())).thenReturn(responseWrapper); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRequest()); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk());// .andExpect(jsonPath("$.response.vid", is("12345"))); - } - - @Test - @WithUserDetails("resident") - public void otpValidationFailureTest() throws Exception { - - Mockito.when(residentVidService.generateVid(Mockito.any(), Mockito.anyString())) - .thenThrow(new OtpValidationFailedException()); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRequest()); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-422"))); - } - - @Test - @WithUserDetails("resident") - public void vidCreationFailureTest() throws Exception { - - Mockito.when(residentVidService.generateVid(Mockito.any(), Mockito.anyString())) - .thenThrow(new VidCreationException()); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRequest()); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-406"))); - } - - @Test - @WithUserDetails("resident") - public void invalidId() throws Exception { - - ResidentVidRequestDto request = getRequest(); - request.setId(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("resident") - public void invalidVersion() throws Exception { - - ResidentVidRequestDto request = getRequest(); - request.setVersion(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("resident") - public void invalidRequest() throws Exception { - - ResidentVidRequestDto request = getRequest(); - request.setRequest(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("resident") - public void invalidIndividualId() throws Exception { - - ResidentVidRequestDto request = getRequest(); - request.getRequest().setIndividualId(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("resident") - public void invalidTransactionId() throws Exception { - - ResidentVidRequestDto request = getRequest(); - request.getRequest().setTransactionID(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("resident") - public void invalidOtp() throws Exception { - - ResidentVidRequestDto request = getRequest(); - request.getRequest().setOtp(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("resident") - public void vidRevokingFailureTest() throws Exception { - - VidRevokeResponseDTO dto = new VidRevokeResponseDTO(); - dto.setMessage("Successful"); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(dto); - - Mockito.when(residentVidService.revokeVid(Mockito.any(VidRevokeRequestDTO.class), Mockito.anyString(), Mockito.anyString())) - .thenReturn(responseWrapper); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRevokeRequest()); - - RequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310540").content(json) - .contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()); - // .andExpect(jsonPath("$.response.message", is("Successful"))); - - } - - @Test - @WithUserDetails("resident") - public void vidRevokingFailureTest2() throws Exception { - - Mockito.when(residentVidService.revokeVid(Mockito.any(VidRevokeRequestDTO.class), Mockito.anyString(), Mockito.anyString())) - .thenThrow(new VidRevocationException()); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRevokeRequest()); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-407"))); - - } - - @Test - @WithUserDetails("reg-admin") - public void invalidIdRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.setId(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidVersionRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.setVersion(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidRequestRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.setRequest(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidVidStatusRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.getRequest().setVidStatus(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310540") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-471"))); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidIndividualIdTypeRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310540") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidIndividualIdRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.getRequest().setIndividualId(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidTransactionIdRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.getRequest().setTransactionID(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - @Test - @WithUserDetails("reg-admin") - public void invalidOtpRevokeTest() throws Exception { - - RequestWrapper request = getRevokeRequest(); - request.getRequest().setOtp(null); - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(request); - - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") - .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); - } - - private static ResidentVidRequestDto getRequest() { - VidRequestDto vidRequestDto = new VidRequestDto(); - vidRequestDto.setIndividualId("9072037081"); - vidRequestDto.setOtp("974436"); - vidRequestDto.setTransactionID("1111122222"); - vidRequestDto.setVidType("Temporary"); - - ResidentVidRequestDto request = new ResidentVidRequestDto(); - request.setId("mosip.resident.vid"); - request.setVersion("v1"); - - request.setRequesttime(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")); - request.setRequest(vidRequestDto); - return request; - } - - private static RequestWrapper getRevokeRequest() { - VidRevokeRequestDTO vidRevokeRequestDTO = new VidRevokeRequestDTO(); - vidRevokeRequestDTO.setIndividualId("2038096257310540"); - vidRevokeRequestDTO.setOtp("974436"); - vidRevokeRequestDTO.setTransactionID("1111122222"); - vidRevokeRequestDTO.setVidStatus("REVOKED"); - - RequestWrapper request = new RequestWrapper(); - request.setId("mosip.resident.vidstatus"); - request.setVersion("v1"); - request.setRequesttime(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")); - request.setRequest(vidRevokeRequestDTO); - return request; - } - - @Test - @WithUserDetails("reg-admin") - public void testGetVidPolicy() throws Exception { - when(residentVidService.getVidPolicy()).thenReturn("policy"); - this.mockMvc.perform(get("/vid/policy")).andExpect(status().isOk()).andDo(print()) - .andExpect(jsonPath("$.response", is("policy"))); - } - - @Test - @WithUserDetails("reg-admin") - public void testGetVidPolicyFailed() throws Exception { - when(residentVidService.getVidPolicy()).thenThrow(new ResidentServiceCheckedException()); - this.mockMvc.perform(get("/vid/policy")).andExpect(status().isOk()).andDo(print()) - .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-426"))); - } - - @Test - @WithUserDetails("reg-admin") - public void vidCreationV2SuccessTest() throws Exception { - - VidResponseDto dto = new VidResponseDto(); - dto.setVid("12345"); - dto.setMessage("Successful"); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(dto); - - Mockito.when(residentVidService.generateVid(Mockito.any(BaseVidRequestDto.class), any())).thenReturn(responseWrapper); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRequest()); - - this.mockMvc.perform(post("/generate-vid").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk());// .andExpect(jsonPath("$.response.vid", is("12345"))); - } - - @Test - @WithUserDetails("reg-admin") - public void vidRevokingV2SuccessTest() throws Exception { - - VidRevokeResponseDTO dto = new VidRevokeResponseDTO(); - dto.setMessage("Successful"); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(dto); - - Mockito.when(residentVidService.revokeVid(Mockito.any(VidRevokeRequestDTO.class), any(), Mockito.anyString())) - .thenReturn(responseWrapper); - - Gson gson = new GsonBuilder().serializeNulls().create(); - String json = gson.toJson(getRevokeRequest()); - - RequestBuilder builder = MockMvcRequestBuilders.patch("/revoke-vid/{vid}", "2038096257310540").content(json) - .contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) - .characterEncoding("UTF-8"); - - this.mockMvc.perform(builder).andExpect(status().isOk()); - // .andExpect(jsonPath("$.response.message", is("Successful"))); - - } - -} +package io.mosip.resident.controller; + +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithUserDetails; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.web.client.RestTemplate; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import io.mosip.kernel.core.util.DateUtils; +import io.mosip.resident.dto.BaseVidRequestDto; +import io.mosip.resident.dto.RequestWrapper; +import io.mosip.resident.dto.ResidentVidRequestDto; +import io.mosip.resident.dto.ResponseWrapper; +import io.mosip.resident.dto.VidRequestDto; +import io.mosip.resident.dto.VidResponseDto; +import io.mosip.resident.dto.VidRevokeRequestDTO; +import io.mosip.resident.dto.VidRevokeResponseDTO; +import io.mosip.resident.exception.ApisResourceAccessException; +import io.mosip.resident.exception.OtpValidationFailedException; +import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.VidCreationException; +import io.mosip.resident.exception.VidRevocationException; +import io.mosip.resident.helper.ObjectStoreHelper; +import io.mosip.resident.service.DocumentService; +import io.mosip.resident.service.ProxyIdRepoService; +import io.mosip.resident.service.impl.IdAuthServiceImpl; +import io.mosip.resident.service.impl.IdentityServiceImpl; +import io.mosip.resident.service.impl.ResidentServiceImpl; +import io.mosip.resident.service.impl.ResidentVidServiceImpl; +import io.mosip.resident.test.ResidentTestBootApplication; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.ResidentServiceRestClient; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ResidentTestBootApplication.class) +@AutoConfigureMockMvc +@TestPropertySource(locations = "classpath:application.properties") +public class ResidentVidControllerTest { + + @MockBean + private ProxyIdRepoService proxyIdRepoService; + + @MockBean + private ResidentVidServiceImpl residentVidService; + + @MockBean + private IdAuthServiceImpl idAuthService; + + @MockBean + private IdentityServiceImpl identityServiceImpl; + + @MockBean + private ResidentServiceImpl residentService; + + @MockBean + @Qualifier("restClientWithPlainRestTemplate") + private ResidentServiceRestClient residentServiceRestClient; + + @MockBean + private DocumentService docService; + + @MockBean + private ObjectStoreHelper objectStore; + + @MockBean + @Qualifier("selfTokenRestTemplate") + private RestTemplate residentRestTemplate; + + @Mock + private Environment env; + + @Autowired + private MockMvc mockMvc; + + @Mock + private AuditUtil audit; + + @Before + public void setup() throws ApisResourceAccessException { + MockitoAnnotations.initMocks(this); + Mockito.doNothing().when(audit).setAuditRequestDto(Mockito.any()); + Mockito.when(identityServiceImpl.getResidentIndvidualIdFromSession()).thenReturn(null); + } + + @Test + @WithUserDetails("resident") + public void vidCreationSuccessTest() throws Exception { + + VidResponseDto dto = new VidResponseDto(); + dto.setVid("12345"); + dto.setMessage("Successful"); + + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(dto); + + Mockito.when(residentVidService.generateVid(Mockito.any(), Mockito.anyString())).thenReturn(responseWrapper); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRequest()); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk());// .andExpect(jsonPath("$.response.vid", is("12345"))); + } + + @Test + @WithUserDetails("resident") + public void otpValidationFailureTest() throws Exception { + + Mockito.when(residentVidService.generateVid(Mockito.any(), Mockito.anyString())) + .thenThrow(new OtpValidationFailedException()); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRequest()); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-422"))); + } + + @Test + @WithUserDetails("resident") + public void vidCreationFailureTest() throws Exception { + + Mockito.when(residentVidService.generateVid(Mockito.any(), Mockito.anyString())) + .thenThrow(new VidCreationException()); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRequest()); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-406"))); + } + + @Test + @WithUserDetails("resident") + public void invalidId() throws Exception { + + ResidentVidRequestDto request = getRequest(); + request.setId(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("resident") + public void invalidVersion() throws Exception { + + ResidentVidRequestDto request = getRequest(); + request.setVersion(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("resident") + public void invalidRequest() throws Exception { + + ResidentVidRequestDto request = getRequest(); + request.setRequest(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("resident") + public void invalidIndividualId() throws Exception { + + ResidentVidRequestDto request = getRequest(); + request.getRequest().setIndividualId(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("resident") + public void invalidTransactionId() throws Exception { + + ResidentVidRequestDto request = getRequest(); + request.getRequest().setTransactionID(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("resident") + public void invalidOtp() throws Exception { + + ResidentVidRequestDto request = getRequest(); + request.getRequest().setOtp(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + this.mockMvc.perform(post("/vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk()).andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("resident") + public void vidRevokingFailureTest() throws Exception { + + VidRevokeResponseDTO dto = new VidRevokeResponseDTO(); + dto.setMessage("Successful"); + + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(dto); + + Mockito.when(residentVidService.revokeVid(Mockito.any(VidRevokeRequestDTO.class), Mockito.anyString(), Mockito.anyString())) + .thenReturn(responseWrapper); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRevokeRequest()); + + RequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310540").content(json) + .contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()); + // .andExpect(jsonPath("$.response.message", is("Successful"))); + + } + + @Test + @WithUserDetails("resident") + public void vidRevokingFailureTest2() throws Exception { + + Mockito.when(residentVidService.revokeVid(Mockito.any(VidRevokeRequestDTO.class), Mockito.anyString(), Mockito.anyString())) + .thenThrow(new VidRevocationException()); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRevokeRequest()); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-407"))); + + } + + @Test + @WithUserDetails("reg-admin") + public void invalidIdRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.setId(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidVersionRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.setVersion(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidRequestRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.setRequest(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidVidStatusRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.getRequest().setVidStatus(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310540") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-471"))); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidIndividualIdTypeRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310540") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidIndividualIdRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.getRequest().setIndividualId(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidTransactionIdRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.getRequest().setTransactionID(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + @Test + @WithUserDetails("reg-admin") + public void invalidOtpRevokeTest() throws Exception { + + RequestWrapper request = getRevokeRequest(); + request.getRequest().setOtp(null); + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(request); + + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/vid/{vid}", "2038096257310541") + .content(json).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-410"))); + } + + private static ResidentVidRequestDto getRequest() { + VidRequestDto vidRequestDto = new VidRequestDto(); + vidRequestDto.setIndividualId("9072037081"); + vidRequestDto.setOtp("974436"); + vidRequestDto.setTransactionID("1111122222"); + vidRequestDto.setVidType("Temporary"); + + ResidentVidRequestDto request = new ResidentVidRequestDto(); + request.setId("mosip.resident.vid"); + request.setVersion("v1"); + + request.setRequesttime(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")); + request.setRequest(vidRequestDto); + return request; + } + + private static RequestWrapper getRevokeRequest() { + VidRevokeRequestDTO vidRevokeRequestDTO = new VidRevokeRequestDTO(); + vidRevokeRequestDTO.setIndividualId("2038096257310540"); + vidRevokeRequestDTO.setOtp("974436"); + vidRevokeRequestDTO.setTransactionID("1111122222"); + vidRevokeRequestDTO.setVidStatus("REVOKED"); + + RequestWrapper request = new RequestWrapper(); + request.setId("mosip.resident.vidstatus"); + request.setVersion("v1"); + request.setRequesttime(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")); + request.setRequest(vidRevokeRequestDTO); + return request; + } + + @Test + @WithUserDetails("reg-admin") + public void testGetVidPolicy() throws Exception { + when(residentVidService.getVidPolicy()).thenReturn("policy"); + this.mockMvc.perform(get("/vid/policy")).andExpect(status().isOk()).andDo(print()) + .andExpect(jsonPath("$.response", is("policy"))); + } + + @Test + @WithUserDetails("reg-admin") + public void testGetVidPolicyFailed() throws Exception { + when(residentVidService.getVidPolicy()).thenThrow(new ResidentServiceCheckedException()); + this.mockMvc.perform(get("/vid/policy")).andExpect(status().isOk()).andDo(print()) + .andExpect(jsonPath("$.errors[0].errorCode", is("RES-SER-426"))); + } + + @Test + @WithUserDetails("reg-admin") + public void vidCreationV2SuccessTest() throws Exception { + + VidResponseDto dto = new VidResponseDto(); + dto.setVid("12345"); + dto.setMessage("Successful"); + + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(dto); + + Mockito.when(residentVidService.generateVid(Mockito.any(BaseVidRequestDto.class), any())).thenReturn(responseWrapper); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRequest()); + + this.mockMvc.perform(post("/generate-vid").contentType(MediaType.APPLICATION_JSON).content(json)) + .andExpect(status().isOk());// .andExpect(jsonPath("$.response.vid", is("12345"))); + } + + @Test + @WithUserDetails("reg-admin") + public void vidRevokingV2SuccessTest() throws Exception { + + VidRevokeResponseDTO dto = new VidRevokeResponseDTO(); + dto.setMessage("Successful"); + + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(dto); + + Mockito.when(residentVidService.revokeVid(Mockito.any(VidRevokeRequestDTO.class), any(), Mockito.anyString())) + .thenReturn(responseWrapper); + + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(getRevokeRequest()); + + RequestBuilder builder = MockMvcRequestBuilders.patch("/revoke-vid/{vid}", "2038096257310540").content(json) + .contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE) + .characterEncoding("UTF-8"); + + this.mockMvc.perform(builder).andExpect(status().isOk()); + // .andExpect(jsonPath("$.response.message", is("Successful"))); + + } + +} diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/TransliterationControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/TransliterationControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java index 75caca0fae5..7c9391a9b71 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/TransliterationControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.junit.Assert.assertEquals; @@ -20,7 +20,6 @@ import io.mosip.preregistration.application.service.TransliterationService; import io.mosip.preregistration.core.common.dto.MainRequestDTO; import io.mosip.preregistration.core.common.dto.MainResponseDTO; -import io.mosip.resident.controller.TransliterationController; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.impl.IdentityServiceImpl; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/WebSubCredentialStatusUpdateControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/WebSubCredentialStatusUpdateControllerTest.java similarity index 94% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/WebSubCredentialStatusUpdateControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/WebSubCredentialStatusUpdateControllerTest.java index b2ac663277e..6a9dfa638b3 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/WebSubCredentialStatusUpdateControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/WebSubCredentialStatusUpdateControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.doThrow; @@ -29,9 +29,6 @@ import io.mosip.kernel.core.websub.model.Event; import io.mosip.kernel.core.websub.model.EventModel; -import io.mosip.resident.controller.VerificationController; -import io.mosip.resident.controller.WebSubCredentialStatusUpdateController; -import io.mosip.resident.controller.WebSubUpdateAuthTypeController; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.helper.ObjectStoreHelper; @@ -41,7 +38,6 @@ import io.mosip.resident.service.ResidentVidService; import io.mosip.resident.service.VerificationService; import io.mosip.resident.service.WebSubCredentialStatusUpdateService; -import io.mosip.resident.service.WebSubUpdateAuthTypeService; import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.service.impl.VerificationServiceImpl; import io.mosip.resident.test.ResidentTestBootApplication; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/WebSubUpdateAuthTypeControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/WebSubUpdateAuthTypeControllerTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/controller/WebSubUpdateAuthTypeControllerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/controller/WebSubUpdateAuthTypeControllerTest.java index 35fc3f60f5a..23c03d9fdeb 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/WebSubUpdateAuthTypeControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/WebSubUpdateAuthTypeControllerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.controller; +package io.mosip.resident.controller; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.doThrow; @@ -29,8 +29,6 @@ import io.mosip.kernel.core.websub.model.Event; import io.mosip.kernel.core.websub.model.EventModel; -import io.mosip.resident.controller.VerificationController; -import io.mosip.resident.controller.WebSubUpdateAuthTypeController; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.helper.ObjectStoreHelper; From 116d55cbe26b9888230e9dfab14ab391dc9e2488 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:27:23 +0530 Subject: [PATCH 06/11] updated package of service impl test classes --- .../impl}/AcknowledgmentServiceTest.java | 3 +- .../AuthTransactionCallbackServiceTest.java | 4 +- .../impl}/BaseWebSubInitializerTest.java | 3 +- .../impl}/DownloadCardServiceTest.java | 6 +- .../DownloadmasterDataServiceImplTest.java | 5 +- .../impl}/GrievanceServiceImplTest.java | 4 +- .../impl}/IdAuthServiceTest.java | 4 +- .../impl}/IdentityServiceTest.java | 3 +- .../impl}/NotificationServiceTest.java | 2 +- .../impl}/OTPManagerServiceImplTest.java | 4 +- .../impl}/OrderCardServiceTest.java | 5 +- .../impl}/PartnerServiceImplTest.java | 4 +- .../impl}/PinUnpinStatusServiceTest.java | 3 +- .../impl}/ProxyIdRepoServiceTest.java | 4 +- .../impl}/ProxyMasterdataServiceTest.java | 42 +++++----- .../impl}/ProxyOtpServiceImpllTest.java | 4 +- .../ProxyPartnerManagementServiceTest.java | 3 +- .../impl}/ResidentCredentialServiceTest.java | 5 +- .../impl}/ResidentOtpServiceTest.java | 4 +- .../ResidentServiceDownloadCardTest.java | 7 +- .../ResidentServiceGetEventStatusTest.java | 5 +- .../ResidentServiceGetServiceHistoryTest.java | 15 ++-- .../ResidentServiceReqAuthHistoryTest.java | 3 +- .../impl}/ResidentServiceReqEUinTest.java | 3 +- .../impl}/ResidentServiceReqReprintTest.java | 3 +- .../ResidentServiceRequestAuthLockTest.java | 17 ++-- ...esidentServiceRequestTypeAuthLockTest.java | 5 +- .../impl}/ResidentServiceResUpdateTest.java | 79 +++++++++---------- .../ResidentVerificationServiceTest.java | 4 +- .../impl}/ResidentVidServiceTest.java | 74 ++++++++--------- .../impl}/RidStatusServiceTest.java | 3 +- .../WebSubUpdateAuthTypeServiceTest.java | 3 +- .../resident/test/util/TemplateUtilTest.java | 35 ++++---- 33 files changed, 158 insertions(+), 210 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/AcknowledgmentServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/AuthTransactionCallbackServiceTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/BaseWebSubInitializerTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/DownloadCardServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/DownloadmasterDataServiceImplTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/GrievanceServiceImplTest.java (94%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/IdAuthServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/IdentityServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/NotificationServiceTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/OTPManagerServiceImplTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/OrderCardServiceTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/PartnerServiceImplTest.java (95%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/PinUnpinStatusServiceTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ProxyIdRepoServiceTest.java (93%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ProxyMasterdataServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ProxyOtpServiceImpllTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ProxyPartnerManagementServiceTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentCredentialServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentOtpServiceTest.java (95%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceDownloadCardTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceGetEventStatusTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceGetServiceHistoryTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceReqAuthHistoryTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceReqEUinTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceReqReprintTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceRequestAuthLockTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceRequestTypeAuthLockTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentServiceResUpdateTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentVerificationServiceTest.java (94%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/ResidentVidServiceTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/RidStatusServiceTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/service => service/impl}/WebSubUpdateAuthTypeServiceTest.java (97%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/AcknowledgmentServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/AcknowledgmentServiceTest.java index e03662a8d6a..4103de6163a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/AcknowledgmentServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; @@ -37,7 +37,6 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.AcknowledgementService; -import io.mosip.resident.service.impl.AcknowledgementServiceImpl; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/AuthTransactionCallbackServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/AuthTransactionCallbackServiceTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/AuthTransactionCallbackServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/AuthTransactionCallbackServiceTest.java index c823947d2b6..ac20fa3e8f7 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/AuthTransactionCallbackServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/AuthTransactionCallbackServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.powermock.api.mockito.PowerMockito.mock; @@ -35,8 +35,6 @@ import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; -import io.mosip.resident.service.impl.AuthTransactionCallBackServiceImpl; -import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/BaseWebSubInitializerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/BaseWebSubInitializerTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/BaseWebSubInitializerTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/BaseWebSubInitializerTest.java index 3d5c68464fd..975a36da271 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/BaseWebSubInitializerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/BaseWebSubInitializerTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import org.junit.After; import org.junit.Before; @@ -19,7 +19,6 @@ import io.mosip.kernel.websub.api.model.SubscriptionChangeRequest; import io.mosip.kernel.websub.api.model.SubscriptionChangeResponse; import io.mosip.kernel.websub.api.model.UnsubscriptionRequest; -import io.mosip.resident.service.impl.BaseWebSubInitializer; @RunWith(MockitoJUnitRunner.class) @ContextConfiguration diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DownloadCardServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/DownloadCardServiceTest.java index ef23eb02ccd..d4da90b3e10 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DownloadCardServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -12,7 +12,6 @@ import java.util.List; import java.util.Map; -import io.mosip.resident.dto.IdentityDTO; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +33,7 @@ import io.mosip.resident.dto.DigitalCardStatusResponseDto; import io.mosip.resident.dto.DownloadCardRequestDTO; import io.mosip.resident.dto.DownloadPersonalizedCardDto; +import io.mosip.resident.dto.IdentityDTO; import io.mosip.resident.dto.MainRequestDTO; import io.mosip.resident.dto.ResidentCredentialResponseDto; import io.mosip.resident.dto.ResponseWrapper; @@ -49,8 +49,6 @@ import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ResidentCredentialService; import io.mosip.resident.service.ResidentVidService; -import io.mosip.resident.service.impl.DownloadCardServiceImpl; -import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilities; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DownloadmasterDataServiceImplTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/DownloadmasterDataServiceImplTest.java index 4559c58b546..9892312bc9e 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DownloadmasterDataServiceImplTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; @@ -9,7 +9,6 @@ import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.time.LocalTime; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -34,14 +33,12 @@ import io.mosip.kernel.core.templatemanager.spi.TemplateManager; import io.mosip.kernel.signature.dto.SignatureResponseDto; import io.mosip.kernel.templatemanager.velocity.builder.TemplateManagerBuilderImpl; -import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.RegistrationCenterDto; import io.mosip.resident.dto.WorkingDaysDto; import io.mosip.resident.dto.WorkingDaysResponseDto; import io.mosip.resident.entity.ResidentTransactionEntity; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.ProxyMasterdataService; -import io.mosip.resident.service.impl.DownLoadMasterDataServiceImpl; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/GrievanceServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/GrievanceServiceImplTest.java similarity index 94% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/GrievanceServiceImplTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/GrievanceServiceImplTest.java index 69d303f1db2..786b1630a5e 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/GrievanceServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/GrievanceServiceImplTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertNotNull; @@ -18,8 +18,6 @@ import io.mosip.resident.dto.MainRequestDTO; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.repository.ResidentGrievanceRepository; -import io.mosip.resident.service.impl.GrievanceServiceImpl; -import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.util.AuditUtil; /** diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/IdAuthServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/IdAuthServiceTest.java index 6d9c6201867..6683464f5c8 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/IdAuthServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; @@ -62,8 +62,6 @@ import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ProxyIdRepoService; -import io.mosip.resident.service.impl.IdAuthServiceImpl; -import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdentityServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/IdentityServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/IdentityServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/IdentityServiceTest.java index c9252efb99f..a24d76e8612 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdentityServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/IdentityServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -62,7 +62,6 @@ import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.IdentityService; import io.mosip.resident.service.ResidentVidService; -import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilities; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/NotificationServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/NotificationServiceTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/NotificationServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/NotificationServiceTest.java index b74d0c59a73..40628ced8c9 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/NotificationServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/NotificationServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/OTPManagerServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/OTPManagerServiceImplTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/OTPManagerServiceImplTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/OTPManagerServiceImplTest.java index 8a8758fadbe..e4547b5e238 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/OTPManagerServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/OTPManagerServiceImplTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -42,8 +42,6 @@ import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ResidentService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.OtpManagerServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/OrderCardServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/OrderCardServiceTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/OrderCardServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/OrderCardServiceTest.java index 864ea448b64..d1a09441d81 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/OrderCardServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/OrderCardServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -34,9 +34,6 @@ import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.OrderCardService; import io.mosip.resident.service.ResidentCredentialService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.OrderCardServiceImpl; -import io.mosip.resident.service.impl.ProxyPartnerManagementServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/PartnerServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/PartnerServiceImplTest.java similarity index 95% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/PartnerServiceImplTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/PartnerServiceImplTest.java index 9e06784395c..1d212e7e101 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/PartnerServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/PartnerServiceImplTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; @@ -31,8 +31,6 @@ import io.mosip.kernel.websub.api.model.UnsubscriptionRequest; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.PartnerServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/PinUnpinStatusServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/PinUnpinStatusServiceTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/PinUnpinStatusServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/PinUnpinStatusServiceTest.java index 459488b511d..6db994d05ff 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/PinUnpinStatusServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/PinUnpinStatusServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; @@ -22,7 +22,6 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.PinUnpinStatusService; -import io.mosip.resident.service.impl.PinUnpinStatusServiceImpl; import io.mosip.resident.util.AuditUtil; /** diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyIdRepoServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java similarity index 93% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyIdRepoServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java index 3ef03f9b698..f4c6f38f714 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyIdRepoServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; @@ -21,8 +21,6 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ProxyIdRepoServiceImpl; import io.mosip.resident.util.ResidentServiceRestClient; @ContextConfiguration(classes = { TestContext.class, WebApplicationContext.class }) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyMasterdataServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyMasterdataServiceTest.java index 35bccefde64..e0a5a6fc8b4 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyMasterdataServiceTest.java @@ -1,4 +1,24 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; import io.mosip.kernel.core.exception.ServiceError; import io.mosip.kernel.core.http.ResponseWrapper; @@ -12,30 +32,10 @@ import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.service.ProxyMasterdataService; -import io.mosip.resident.service.impl.ProxyMasterdataServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; import reactor.util.function.Tuple2; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - /** * Resident proxy masterdata service test class. * diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyOtpServiceImpllTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyOtpServiceImpllTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyOtpServiceImpllTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyOtpServiceImpllTest.java index e0379b5bf67..f589ddfcd0a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyOtpServiceImpllTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyOtpServiceImpllTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -47,8 +47,6 @@ import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.OtpManager; import io.mosip.resident.service.ResidentService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ProxyOtpServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyPartnerManagementServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyPartnerManagementServiceTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyPartnerManagementServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyPartnerManagementServiceTest.java index ffeef034369..c742b026e74 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyPartnerManagementServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyPartnerManagementServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -26,7 +26,6 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.ProxyPartnerManagementService; -import io.mosip.resident.service.impl.ProxyPartnerManagementServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentCredentialServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentCredentialServiceTest.java index 036dbe63b97..35b95bea369 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentCredentialServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -58,9 +58,6 @@ import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ResidentCredentialService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ProxyPartnerManagementServiceImpl; -import io.mosip.resident.service.impl.ResidentCredentialServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentOtpServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentOtpServiceTest.java similarity index 95% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentOtpServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentOtpServiceTest.java index 61af400b065..1550cdb8402 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentOtpServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentOtpServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -26,8 +26,6 @@ import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.ResidentOtpService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentOtpServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceDownloadCardTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceDownloadCardTest.java index 73801685250..06291637a74 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceDownloadCardTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -20,7 +20,6 @@ import javax.persistence.EntityManager; import javax.persistence.Query; -import io.mosip.resident.constant.EventStatusSuccess; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,6 +36,7 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.kernel.core.templatemanager.spi.TemplateManager; import io.mosip.resident.constant.ApiName; +import io.mosip.resident.constant.EventStatusSuccess; import io.mosip.resident.constant.RequestType; import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.BellNotificationDto; @@ -58,9 +58,6 @@ import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.repository.ResidentUserRepository; import io.mosip.resident.service.ProxyMasterdataService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentCredentialServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetEventStatusTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceGetEventStatusTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetEventStatusTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceGetEventStatusTest.java index b79918e6ccc..602fedf5119 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetEventStatusTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceGetEventStatusTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import java.io.IOException; import java.time.LocalDateTime; @@ -21,13 +21,10 @@ import io.mosip.resident.dto.EventStatusResponseDTO; import io.mosip.resident.entity.ResidentTransactionEntity; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.EidNotBelongToSessionException; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.ProxyMasterdataService; import io.mosip.resident.service.ResidentService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceGetServiceHistoryTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceGetServiceHistoryTest.java index 9e76822da41..3134a4a2568 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceGetServiceHistoryTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -15,10 +15,6 @@ import javax.persistence.EntityManager; import javax.persistence.Query; -import io.mosip.resident.constant.IdType; -import io.mosip.resident.dto.RegistrationStatusDTO; -import io.mosip.resident.dto.RegistrationStatusResponseDTO; -import io.mosip.resident.util.ResidentServiceRestClient; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,15 +26,19 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.EventStatus; import io.mosip.resident.constant.EventStatusSuccess; +import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.RequestType; import io.mosip.resident.constant.ServiceType; import io.mosip.resident.dto.AidStatusRequestDTO; import io.mosip.resident.dto.AutnTxnDto; import io.mosip.resident.dto.PageDto; +import io.mosip.resident.dto.RegistrationStatusDTO; +import io.mosip.resident.dto.RegistrationStatusResponseDTO; import io.mosip.resident.dto.ServiceHistoryResponseDto; import io.mosip.resident.entity.ResidentSessionEntity; import io.mosip.resident.entity.ResidentTransactionEntity; @@ -50,15 +50,12 @@ import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.ProxyIdRepoService; import io.mosip.resident.service.ProxyMasterdataService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.PartnerServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utility; import io.mosip.resident.validator.RequestValidator; -import org.springframework.test.util.ReflectionTestUtils; /** * This class is used to test the get service history service diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqAuthHistoryTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqAuthHistoryTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqAuthHistoryTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqAuthHistoryTest.java index b09402d1f3f..8ea013b51ba 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqAuthHistoryTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqAuthHistoryTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -23,7 +23,6 @@ import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; @RunWith(SpringRunner.class) public class ResidentServiceReqAuthHistoryTest { diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqEUinTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqEUinTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqEUinTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqEUinTest.java index e70443543cf..211e97541a6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqEUinTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqEUinTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -20,7 +20,6 @@ import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.UINCardDownloadService; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqReprintTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqReprintTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqReprintTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqReprintTest.java index d385ae0ce41..258dc3a0fa6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceReqReprintTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceReqReprintTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -38,7 +38,6 @@ import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ProxyIdRepoService; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestAuthLockTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceRequestAuthLockTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestAuthLockTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceRequestAuthLockTest.java index fb00dc7c3c7..f1381ef0bb7 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestAuthLockTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceRequestAuthLockTest.java @@ -1,7 +1,7 @@ /** * */ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -9,13 +9,6 @@ import java.util.ArrayList; import java.util.List; -import io.mosip.kernel.core.exception.ServiceError; -import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.resident.constant.ApiName; -import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.dto.AuthLockStatusResponseDtoV2; -import io.mosip.resident.dto.AuthLockTypeStatusDtoV2; -import io.mosip.resident.util.ResidentServiceRestClient; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,11 +20,17 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.util.ReflectionTestUtils; +import io.mosip.kernel.core.exception.ServiceError; +import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.kernel.core.idvalidator.spi.RidValidator; import io.mosip.kernel.core.idvalidator.spi.UinValidator; import io.mosip.kernel.core.idvalidator.spi.VidValidator; +import io.mosip.resident.constant.ApiName; import io.mosip.resident.constant.AuthTypeStatus; +import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.AuthLockOrUnLockRequestDto; +import io.mosip.resident.dto.AuthLockStatusResponseDtoV2; +import io.mosip.resident.dto.AuthLockTypeStatusDtoV2; import io.mosip.resident.dto.AuthUnLockRequestDTO; import io.mosip.resident.dto.NotificationResponseDTO; import io.mosip.resident.dto.ResponseDTO; @@ -42,8 +41,8 @@ import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ResidentService; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.UINCardDownloadService; /** diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceRequestTypeAuthLockTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceRequestTypeAuthLockTest.java index f1c26ee3b07..2ba2965ca0c 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceRequestTypeAuthLockTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -45,9 +45,6 @@ import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.PartnerService; import io.mosip.resident.service.ResidentService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.PartnerServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.UINCardDownloadService; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceResUpdateTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceResUpdateTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceResUpdateTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceResUpdateTest.java index 6306def31ae..b69a156815e 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceResUpdateTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentServiceResUpdateTest.java @@ -1,6 +1,44 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.io.IOUtils; +import org.json.simple.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; import com.fasterxml.jackson.databind.ObjectMapper; + import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.kernel.core.exception.FileNotFoundException; import io.mosip.kernel.core.http.ResponseWrapper; @@ -38,51 +76,12 @@ import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ProxyMasterdataService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentConfigServiceImpl; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utility; -import org.apache.commons.io.IOUtils; -import org.json.simple.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; import reactor.util.function.Tuple2; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - @RunWith(SpringRunner.class) public class ResidentServiceResUpdateTest { @InjectMocks diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentVerificationServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentVerificationServiceTest.java similarity index 94% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentVerificationServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentVerificationServiceTest.java index b1b3d32d1a7..45b15203673 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentVerificationServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentVerificationServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; @@ -23,8 +23,6 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.VerificationService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.VerificationServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utility; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentVidServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentVidServiceTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentVidServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentVidServiceTest.java index 1435111c65a..dbf21e97958 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentVidServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ResidentVidServiceTest.java @@ -1,9 +1,45 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import org.apache.commons.io.IOUtils; +import org.assertj.core.util.Lists; +import org.json.simple.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.util.ReflectionTestUtils; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; + import io.mosip.kernel.core.exception.ServiceError; import io.mosip.kernel.core.util.DateUtils; import io.mosip.resident.constant.ResidentConstants; @@ -23,46 +59,10 @@ import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.NotificationService; -import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.service.impl.ResidentVidServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.JsonUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utility; -import org.apache.commons.io.IOUtils; -import org.assertj.core.util.Lists; -import org.json.simple.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.util.ReflectionTestUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @RefreshScope diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/RidStatusServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/RidStatusServiceTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/RidStatusServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/RidStatusServiceTest.java index b1382f33c8d..9a47ef9cb58 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/RidStatusServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/RidStatusServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -29,7 +29,6 @@ import io.mosip.resident.exception.RIDInvalidException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.NotificationService; -import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/WebSubUpdateAuthTypeServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/WebSubUpdateAuthTypeServiceTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/service/WebSubUpdateAuthTypeServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/service/impl/WebSubUpdateAuthTypeServiceTest.java index 51de1b59f14..c8fa0697d63 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/WebSubUpdateAuthTypeServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/WebSubUpdateAuthTypeServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.service; +package io.mosip.resident.service.impl; import static org.powermock.api.mockito.PowerMockito.mock; @@ -38,7 +38,6 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.NotificationService; -import io.mosip.resident.service.impl.WebSubUpdateAuthTypeServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java index ecd78cf6c07..c9ef3671079 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java @@ -1,5 +1,22 @@ package io.mosip.resident.test.util; +import static junit.framework.TestCase.assertEquals; + +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.EventStatus; import io.mosip.resident.constant.EventStatusFailure; @@ -18,28 +35,12 @@ import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.ProxyMasterdataService; import io.mosip.resident.service.impl.IdentityServiceImpl; +import io.mosip.resident.service.impl.IdentityServiceTest; import io.mosip.resident.service.impl.ProxyPartnerManagementServiceImpl; import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.test.service.IdentityServiceTest; import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utility; import io.mosip.resident.validator.RequestValidator; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import static junit.framework.TestCase.assertEquals; /** * This class is used to test the TemplateUtil class From 2af32db87ab57c19f8ce119c3a62c0c3fc18c61f Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:39:04 +0530 Subject: [PATCH 07/11] updated package of util test classes --- .../io/mosip/resident/{test => }/util/AuditUtilTest.java | 6 +----- .../mosip/resident/{test => }/util/EncryptorUtilTest.java | 4 +--- .../io/mosip/resident/{test => }/util/IdSchemaUtilTest.java | 4 +--- .../io/mosip/resident/{test => }/util/JsonUtilTest.java | 3 +-- .../{test => }/util/ResidentServiceRestClientTest.java | 3 +-- .../io/mosip/resident/{test => }/util/ServerUtilTest.java | 4 +--- .../io/mosip/resident/{test => }/util/TemplateUtilTest.java | 4 +--- .../mosip/resident/{test => }/util/TokenGeneratorTest.java | 3 +-- .../mosip/resident/{test => }/util/UINCardDownloadTest.java | 4 +--- .../io/mosip/resident/{test => }/util/UtilitiesTest.java | 5 +---- .../java/io/mosip/resident/{test => }/util/UtilityTest.java | 6 +----- 11 files changed, 11 insertions(+), 35 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/AuditUtilTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/EncryptorUtilTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/IdSchemaUtilTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/JsonUtilTest.java (97%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/ResidentServiceRestClientTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/ServerUtilTest.java (91%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/TemplateUtilTest.java (99%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/TokenGeneratorTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/UINCardDownloadTest.java (93%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/UtilitiesTest.java (96%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/util/UtilityTest.java (97%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/AuditUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/AuditUtilTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/AuditUtilTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/AuditUtilTest.java index b2d80d0fb56..737a8ae03cf 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/AuditUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/AuditUtilTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -40,10 +40,6 @@ import io.mosip.resident.dto.AuditRequestDTO; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.util.AuditResponseDto; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.EventEnum; -import io.mosip.resident.util.Utility; import reactor.util.function.Tuple2; import reactor.util.function.Tuples; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/EncryptorUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/EncryptorUtilTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/EncryptorUtilTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/EncryptorUtilTest.java index 19881e24701..89eb2798c35 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/EncryptorUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/EncryptorUtilTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -32,8 +32,6 @@ import io.mosip.kernel.core.http.RequestWrapper; import io.mosip.kernel.core.util.DateUtils; import io.mosip.resident.dto.CryptomanagerRequestDto; -import io.mosip.resident.util.EncryptorUtil; -import io.mosip.resident.util.ResidentServiceRestClient; /** * @author Abubacker Siddik diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/IdSchemaUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/IdSchemaUtilTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/IdSchemaUtilTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/IdSchemaUtilTest.java index fb361634b55..cbda48b546a 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/IdSchemaUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/IdSchemaUtilTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static io.mosip.resident.util.IdSchemaUtil.RESPONSE; import static io.mosip.resident.util.IdSchemaUtil.SCHEMA_JSON; @@ -31,8 +31,6 @@ import io.mosip.kernel.core.util.DateUtils; import io.mosip.resident.constant.ApiName; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.util.IdSchemaUtil; -import io.mosip.resident.util.ResidentServiceRestClient; /** * @author Abubacker Siddik diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/JsonUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/JsonUtilTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/JsonUtilTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/JsonUtilTest.java index 1544fa0dafc..aec6a64338b 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/JsonUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/JsonUtilTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -18,7 +18,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import io.mosip.resident.dto.JsonValue; -import io.mosip.resident.util.JsonUtil; @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/ResidentServiceRestClientTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/ResidentServiceRestClientTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/ResidentServiceRestClientTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/ResidentServiceRestClientTest.java index a6622b1fb80..4c86f6017ec 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/ResidentServiceRestClientTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/ResidentServiceRestClientTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -38,7 +38,6 @@ import io.mosip.resident.constant.ApiName; import io.mosip.resident.dto.AutnTxnResponseDto; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.util.ResidentServiceRestClient; @RunWith(MockitoJUnitRunner.class) public class ResidentServiceRestClientTest { diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/ServerUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/ServerUtilTest.java similarity index 91% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/ServerUtilTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/ServerUtilTest.java index ef3d9206274..b6ed0cfa697 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/ServerUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/ServerUtilTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertTrue; @@ -10,8 +10,6 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; -import io.mosip.resident.util.ServerUtil; - @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) public class ServerUtilTest { diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/TemplateUtilTest.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/TemplateUtilTest.java index c9ef3671079..ef0a45616e9 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/TemplateUtilTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static junit.framework.TestCase.assertEquals; @@ -38,8 +38,6 @@ import io.mosip.resident.service.impl.IdentityServiceTest; import io.mosip.resident.service.impl.ProxyPartnerManagementServiceImpl; import io.mosip.resident.service.impl.ResidentServiceImpl; -import io.mosip.resident.util.TemplateUtil; -import io.mosip.resident.util.Utility; import io.mosip.resident.validator.RequestValidator; /** diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TokenGeneratorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/TokenGeneratorTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/TokenGeneratorTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/TokenGeneratorTest.java index 0c241ec1b13..769cf7b68b6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TokenGeneratorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/TokenGeneratorTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.mockito.ArgumentMatchers.any; import static org.powermock.api.mockito.PowerMockito.mockStatic; @@ -25,7 +25,6 @@ import io.mosip.kernel.core.util.TokenHandlerUtil; import io.mosip.resident.exception.TokenGenerationFailedException; -import io.mosip.resident.util.TokenGenerator; @RunWith(PowerMockRunner.class) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UINCardDownloadTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/UINCardDownloadTest.java similarity index 93% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/UINCardDownloadTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/UINCardDownloadTest.java index 0d231b02dcb..bf51fa09d48 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UINCardDownloadTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/UINCardDownloadTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertEquals; @@ -12,8 +12,6 @@ import io.mosip.resident.constant.IdType; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.util.ResidentServiceRestClient; -import io.mosip.resident.util.UINCardDownloadService; @RunWith(MockitoJUnitRunner.class) public class UINCardDownloadTest { diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/UtilitiesTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/UtilitiesTest.java index 8a7533f2366..87b71b96ec9 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/UtilitiesTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static io.mosip.resident.constant.ResidentConstants.TRANSACTION_TYPE_CODE; import static org.junit.Assert.assertEquals; @@ -53,9 +53,6 @@ import io.mosip.resident.exception.IndividualIdNotFoundException; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.VidCreationException; -import io.mosip.resident.util.JsonUtil; -import io.mosip.resident.util.ResidentServiceRestClient; -import io.mosip.resident.util.Utilities; @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilityTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/UtilityTest.java similarity index 97% rename from resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilityTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/util/UtilityTest.java index 0fbd57fbe28..c00e89ebea7 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilityTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/UtilityTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.util; +package io.mosip.resident.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -44,7 +44,6 @@ import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; import io.mosip.kernel.core.exception.ServiceError; @@ -62,9 +61,6 @@ import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.impl.IdentityServiceImpl; -import io.mosip.resident.util.JsonUtil; -import io.mosip.resident.util.ResidentServiceRestClient; -import io.mosip.resident.util.Utility; @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) From 370b58283a22ca14fff1f21e89b6ec48eec16958 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:43:22 +0530 Subject: [PATCH 08/11] updated package of aspect test classes --- .../io/mosip/resident/{test => }/aspect/LoginCheckTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/aspect/LoginCheckTest.java (98%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/aspect/LoginCheckTest.java b/resident/resident-service/src/test/java/io/mosip/resident/aspect/LoginCheckTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/aspect/LoginCheckTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/aspect/LoginCheckTest.java index 558e285e125..4436143d9e4 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/aspect/LoginCheckTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/aspect/LoginCheckTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.aspect; +package io.mosip.resident.aspect; import java.util.ArrayList; import java.util.Collection; @@ -18,7 +18,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.util.ReflectionTestUtils; -import io.mosip.resident.aspect.LoginCheck; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentSessionRepository; From d8e562add35095d2e6341ce42c5a4b7b9169dc34 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:45:48 +0530 Subject: [PATCH 09/11] updated package of config test classes --- .../resident/{test => }/config/ResidentServiceConfigTest.java | 2 +- .../io/mosip/resident/{test => }/config/TestSecurityConfig.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/config/ResidentServiceConfigTest.java (94%) rename resident/resident-service/src/test/java/io/mosip/resident/{test => }/config/TestSecurityConfig.java (99%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/config/ResidentServiceConfigTest.java b/resident/resident-service/src/test/java/io/mosip/resident/config/ResidentServiceConfigTest.java similarity index 94% rename from resident/resident-service/src/test/java/io/mosip/resident/test/config/ResidentServiceConfigTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/config/ResidentServiceConfigTest.java index 57a0243c821..f329a7762fd 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/config/ResidentServiceConfigTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/config/ResidentServiceConfigTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.config; +package io.mosip.resident.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/config/TestSecurityConfig.java b/resident/resident-service/src/test/java/io/mosip/resident/config/TestSecurityConfig.java similarity index 99% rename from resident/resident-service/src/test/java/io/mosip/resident/test/config/TestSecurityConfig.java rename to resident/resident-service/src/test/java/io/mosip/resident/config/TestSecurityConfig.java index 0fa5a8e420c..75d3396d607 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/config/TestSecurityConfig.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/config/TestSecurityConfig.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.config; +package io.mosip.resident.config; import java.util.ArrayList; import java.util.Arrays; From 6114679ed330cb644c59e6395f2257f569ba5b32 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 14:47:32 +0530 Subject: [PATCH 10/11] updated package of handler test classes --- .../service}/ResidentUpdateServiceTest.java | 4 +--- .../handler => handler/service}/SyncAndUploadServiceTest.java | 3 +-- .../service}/UinCardRePrintServiceTest.java | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) rename resident/resident-service/src/test/java/io/mosip/resident/{test/handler => handler/service}/ResidentUpdateServiceTest.java (95%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/handler => handler/service}/SyncAndUploadServiceTest.java (98%) rename resident/resident-service/src/test/java/io/mosip/resident/{test/handler => handler/service}/UinCardRePrintServiceTest.java (96%) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/handler/ResidentUpdateServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/handler/service/ResidentUpdateServiceTest.java similarity index 95% rename from resident/resident-service/src/test/java/io/mosip/resident/test/handler/ResidentUpdateServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/handler/service/ResidentUpdateServiceTest.java index dead2cf5e23..961dacf90c2 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/handler/ResidentUpdateServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/handler/service/ResidentUpdateServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.handler; +package io.mosip.resident.handler.service; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -40,8 +40,6 @@ import io.mosip.resident.dto.ResidentUpdateDto; import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.handler.service.ResidentUpdateService; -import io.mosip.resident.handler.service.SyncAndUploadService; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.IdSchemaUtil; import io.mosip.resident.util.ResidentServiceRestClient; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/handler/SyncAndUploadServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/handler/service/SyncAndUploadServiceTest.java similarity index 98% rename from resident/resident-service/src/test/java/io/mosip/resident/test/handler/SyncAndUploadServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/handler/service/SyncAndUploadServiceTest.java index 1bf958e8bb2..c27de24bcc6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/handler/SyncAndUploadServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/handler/service/SyncAndUploadServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.handler; +package io.mosip.resident.handler.service; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -34,7 +34,6 @@ import io.mosip.resident.dto.RegistrationType; import io.mosip.resident.dto.SyncResponseDto; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.handler.service.SyncAndUploadService; import io.mosip.resident.service.ProxyIdRepoService; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.EncryptorUtil; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/handler/UinCardRePrintServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/handler/service/UinCardRePrintServiceTest.java similarity index 96% rename from resident/resident-service/src/test/java/io/mosip/resident/test/handler/UinCardRePrintServiceTest.java rename to resident/resident-service/src/test/java/io/mosip/resident/handler/service/UinCardRePrintServiceTest.java index 5d45f8433c8..528c78c26eb 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/handler/UinCardRePrintServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/handler/service/UinCardRePrintServiceTest.java @@ -1,4 +1,4 @@ -package io.mosip.resident.test.handler; +package io.mosip.resident.handler.service; import static org.junit.Assert.assertTrue; @@ -47,8 +47,6 @@ import io.mosip.resident.dto.VidResDTO; import io.mosip.resident.dto.VidResponseDTO1; import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.handler.service.SyncAndUploadService; -import io.mosip.resident.handler.service.UinCardRePrintService; import io.mosip.resident.service.ProxyIdRepoService; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.IdSchemaUtil; From 7eb5ffcae43292382fef333fb11dd97b57d3b474 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 13 Jun 2023 17:54:49 +0530 Subject: [PATCH 11/11] added some exception test cases --- .../controller/ResidentControllerTest.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java index c5f9556aa1b..0c582385b8d 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; @@ -612,7 +613,14 @@ public void testGetCredentialRequestStatusSuccess() throws Exception { this.mockMvc.perform(get("/events/86c2ad43-e2a4-4952-bafc-d97ad1e5e453/?langCode=eng")) .andExpect(status().isOk()); } - + + @Test(expected = Exception.class) + @WithUserDetails("reg-admin") + public void testCheckEventIdStatusWithException() throws Exception { + when(residentService.getEventStatus(anyString(), anyString(), anyInt(), anyString())).thenThrow(new ResidentServiceCheckedException()); + residentController.checkEventIdStatus("17", "eng", 0, LOCALE_EN_US); + } + @Test @WithUserDetails("reg-admin") public void testGetUserInfo() throws Exception { @@ -626,6 +634,13 @@ public void testGetUserInfo() throws Exception { .andExpect(status().isOk()); } + @Test(expected = Exception.class) + @WithUserDetails("reg-admin") + public void testGetUserInfoWithException() throws Exception { + Mockito.when(residentService.getUserinfo(Mockito.any(), Mockito.anyInt(), Mockito.anyString())).thenThrow(new ApisResourceAccessException()); + residentController.userinfo(0, LOCALE_EN_US); + } + @Test @WithUserDetails("reg-admin") public void testBellClickdttimes() throws Exception { @@ -637,6 +652,13 @@ public void testBellClickdttimes() throws Exception { residentController.bellClickdttimes(); } + @Test(expected = Exception.class) + @WithUserDetails("reg-admin") + public void testBellClickdttimesWithException() throws Exception { + when(identityServiceImpl.getResidentIdaToken()).thenThrow(new ApisResourceAccessException()); + residentController.bellClickdttimes(); + } + @Test @WithUserDetails("reg-admin") public void testNotificationCount() throws Exception { @@ -668,6 +690,13 @@ public void testGetNotificationsList() throws Exception { residentController.getNotificationsList("eng", 0, 10, 0, LOCALE_EN_US); } + @Test(expected = Exception.class) + @WithUserDetails("reg-admin") + public void testGetNotificationsListWithException() throws Exception { + when(identityServiceImpl.getResidentIdaToken()).thenThrow(new ApisResourceAccessException()); + residentController.getNotificationsList("eng", 0, 10, 0, LOCALE_EN_US); + } + @Test @WithUserDetails("reg-admin") public void testDownLoadServiceHistory() throws Exception { @@ -694,6 +723,17 @@ public void testDownLoadServiceHistory() throws Exception { ServiceType.ID_MANAGEMENT_REQUEST.name(), EventStatus.SUCCESS.getStatus(), "", "eng", 0, LOCALE_EN_US); } + @Test(expected = Exception.class) + @WithUserDetails("reg-admin") + public void testDownLoadServiceHistoryWithException() throws Exception { + ReflectionTestUtils.setField(residentController, "maxEventsServiceHistoryPageSize", 10); + Mockito.when(residentService.getServiceHistory(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyInt(), + Mockito.any())).thenThrow(new ApisResourceAccessException()); + residentController.downLoadServiceHistory(LocalDateTime.now(), LocalDate.now(), LocalDate.now(), SortType.ASC.name(), + ServiceType.ID_MANAGEMENT_REQUEST.name(), EventStatus.SUCCESS.getStatus(), "", "eng", 0, LOCALE_EN_US); + } + @Test(expected = ResidentServiceException.class) @WithUserDetails("reg-admin") public void testCheckAidStatusWithException() throws Exception {