From 707e498cc826376862fffb928ec46a1644e5ebb9 Mon Sep 17 00:00:00 2001 From: RitikJain4108 <99730411+RitikJain4108@users.noreply.github.com> Date: Fri, 14 Apr 2023 20:21:08 +0530 Subject: [PATCH] removed pre-reg dependency (#877) Co-authored-by: Ritik Jain --- resident/resident-service/pom.xml | 2 + .../resident/ResidentBootApplication.java | 4 +- .../controller/ProxyOtpController.java | 118 -------- .../controller/TransliterationController.java | 66 ----- .../io/mosip/resident/service/OtpManager.java | 19 -- .../resident/service/ProxyOtpService.java | 20 -- .../service/impl/OtpManagerServiceImpl.java | 247 ---------------- .../service/impl/ProxyOtpServiceImpl.java | 230 --------------- .../resident/validator/RequestValidator.java | 17 -- .../config/ResidentServiceConfigTest.java | 8 - .../controller/ProxyOtpControllerTest.java | 177 ------------ .../TransliterationControllerTest.java | 87 ------ .../service/OTPManagerServiceImplTest.java | 186 ------------ .../service/ProxyOtpServiceImpllTest.java | 273 ------------------ .../test/validator/RequestValidatorTest.java | 33 --- 15 files changed, 3 insertions(+), 1484 deletions(-) delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/service/OtpManager.java delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/service/ProxyOtpService.java delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/service/impl/OtpManagerServiceImpl.java delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyOtpServiceImpl.java delete mode 100644 resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyOtpControllerTest.java delete mode 100644 resident/resident-service/src/test/java/io/mosip/resident/test/controller/TransliterationControllerTest.java delete mode 100644 resident/resident-service/src/test/java/io/mosip/resident/test/service/OTPManagerServiceImplTest.java delete mode 100644 resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyOtpServiceImpllTest.java diff --git a/resident/resident-service/pom.xml b/resident/resident-service/pom.xml index cb48e7d791a..7a4fb386608 100644 --- a/resident/resident-service/pom.xml +++ b/resident/resident-service/pom.xml @@ -372,6 +372,7 @@ + org.apache.commons commons-lang3 diff --git a/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java b/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java index fcd7ddb1b4f..8cfaf52187f 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java @@ -8,8 +8,6 @@ import io.mosip.kernel.authcodeflowproxy.api.validator.ValidateTokenUtil; import io.mosip.kernel.cbeffutil.impl.CbeffImpl; import io.mosip.kernel.dataaccess.hibernate.config.HibernateDaoConfig; -import io.mosip.preregistration.application.service.TransliterationService; -import io.mosip.preregistration.application.service.util.TransliterationServiceUtil; @SpringBootApplication(scanBasePackages = { "io.mosip.resident.*", @@ -22,7 +20,7 @@ "io.mosip.kernel.virusscanner.*", "io.mosip.commons.khazana.*", "io.mosip.idrepository.core.util.*"},exclude = HibernateDaoConfig.class) -@Import({TokenIDGenerator.class, ValidateTokenUtil.class, CbeffImpl.class, TransliterationService.class, TransliterationServiceUtil.class}) +@Import({TokenIDGenerator.class, ValidateTokenUtil.class, CbeffImpl.class}) public class ResidentBootApplication { public static void main(String[] args) { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java deleted file mode 100644 index 3a0cd9e93a7..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java +++ /dev/null @@ -1,118 +0,0 @@ -package io.mosip.resident.controller; - -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -import io.mosip.kernel.core.authmanager.model.AuthNResponse; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.resident.config.LoggerConfiguration; -import io.mosip.resident.constant.ResidentConstants; -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.InvalidInputException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.service.ProxyOtpService; -import io.mosip.resident.validator.RequestValidator; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; -import reactor.util.function.Tuple2; - -/** - * This class provides different api to perform operation for login - * - * @author Kamesh Shekhar Prasad - * @since 1.0.0 - * - */ -@RestController -@Tag(name = "login-controller", description = "Login Controller") -public class ProxyOtpController { - - private Logger log = LoggerConfiguration.logConfig(ProxyOtpController.class); - - @Autowired - private ProxyOtpService proxyOtpService; - - @Autowired - private RequestValidator requestValidator; - - @Autowired - private Environment environment; - - /** - * This Post api use to send otp to the user by email or sms - * - * @param userOtpRequest - * @return AuthNResponse - */ - - @PostMapping(value = "/contact-details/send-otp", produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "sendOTP", description = "Send Otp to UserId", tags = "login-controller") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "201", description = "Created" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "401", description = "Unauthorized" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "404", description = "Not Found" ,content = @Content(schema = @Schema(hidden = true)))}) - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity> sendOTP( - @Validated @RequestBody MainRequestDTO userOtpRequest) { - try { - requestValidator.validateProxySendOtpRequest(userOtpRequest); - } catch (InvalidInputException e) { - throw new ResidentServiceException(e.getErrorCode(), e.getErrorText(), e, - Map.of(ResidentConstants.REQ_RES_ID, - environment.getProperty(ResidentConstants.RESIDENT_CONTACT_DETAILS_SEND_OTP_ID))); - } - return proxyOtpService.sendOtp(userOtpRequest); - } - - - - /** - * This Post api use to validate userid and otp - * - * @param userIdOtpRequest - * @return AuthNResponse - */ - @PostMapping(value = "/contact-details/update-data", produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "validateWithUserIdOtp", description = "Validate UserId and Otp", tags = "login-controller") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "201", description = "Created" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "401", description = "Unauthorized" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "404", description = "Not Found" ,content = @Content(schema = @Schema(hidden = true)))}) - public ResponseEntity> validateWithUserIdOtp( - @Validated @RequestBody MainRequestDTO userIdOtpRequest) { - - log.debug("User ID: {}", userIdOtpRequest.getRequest().getUserId()); - try { - requestValidator.validateUpdateDataRequest(userIdOtpRequest); - } catch (InvalidInputException e) { - throw new ResidentServiceException(e.getErrorCode(), e.getErrorText(), e, - Map.of(ResidentConstants.REQ_RES_ID, - environment.getProperty(ResidentConstants.RESIDENT_CONTACT_DETAILS_UPDATE_ID))); - } - Tuple2, String> tupleResponse = proxyOtpService.validateWithUserIdOtp(userIdOtpRequest); - return ResponseEntity.ok() - .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) - .body(tupleResponse.getT1()); - } -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java deleted file mode 100644 index 62f8cae9055..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.mosip.resident.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import io.mosip.preregistration.application.dto.TransliterationRequestDTO; -import io.mosip.preregistration.application.dto.TransliterationResponseDTO; -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.validator.RequestValidator; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; - -/** - * This class provides different API's to perform operations on - * Transliteration Application - * - * @author Kamesh Shekhar Prasad - * - */ -@RestController -@RequestMapping("/transliteration") -@Tag(name = "Transliteration Controller", description = "Transliteration Controller") -public class TransliterationController { - - /** Autowired reference for {@link #transliterationService}. */ - @Autowired - private TransliterationService transliterationService; - - @Autowired - private RequestValidator requestValidator; - - /** The Constant for GET UPDATED DATE TIME application. */ - private static final String TRANS = "resident.transliteration.transliterate"; - - /** - * Post API to transliterate from transliteration application. - * - * @param requestDTO - * @return responseDto with transliterated toFieldValue. - */ - @PostMapping(path = "/transliterate", consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "Get Pre-Registartion-Translitration data", description = "Get Pre-Registartion-Translitration data", tags = "Transliteration Controller") - @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Given key is translitrated successfully"), - @ApiResponse(responseCode = "201", description = "Created" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "401", description = "Unauthorized" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden" ,content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "404", description = "Not Found" ,content = @Content(schema = @Schema(hidden = true)))}) - public ResponseEntity> translitrator( - @Validated @RequestBody() MainRequestDTO requestDTO) { - requestValidator.validateId(requestDTO); - return ResponseEntity.status(HttpStatus.OK).body(transliterationService.translitratorService(requestDTO)); - } -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/OtpManager.java b/resident/resident-service/src/main/java/io/mosip/resident/service/OtpManager.java deleted file mode 100644 index a9bc680b6c5..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/OtpManager.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.mosip.resident.service; - -import java.io.IOException; - -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.dto.OtpRequestDTOV2; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import reactor.util.function.Tuple2; - -/** - * @author Kamesh Shekhar Prasad - * This interface is used to create method declaration for sending and validating otp. - */ -public interface OtpManager { - public boolean sendOtp(MainRequestDTO requestDTO, String channelType, String language) throws IOException, ResidentServiceCheckedException, ApisResourceAccessException; - public boolean validateOtp(String otp, String userId, String transactionId) throws ApisResourceAccessException, ResidentServiceCheckedException; - public Tuple2 updateUserId(String userId, String transactionId) throws ApisResourceAccessException, ResidentServiceCheckedException; -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyOtpService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyOtpService.java deleted file mode 100644 index 5352a84fb0a..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyOtpService.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.mosip.resident.service; - -import org.springframework.http.ResponseEntity; - -import io.mosip.kernel.core.authmanager.model.AuthNResponse; -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 reactor.util.function.Tuple2; - -/** - * @Author Kamesh Shekhar Prasad - * This class is used to do operations on otp. - */ -public interface ProxyOtpService { - ResponseEntity> sendOtp(MainRequestDTO userOtpRequest); - - Tuple2, String> validateWithUserIdOtp(MainRequestDTO userIdOtpRequest); -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/OtpManagerServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/OtpManagerServiceImpl.java deleted file mode 100644 index 91488f70cda..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/OtpManagerServiceImpl.java +++ /dev/null @@ -1,247 +0,0 @@ -package io.mosip.resident.service.impl; - -import java.io.IOException; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.xml.bind.DatatypeConverter; - -import org.json.simple.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; - -import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.kernel.core.util.CryptoUtil; -import io.mosip.kernel.core.util.DateUtils; -import io.mosip.kernel.core.util.HMACUtils; -import io.mosip.preregistration.application.constant.PreRegLoginConstant; -import io.mosip.preregistration.application.constant.PreRegLoginErrorConstants; -import io.mosip.preregistration.application.dto.OTPGenerateRequestDTO; -import io.mosip.preregistration.application.dto.RequestDTO; -import io.mosip.resident.config.LoggerConfiguration; -import io.mosip.resident.constant.RequestType; -import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.constant.TemplateType; -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.dto.NotificationRequestDto; -import io.mosip.resident.dto.NotificationRequestDtoV2; -import io.mosip.resident.dto.OtpRequestDTOV2; -import io.mosip.resident.dto.ResidentUpdateRequestDto; -import io.mosip.resident.entity.OtpTransactionEntity; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.repository.OtpTransactionRepository; -import io.mosip.resident.service.NotificationService; -import io.mosip.resident.service.OtpManager; -import io.mosip.resident.service.ResidentService; -import io.mosip.resident.util.TemplateUtil; -import io.mosip.resident.validator.RequestValidator; -import reactor.util.function.Tuple2; - -/** - * @author Kamesh Shekhar Prasad - * This class is used to generate otp and validate otp. - */ -@Service -public class OtpManagerServiceImpl implements OtpManager { - - private static final Logger logger = LoggerConfiguration.logConfig(OtpManagerServiceImpl.class); - private static final String OTP_EXPIRED = "OTP_EXPIRED"; - private static final String ACCEPTED = "accepted"; - private static final String PHONE = "phone"; - private static final String EMAIL = "email"; - - @Autowired - private OtpTransactionRepository otpRepo; - - @Autowired - private Environment environment; - - @Autowired - @Qualifier("selfTokenRestTemplate") - RestTemplate restTemplate; - - @Autowired - private NotificationService notificationService; - - @Autowired - private IdentityServiceImpl identityService; - - @Autowired - private ResidentService residentService; - - @Autowired - private TemplateUtil templateUtil; - - @Autowired - private RequestValidator requestValidator; - - - @Override - public boolean sendOtp(MainRequestDTO requestDTO, String channelType, String language) throws IOException, ResidentServiceCheckedException, ApisResourceAccessException { - this.logger.info("sessionId", "idType", "id", "In sendOtp method of otpmanager service "); - String userId = requestDTO.getRequest().getUserId(); - NotificationRequestDto notificationRequestDto = new NotificationRequestDtoV2(); - notificationRequestDto.setId(identityService.getResidentIndvidualIdFromSession()); - String refId = this.hash(userId+requestDTO.getRequest().getTransactionId()); - if (this.otpRepo.checkotpsent(refId, "active", DateUtils.getUTCCurrentDateTime(), DateUtils.getUTCCurrentDateTime() - .minusMinutes(this.environment.getProperty("otp.request.flooding.duration", Long.class))) > - this.environment.getProperty("otp.request.flooding.max-count", Integer.class)) { - this.logger.error("sessionId", this.getClass().getSimpleName(), ResidentErrorCode.OTP_REQUEST_FLOODED.getErrorCode(), "OTP_REQUEST_FLOODED"); - throw new ResidentServiceCheckedException(ResidentErrorCode.OTP_REQUEST_FLOODED.getErrorCode(), ResidentErrorCode.OTP_REQUEST_FLOODED.getErrorMessage()); - } else { - String otp = this.generateOTP(requestDTO); - this.logger.info("sessionId", "idType", "id", "In generateOTP method of otpmanager service OTP generated"); - String otpHash = digestAsPlainText((userId + this.environment.getProperty("mosip.kernel.data-key-splitter") + otp+ - requestDTO.getRequest().getTransactionId()).getBytes()); - OtpTransactionEntity otpTxn; - otpTxn = new OtpTransactionEntity(); - otpTxn.setId(UUID.randomUUID().toString()); - otpTxn.setRefId(this.hash(userId + requestDTO.getRequest().getTransactionId())); - otpTxn.setOtpHash(otpHash); - otpTxn.setCrBy(this.environment.getProperty("resident.clientId")); - otpTxn.setCrDtimes(DateUtils.getUTCCurrentDateTime()); - otpTxn.setGeneratedDtimes(DateUtils.getUTCCurrentDateTime()); - otpTxn.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plusSeconds((Long) - this.environment.getProperty("mosip.kernel.otp.expiry-time", Long.class))); - otpTxn.setStatusCode("active"); - this.otpRepo.save(otpTxn); - if (channelType.equalsIgnoreCase("phone")) { - this.logger.info("sessionId", "idType", "id", "In generateOTP method of otpmanager service invoking sms notification"); - NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; - notificationRequestDtoV2.setTemplateType(TemplateType.SUCCESS); - notificationRequestDtoV2.setRequestType(RequestType.SEND_OTP); - notificationRequestDtoV2.setOtp(otp); - notificationService - .sendNotification(notificationRequestDto, List.of(channelType), null, userId); - } - - if (channelType.equalsIgnoreCase("email")) { - this.logger.info("sessionId", "idType", "id", "In generateOTP method of otpmanager service invoking email notification"); - NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; - notificationRequestDtoV2.setTemplateType(TemplateType.SUCCESS); - notificationRequestDtoV2.setRequestType(RequestType.SEND_OTP); - notificationRequestDtoV2.setOtp(otp); - notificationService - .sendNotification(notificationRequestDto, List.of(channelType), userId, null); - } - - return true; - } - } - - private String generateOTP(MainRequestDTO requestDTO) { - this.logger.info("sessionId", "idType", "id", "In generateOTP method of otpmanager service "); - - try { - OTPGenerateRequestDTO otpRequestDTO = new OTPGenerateRequestDTO(); - otpRequestDTO.setId(requestDTO.getId()); - otpRequestDTO.setRequesttime(requestDTO.getRequesttime()); - otpRequestDTO.setVersion(requestDTO.getVersion()); - RequestDTO req = new RequestDTO(); - req.setKey(requestDTO.getRequest().getUserId()); - otpRequestDTO.setRequest(req); - HttpHeaders headers1 = new HttpHeaders(); - headers1.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); - headers1.setContentType(MediaType.APPLICATION_JSON_UTF8); - headers1.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); - HttpEntity entity1 = new HttpEntity(otpRequestDTO, headers1); - ResponseWrapper> response = (ResponseWrapper)this.restTemplate.exchange(this.environment.getProperty("otp-generate.rest.uri"), HttpMethod.POST, entity1, ResponseWrapper.class, new Object[0]).getBody(); - String otp = null; - if (response != null) { - Map res = (Map)response.getResponse(); - if (res != null) { - if (((String)res.get("status")).equals("USER_BLOCKED")) { - this.logger.error("sessionId", this.getClass().getSimpleName(), ResidentErrorCode.BLOCKED_OTP_VALIDATE.getErrorCode(), "USER_BLOCKED"); - throw new ResidentServiceException(ResidentErrorCode.BLOCKED_OTP_VALIDATE.getErrorCode(), ResidentErrorCode.BLOCKED_OTP_VALIDATE.getErrorMessage()); - } - - otp = res.get("otp"); - } - } - - return otp; - } catch (ResidentServiceException var9) { - this.logger.error("sessionId", this.getClass().getSimpleName(), "generateOTP", var9.getMessage()); - throw new ResidentServiceException(ResidentErrorCode.UNABLE_TO_PROCESS.getErrorCode(), ResidentErrorCode.UNABLE_TO_PROCESS.getErrorMessage()); - } catch (Exception var10) { - this.logger.error("sessionId", this.getClass().getSimpleName(), ResidentErrorCode.SERVER_ERROR.getErrorCode(), ResidentErrorCode.SERVER_ERROR.getErrorMessage()); - throw new ResidentServiceException(ResidentErrorCode.SERVER_ERROR.getErrorCode(), ResidentErrorCode.SERVER_ERROR.getErrorMessage()); - } - } - - @Override - public boolean validateOtp(String otp, String userId, String transactionId) throws ApisResourceAccessException, ResidentServiceCheckedException { - logger.info("sessionId", "idType", "id", "In validateOtp method of otpmanager service "); - String otpHash; - otpHash = digestAsPlainText( - (userId + this.environment.getProperty("mosip.kernel.data-key-splitter") + otp+transactionId).getBytes()); - - if (!otpRepo.existsByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS)) { - return false; - } - - OtpTransactionEntity otpTxn = otpRepo.findTopByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS); - otpTxn.setStatusCode(PreRegLoginConstant.USED_STATUS); - otpRepo.save(otpTxn); - if (!(otpTxn.getExpiryDtimes().isAfter(DateUtils.getUTCCurrentDateTime()))) { - logger.error(PreRegLoginConstant.SESSION_ID, this.getClass().getSimpleName(), - PreRegLoginErrorConstants.EXPIRED_OTP.getErrorCode(), OTP_EXPIRED); - throw new ResidentServiceException(ResidentErrorCode.EXPIRED_OTP.getErrorCode(), - ResidentErrorCode.EXPIRED_OTP.getErrorMessage()); - } - return true; - } - - public Tuple2 updateUserId(String userId, String transactionId) throws ApisResourceAccessException, ResidentServiceCheckedException { - ResidentUpdateRequestDto residentUpdateRequestDto = new ResidentUpdateRequestDto(); - String individualId= identityService.getResidentIndvidualIdFromSession(); - String individualIdType = templateUtil.getIndividualIdType(); - residentUpdateRequestDto.setIndividualId(individualId); - residentUpdateRequestDto.setConsent(ACCEPTED); - residentUpdateRequestDto.setIdentityJson(getIdentityJson(individualId, transactionId, userId, individualIdType)); - residentUpdateRequestDto.setIndividualIdType(individualIdType); - return residentService.reqUinUpdate(residentUpdateRequestDto); - } - - public String getIdentityJson(String individualId, String transactionId, String userId, String individualIdType) { - Map identityMap = new LinkedHashMap(); - identityMap.put("IDSchemaVersion", "0.1"); - identityMap.put(individualIdType, individualId); - String channel = getChannel(userId, transactionId); - identityMap.put(channel, userId); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("identity", identityMap); - String str = CryptoUtil.encodeToPlainBase64(jsonObject.toString().getBytes()); - return String.valueOf(str); - } - - public String getChannel(String userId, String transactionId) { - List channels = requestValidator.validateUserIdAndTransactionId(userId, transactionId); - if(channels.get(0).equalsIgnoreCase(PHONE)){ - return PHONE; - } else{ - return EMAIL; - } - } - - public static String digestAsPlainText(byte[] data) { - return DatatypeConverter.printHexBinary(data).toUpperCase(); - } - - public String hash(String id) throws ResidentServiceException { - return HMACUtils.digestAsPlainText(id.getBytes()); - } -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyOtpServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyOtpServiceImpl.java deleted file mode 100644 index 42b72472d84..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyOtpServiceImpl.java +++ /dev/null @@ -1,230 +0,0 @@ -package io.mosip.resident.service.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; - -import io.mosip.kernel.core.authmanager.model.AuthNResponse; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.kernel.core.util.DateUtils; -import io.mosip.preregistration.application.constant.PreRegLoginConstant; -import io.mosip.preregistration.core.util.GenericUtil; -import io.mosip.resident.config.LoggerConfiguration; -import io.mosip.resident.constant.EventStatusSuccess; -import io.mosip.resident.constant.RequestType; -import io.mosip.resident.constant.ResidentConstants; -import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.dto.ExceptionJSONInfoDTO; -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.entity.ResidentTransactionEntity; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.service.OtpManager; -import io.mosip.resident.service.ProxyOtpService; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.util.EventEnum; -import io.mosip.resident.util.Utility; -import io.mosip.resident.validator.RequestValidator; -import reactor.util.function.Tuple2; -import reactor.util.function.Tuples; - -/** - * @author Kamesh Shekhar Prasad - * This class is used to implement opt service impl class. - */ -@Service -public class ProxyOtpServiceImpl implements ProxyOtpService { - - private Logger log = LoggerConfiguration.logConfig(ProxyOtpServiceImpl.class); - - private List otpChannel; - - @Autowired - private OtpManager otpManager; - - @Autowired - private AuditUtil audit; - - @Autowired - RequestValidator requestValidator; - - @Autowired - private IdentityServiceImpl identityServiceImpl; - - @Autowired - private Utility utility; - - @Value("${mosip.mandatory-languages}") - private String mandatoryLanguage; - - @Override - public ResponseEntity> sendOtp(MainRequestDTO userOtpRequest) { - MainResponseDTO response = new MainResponseDTO<>(); - String userid = null; - boolean isSuccess = false; - String language = mandatoryLanguage; - log.info("In callsendOtp method of login service with userID: {} and langCode", - userOtpRequest.getRequest().getUserId(), language); - - try { - response = (MainResponseDTO) getMainResponseDto(userOtpRequest); - log.info("Response after loginCommonUtil {}", response); - - userid = userOtpRequest.getRequest().getUserId(); - otpChannel = requestValidator.validateUserIdAndTransactionId(userid, userOtpRequest.getRequest().getTransactionId()); - boolean otpSent = otpManager.sendOtp(userOtpRequest, otpChannel.get(0), language); - AuthNResponse authNResponse = null; - if (otpSent) { - if (otpChannel.get(0).equalsIgnoreCase(PreRegLoginConstant.PHONE_NUMBER)) - authNResponse = new AuthNResponse(PreRegLoginConstant.SMS_SUCCESS, PreRegLoginConstant.SUCCESS); - else - authNResponse = new AuthNResponse(PreRegLoginConstant.EMAIL_SUCCESS, PreRegLoginConstant.SUCCESS); - response.setResponse(authNResponse); - isSuccess = true; - } else - isSuccess = false; - - response.setResponsetime(DateUtils.getUTCCurrentDateTimeString()); - } catch (HttpServerErrorException | HttpClientErrorException ex) { - log.error("In callsendOtp method of login service- ", ex.getResponseBodyAsString()); - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.SEND_OTP_FAILURE, - userid, "Send OTP")); - if(ex instanceof HttpServerErrorException || ex instanceof HttpClientErrorException){ - throw new ResidentServiceException(ResidentErrorCode.CONFIG_FILE_NOT_FOUND_EXCEPTION.getErrorCode(), - ResidentErrorCode.CONFIG_FILE_NOT_FOUND_EXCEPTION.getErrorMessage()); - } - } - catch (Exception ex) { - log.error("In callsendOtp method of login service- ", ex); - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.SEND_OTP_FAILURE, - userid, "Send OTP")); - throw new ResidentServiceException(ResidentErrorCode.SEND_OTP_FAILED.getErrorCode(), - ResidentErrorCode.SEND_OTP_FAILED.getErrorMessage(), ex); - } finally { - if (isSuccess) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.SEND_OTP_SUCCESS, - userid, "Send OTP")); - } else { - - ExceptionJSONInfoDTO errors = new ExceptionJSONInfoDTO(ResidentErrorCode.SEND_OTP_FAILED.getErrorCode(), - ResidentErrorCode.SEND_OTP_FAILED.getErrorMessage()); - List lst = new ArrayList<>(); - lst.add(errors); - response.setErrors(lst); - response.setResponse(null); - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.SEND_OTP_FAILURE, - userid, "Send OTP")); - } - } - return ResponseEntity.status(HttpStatus.OK).body(response); - } - - @Override - public Tuple2, String> validateWithUserIdOtp(MainRequestDTO userIdOtpRequest) { - log.info("In calluserIdOtp method of login service "); - MainResponseDTO response = null; - response = (MainResponseDTO) getMainResponseDto(userIdOtpRequest); - String userid = null; - boolean isSuccess = false; - String eventId = ResidentConstants.NOT_AVAILABLE; - - try { - OtpRequestDTOV3 user = userIdOtpRequest.getRequest(); - userid = user.getUserId(); - String transactionId = user.getTransactionId(); - boolean validated = otpManager.validateOtp(user.getOtp(), userid, transactionId); - AuthNResponse authresponse = new AuthNResponse(); - if (validated) { - Tuple2 updateResult = otpManager.updateUserId(userid, transactionId); - eventId = updateResult.getT2(); - authresponse.setMessage(PreRegLoginConstant.VALIDATION_SUCCESS); - authresponse.setStatus(PreRegLoginConstant.SUCCESS); - } else { - throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED, - Map.of(ResidentConstants.EVENT_ID, eventId)); - } - response.setResponse(authresponse); - isSuccess = true; - } catch (ResidentServiceException ex) { - log.error("In calluserIdOtp method of login service- ", ex); - ex.setMetadata(Map.of(ResidentConstants.EVENT_ID, eventId)); - throw ex; - } catch (RuntimeException ex) { - log.error("In calluserIdOtp method of login service- ", ex); - throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED, ex, - Map.of(ResidentConstants.EVENT_ID, eventId)); - } catch (ResidentServiceCheckedException e) { - throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED, e, - Map.of(ResidentConstants.EVENT_ID, eventId)); - } catch (ApisResourceAccessException e) { - throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION, e, - Map.of(ResidentConstants.EVENT_ID, eventId)); - } finally { - response.setResponsetime(GenericUtil.getCurrentResponseTime()); - - if (isSuccess) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_OTP_SUCCESS, - userid, "Validate OTP Success")); - } else { - ExceptionJSONInfoDTO errors = new ExceptionJSONInfoDTO(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), - ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); - List lst = new ArrayList<>(); - lst.add(errors); - response.setErrors(lst); - response.setResponse(null); - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.OTP_VALIDATION_FAILED, - userid, "Validate OTP Failed")); - } - - } - return Tuples.of(response, eventId); - } - - private ResidentTransactionEntity createResidentTransactionEntity(String userId) - throws ApisResourceAccessException, ResidentServiceCheckedException { - ResidentTransactionEntity residentTransactionEntity = utility.createEntity(); - residentTransactionEntity.setEventId(utility.createEventId()); - residentTransactionEntity.setRequestTypeCode(RequestType.UPDATE_MY_UIN.name()); - residentTransactionEntity.setAuthTypeCode(identityServiceImpl.getResidentAuthenticationMode()); - residentTransactionEntity.setStatusCode(EventStatusSuccess.DATA_UPDATED.name()); - residentTransactionEntity.setAttributeList(userId); - String individualId = identityServiceImpl.getResidentIndvidualIdFromSession(); - residentTransactionEntity.setRefId(utility.convertToMaskDataFormat(individualId)); - residentTransactionEntity.setIndividualId(individualId); - residentTransactionEntity.setTokenId(identityServiceImpl.getResidentIdaToken()); - residentTransactionEntity.setRequestSummary(EventStatusSuccess.DATA_UPDATED.name()); - if (requestValidator.phoneValidator(userId)) { - residentTransactionEntity.setStatusComment("Update phone as " + userId); - } else if (requestValidator.emailValidator(userId)) { - residentTransactionEntity.setStatusComment("Update email as " + userId); - } - return residentTransactionEntity; - } - - /** - * This method will return the MainResponseDTO with id and version - * - * @param mainRequestDto - * @return MainResponseDTO - */ - public MainResponseDTO getMainResponseDto(MainRequestDTO mainRequestDto) { - log.info("In getMainResponseDTO method of ProxyOtpServiceImpl"); - MainResponseDTO response = new MainResponseDTO<>(); - response.setId(mainRequestDto.getId()); - response.setVersion(mainRequestDto.getVersion()); - return response; - } - -} 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 b8c0b565bd4..ffe47127513 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 @@ -13,7 +13,6 @@ 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; @@ -32,7 +31,6 @@ import io.mosip.kernel.core.util.CryptoUtil; import io.mosip.kernel.core.util.DateUtils; import io.mosip.kernel.core.util.StringUtils; -import io.mosip.preregistration.application.dto.TransliterationRequestDTO; import io.mosip.resident.constant.AuthTypeStatus; import io.mosip.resident.constant.CardType; import io.mosip.resident.constant.EventStatus; @@ -1097,21 +1095,6 @@ private void validateLanguageCode(String languageCode) { } } - public void validateId(io.mosip.preregistration.core.common.dto.MainRequestDTO requestDTO) { - if (Objects.nonNull(requestDTO.getId())) { - if (!requestDTO.getId().equals(transliterateId)) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "id", "Invalid Transliterate id")); - throw new InvalidInputException("id"); - } - } else { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "id", "id is null")); - throw new InvalidInputException("id"); - } - if (requestDTO.getRequest().getFromFieldLang().equalsIgnoreCase(requestDTO.getRequest().getToFieldLang())) { - throw new InvalidInputException("'from' and 'to' languages cannot be same"); - } - } - public List validateUserIdAndTransactionId(String userId, String transactionID) { validateTransactionId(transactionID); List list = new ArrayList<>(); 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/test/config/ResidentServiceConfigTest.java index 57a0243c821..11ffde0b3c0 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/test/config/ResidentServiceConfigTest.java @@ -18,8 +18,6 @@ import io.mosip.kernel.idvalidator.rid.impl.RidValidatorImpl; import io.mosip.kernel.idvalidator.uin.impl.UinValidatorImpl; import io.mosip.kernel.idvalidator.vid.impl.VidValidatorImpl; -import io.mosip.preregistration.application.service.TransliterationService; -import io.mosip.preregistration.application.service.util.TransliterationServiceUtil; import io.mosip.resident.repository.ResidentTransactionRepository; @Configuration @@ -36,12 +34,6 @@ public class ResidentServiceConfigTest { @MockBean private PacketWriter packetWriter; - @MockBean - private TransliterationService transliterationService; - - @MockBean - private TransliterationServiceUtil transliterationServiceUtil; - @Bean @Primary public VidValidator vidValidator1() { 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/test/controller/ProxyOtpControllerTest.java deleted file mode 100644 index 8bdc372d698..00000000000 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyOtpControllerTest.java +++ /dev/null @@ -1,177 +0,0 @@ -package io.mosip.resident.test.controller; - -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 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.core.env.Environment; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -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.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.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.InvalidInputException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.helper.ObjectStoreHelper; -import io.mosip.resident.service.ProxyOtpService; -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 - * This class is used to test proxy otp controller. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ResidentTestBootApplication.class) -@AutoConfigureMockMvc -@TestPropertySource(locations = "classpath:application.properties") -public class ProxyOtpControllerTest { - - @MockBean - private RequestValidator validator; - - @Mock - private AuditUtil audit; - - @MockBean - private ObjectStoreHelper objectStore; - - - @MockBean - @Qualifier("selfTokenRestTemplate") - private RestTemplate residentRestTemplate; - - @InjectMocks - ProxyOtpController proxyOtpController; - - @MockBean - ProxyOtpService proxyOtpService; - - @MockBean - IdentityServiceImpl identityService; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private ResidentVidService vidService; - - @MockBean - private CryptoCoreSpec encryptor; - - @MockBean - private AuditUtil auditUtil; - - @MockBean - private ResidentServiceImpl residentService; - - @Mock - private Utility utility; - - @Mock - private Environment environment; - - Gson gson = new GsonBuilder().serializeNulls().create(); - - private MainRequestDTO userOtpRequest; - - private MainRequestDTO userIdOtpRequest; - - String reqJson; - - byte[] pdfbytes; - - private ResponseEntity> responseEntity; - - private MainResponseDTO response; - - @Before - public void setup() throws Exception { - MockitoAnnotations.initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(proxyOtpController).build(); - userOtpRequest = new MainRequestDTO<>(); - userIdOtpRequest = new MainRequestDTO<>(); - OtpRequestDTOV2 otpRequestDTOV2 = new OtpRequestDTOV2(); - otpRequestDTOV2.setUserId("8809909090"); - otpRequestDTOV2.setTransactionId("1234343434"); - userOtpRequest.setRequest(otpRequestDTOV2); - userOtpRequest.setId("mosip.resident.contact.details.send.otp.id"); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("111"); - otpRequestDTOV3.setUserId("8809909090"); - otpRequestDTOV3.setTransactionId("1234343434"); - userIdOtpRequest.setRequest(otpRequestDTOV3); - userIdOtpRequest.setId("mosip.resident.contact.details.update.id"); - reqJson = gson.toJson(userOtpRequest); - AuthNResponse authNResponse = new AuthNResponse(PreRegLoginConstant.EMAIL_SUCCESS, PreRegLoginConstant.SUCCESS); - response = new MainResponseDTO<>(); - response.setResponse(authNResponse); - responseEntity = new ResponseEntity<>(HttpStatus.OK); - Mockito.when(environment.getProperty(Mockito.anyString())).thenReturn("property"); - } - - @Test - public void testSendOtp() throws Exception { - Mockito.when(proxyOtpService.sendOtp(Mockito.any())).thenReturn(responseEntity); - mockMvc.perform(MockMvcRequestBuilders.post("/contact-details/send-otp").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(reqJson.getBytes())).andExpect(status().isOk()); - } - - @Test(expected = ResidentServiceException.class) - public void testSendOtpException() throws Exception { - doThrow(new InvalidInputException("error message")).when(validator).validateProxySendOtpRequest(Mockito.any()); - proxyOtpController.sendOTP(userOtpRequest); - } - - @Test - public void testValidateOtp() throws Exception { - Mockito.when(proxyOtpService.validateWithUserIdOtp(Mockito.any())).thenReturn(Tuples.of(response, "12345")); - mockMvc.perform(MockMvcRequestBuilders.post("/contact-details/update-data").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(reqJson.getBytes())).andExpect(status().isOk()); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpException() throws Exception { - doThrow(new InvalidInputException("error message")).when(validator).validateUpdateDataRequest(Mockito.any()); - proxyOtpController.validateWithUserIdOtp(userIdOtpRequest); - } - -} 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/test/controller/TransliterationControllerTest.java deleted file mode 100644 index 75caca0fae5..00000000000 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/TransliterationControllerTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package io.mosip.resident.test.controller; - -import static org.junit.Assert.assertEquals; - -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.Qualifier; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.web.client.RestTemplate; - -import io.mosip.preregistration.application.dto.TransliterationRequestDTO; -import io.mosip.preregistration.application.dto.TransliterationResponseDTO; -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; -import io.mosip.resident.service.impl.ResidentVidServiceImpl; -import io.mosip.resident.util.AuditUtil; -import io.mosip.resident.validator.RequestValidator; - -/** - * Acknowledgment Controller Test - * Note: This class is used to test the Acknowledgment Controller - * @author Kamesh Shekhar Prasad - */ - -@RunWith(MockitoJUnitRunner.class) -@ContextConfiguration -public class TransliterationControllerTest { - @InjectMocks - private TransliterationController transliterationController; - - @Mock - private AuditUtil auditUtil; - - @Mock - private RequestValidator requestValidator; - - @Mock - private TransliterationService transliterationService; - - @Mock - private IdentityServiceImpl identityService; - - @Mock - private ObjectStoreHelper objectStore; - - @Mock - private ResidentVidServiceImpl residentVidService; - - @MockBean - @Qualifier("selfTokenRestTemplate") - private RestTemplate residentRestTemplate; - - @Mock - private IdAuthService idAuthService; - - private ResponseEntity> response; - - @Test - public void testCreateRequestGenerationSuccess() throws Exception { - MainResponseDTO response = new MainResponseDTO<>(); - TransliterationResponseDTO dto = new TransliterationResponseDTO(); - response.setResponse(dto); - MainRequestDTO requestDTO = new MainRequestDTO<>(); - TransliterationRequestDTO transliterationRequestDTO = new TransliterationRequestDTO(); - transliterationRequestDTO.setFromFieldLang("eng"); - transliterationRequestDTO.setFromFieldValue("cat"); - transliterationRequestDTO.setToFieldLang("hin"); - requestDTO.setRequest(transliterationRequestDTO); - Mockito.when(transliterationService.translitratorService(Mockito.any())).thenReturn(response); - - ResponseEntity> responseEntity = transliterationController.translitrator(requestDTO); - assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); - } - -} 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/test/service/OTPManagerServiceImplTest.java deleted file mode 100644 index 8a8758fadbe..00000000000 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/OTPManagerServiceImplTest.java +++ /dev/null @@ -1,186 +0,0 @@ -package io.mosip.resident.test.service; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatchers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.client.RestTemplate; - -import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.kernel.core.util.DateUtils; -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.dto.NotificationResponseDTO; -import io.mosip.resident.dto.OtpRequestDTOV2; -import io.mosip.resident.entity.OtpTransactionEntity; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.repository.OtpTransactionRepository; -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; -import io.mosip.resident.validator.RequestValidator; - -/** - * This class is used to test Otp Manger service impl class. - * @author Kamesh Shekhar Prasad - */ -@RunWith(MockitoJUnitRunner.class) -@RefreshScope -@ContextConfiguration -public class OTPManagerServiceImplTest { - - @Mock - private ResidentServiceRestClient residentServiceRestClient; - - @Mock - Environment env; - - @Mock - private AuditUtil audit; - - @InjectMocks - private OtpManagerServiceImpl otpManagerService; - - @Mock - private IdentityServiceImpl identityServiceImpl; - - @Mock - @Qualifier("selfTokenRestTemplate") - private RestTemplate restTemplate; - - @Mock - private ResidentTransactionRepository residentTransactionRepository; - - @Autowired - private MockMvc mockMvc; - - @Mock - private NotificationService notificationService; - - private NotificationResponseDTO notificationResponseDTO; - - private MainRequestDTO requestDTO; - - private OtpRequestDTOV2 otpRequestDTOV2; - - - @Mock - private OtpTransactionRepository otpTransactionRepository; - - private ResponseWrapper> response; - - @Mock - private Environment environment; - - private ResponseEntity response1; - - @Mock - private TemplateUtil templateUtil; - - @Mock - private RequestValidator requestValidator; - - @Mock - private ResidentService residentService; - - @Before - public void setup() throws ApisResourceAccessException, ResidentServiceCheckedException { - MockitoAnnotations.initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(otpManagerService).build(); - response = new ResponseWrapper<>(); - Map responseMap = new HashMap<>(); - responseMap.put("otp", "111111"); - responseMap.put("status", "PASSED"); - response.setResponse(responseMap); - otpRequestDTOV2 = new OtpRequestDTOV2(); - requestDTO = new MainRequestDTO<>(); - otpRequestDTOV2.setTransactionId("1234567891"); - otpRequestDTOV2.setUserId("kamesh@gmail.com"); - requestDTO.setRequest(otpRequestDTOV2); - Mockito.when(identityServiceImpl.getResidentIndvidualIdFromSession()).thenReturn("2123456"); - when(otpTransactionRepository.checkotpsent(any(), any(), any(), any())).thenReturn(0); - ResponseWrapper> responseMap1=new ResponseWrapper<>(); - responseMap1.setResponse(responseMap); - response1 = new ResponseEntity<>(responseMap1, HttpStatus.ACCEPTED); - Mockito.when(environment.getProperty(Mockito.any())).thenReturn("https://dev.mosip.net/v1/otpmanager/otp/generate"); - Mockito.when(restTemplate.exchange(ArgumentMatchers.anyString(), - ArgumentMatchers.any(HttpMethod.class), - ArgumentMatchers.any(), - Mockito.eq(ResponseWrapper.class))) - .thenReturn(response1); - Mockito.when(environment.getProperty(any())).thenReturn("http://localhost:8099"); - Mockito.when(environment.getProperty("otp.request.flooding.duration", Long.class)).thenReturn(45L); - Mockito.when(environment.getProperty("mosip.kernel.otp.expiry-time", Long.class)).thenReturn(45L); - Mockito.when(environment.getProperty("otp.request.flooding.max-count", Integer.class)).thenReturn(8); -} - - @Test - public void testSendOtpSuccess() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - assertEquals(true, otpManagerService.sendOtp(requestDTO, "EMAIL", "eng")); - } - - @Test(expected = ResidentServiceCheckedException.class) - public void testSendOtpAlreadyOtpSendError() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - when(otpTransactionRepository.checkotpsent(any(), any(), any(), any())).thenReturn(9); - assertEquals(true, otpManagerService.sendOtp(requestDTO, "EMAIL", "eng")); - } - - @Test - public void testSendOtpOtpSendWithinLessTime() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - OtpTransactionEntity otpTransactionEntity = new OtpTransactionEntity(); - assertEquals(true, otpManagerService.sendOtp(requestDTO, "EMAIL", "eng")); - } - - @Test - public void testSendOtpPhoneSuccess() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - assertEquals(true, otpManagerService.sendOtp(requestDTO, "PHONE", "eng")); - } - - @Test - public void testValidateOtpSuccess() throws ResidentServiceCheckedException, ApisResourceAccessException { - when(otpTransactionRepository.existsByOtpHashAndStatusCode(Mockito.anyString(), Mockito.anyString())).thenReturn(true); - OtpTransactionEntity otpTransactionEntity = new OtpTransactionEntity(); - otpTransactionEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plusSeconds(120)); - when(otpTransactionRepository.findTopByOtpHashAndStatusCode(Mockito.anyString(), Mockito.anyString())).thenReturn(otpTransactionEntity); - assertEquals(true, otpManagerService.validateOtp("111111", "kamesh@gmail.com", "1234565656")); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpFailure() throws ResidentServiceCheckedException, ApisResourceAccessException { - when(otpTransactionRepository.existsByOtpHashAndStatusCode(Mockito.anyString(), Mockito.anyString())).thenReturn(true); - OtpTransactionEntity otpTransactionEntity = new OtpTransactionEntity(); - otpTransactionEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime()); - when(otpTransactionRepository.findTopByOtpHashAndStatusCode(Mockito.anyString(), Mockito.anyString())).thenReturn(otpTransactionEntity); - assertEquals(true, otpManagerService.validateOtp("111111", "kamesh@gmail.com", "1234565656")); - } - -} \ No newline at end of file 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/test/service/ProxyOtpServiceImpllTest.java deleted file mode 100644 index 9b517fb30ae..00000000000 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyOtpServiceImpllTest.java +++ /dev/null @@ -1,273 +0,0 @@ -package io.mosip.resident.test.service; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; - -import java.io.IOException; -import java.util.HashMap; -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.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.RestTemplate; - -import io.mosip.kernel.core.authmanager.model.AuthNResponse; -import io.mosip.kernel.core.http.ResponseWrapper; -import io.mosip.preregistration.application.constant.PreRegLoginConstant; -import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.dto.MainRequestDTO; -import io.mosip.resident.dto.MainResponseDTO; -import io.mosip.resident.dto.NotificationResponseDTO; -import io.mosip.resident.dto.OtpRequestDTOV2; -import io.mosip.resident.dto.OtpRequestDTOV3; -import io.mosip.resident.exception.ApisResourceAccessException; -import io.mosip.resident.exception.ResidentServiceCheckedException; -import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.repository.OtpTransactionRepository; -import io.mosip.resident.repository.ResidentTransactionRepository; -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; -import io.mosip.resident.util.Utility; -import io.mosip.resident.validator.RequestValidator; -import reactor.util.function.Tuples; - -/** - * This class is used to test proxy otp service impl class. - * @author Kamesh Shekhar Prasad - */ -@RunWith(MockitoJUnitRunner.class) -@RefreshScope -@ContextConfiguration -public class ProxyOtpServiceImpllTest { - - @Mock - private ResidentServiceRestClient residentServiceRestClient; - - @Mock - Environment env; - - @Mock - private AuditUtil audit; - - @InjectMocks - private ProxyOtpServiceImpl proxyOtpService; - - @Mock - private IdentityServiceImpl identityServiceImpl; - - @Mock - private Utility utility; - - @Mock - @Qualifier("selfTokenRestTemplate") - private RestTemplate restTemplate; - - @Mock - private ResidentTransactionRepository residentTransactionRepository; - - @Autowired - private MockMvc mockMvc; - - @Mock - private NotificationService notificationService; - - private NotificationResponseDTO notificationResponseDTO; - - private MainRequestDTO requestDTO; - - private OtpRequestDTOV2 otpRequestDTOV2; - - - @Mock - private OtpTransactionRepository otpTransactionRepository; - - private ResponseWrapper> response; - - @Mock - private Environment environment; - - private ResponseEntity response1; - - @Mock - private TemplateUtil templateUtil; - - @Mock - private RequestValidator requestValidator; - - @Mock - private ResidentService residentService; - - @Mock - private OtpManager otpManager; - - private ResponseEntity> responseEntity; - - @Before - public void setup() throws ApisResourceAccessException, ResidentServiceCheckedException, IOException { - MockitoAnnotations.initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(proxyOtpService).build(); - response = new ResponseWrapper<>(); - Map responseMap = new HashMap<>(); - responseMap.put("otp", "111111"); - responseMap.put("status", "PASSED"); - response.setResponse(responseMap); - otpRequestDTOV2 = new OtpRequestDTOV2(); - requestDTO = new MainRequestDTO<>(); - otpRequestDTOV2.setTransactionId("1234567891"); - otpRequestDTOV2.setUserId("kamesh@gmail.com"); - requestDTO.setRequest(otpRequestDTOV2); - ResponseWrapper> responseMap1 = new ResponseWrapper<>(); - responseMap1.setResponse(responseMap); - response1 = new ResponseEntity<>(responseMap1, HttpStatus.ACCEPTED); - Mockito.when(requestValidator.validateUserIdAndTransactionId(Mockito.anyString(), Mockito.anyString())).thenReturn(List.of("EMAIL")); - ReflectionTestUtils.setField(proxyOtpService, "mandatoryLanguage", "eng"); - Mockito.when(otpManager.sendOtp(any(), any(), any())).thenReturn(true); - AuthNResponse authNResponse = new AuthNResponse(PreRegLoginConstant.EMAIL_SUCCESS, PreRegLoginConstant.SUCCESS); - MainResponseDTO response = new MainResponseDTO<>(); - response.setResponse(authNResponse); - responseEntity = new ResponseEntity<>(HttpStatus.OK); - } - - @Test - public void testSendOtpEmailSuccess() { - assertEquals(responseEntity.getStatusCode(), proxyOtpService.sendOtp(requestDTO).getStatusCode()); - } - - @Test - public void testSendOtpPhoneSuccess() { - otpRequestDTOV2.setUserId("8809463737"); - requestDTO.setRequest(otpRequestDTOV2); - Mockito.when(requestValidator.validateUserIdAndTransactionId(Mockito.anyString(), - Mockito.anyString())).thenReturn(List.of("PHONE")); - assertEquals(responseEntity.getStatusCode(), proxyOtpService.sendOtp(requestDTO).getStatusCode()); - } - - @Test - public void testSendOtpFailure() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - Mockito.when(otpManager.sendOtp(any(), any(), any())).thenReturn(false); - assertEquals(responseEntity.getStatusCode(), proxyOtpService.sendOtp(requestDTO).getStatusCode()); - } - - @Test(expected = ResidentServiceException.class) - public void testHttpServerErrorException() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - Mockito.when(otpManager.sendOtp(any(), any(), any())).thenThrow(new HttpServerErrorException(HttpStatus.BAD_GATEWAY)); - assertEquals(responseEntity.getStatusCode(), proxyOtpService.sendOtp(requestDTO).getStatusCode()); - } - - @Test(expected = ResidentServiceException.class) - public void testHttpClientErrorException() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - Mockito.when(otpManager.sendOtp(any(), any(), any())).thenThrow(new HttpClientErrorException(HttpStatus.BAD_GATEWAY)); - assertEquals(responseEntity.getStatusCode(), proxyOtpService.sendOtp(requestDTO).getStatusCode()); - } - - @Test(expected = ResidentServiceException.class) - public void testResidentServiceException() throws ResidentServiceCheckedException, IOException, ApisResourceAccessException { - Mockito.when(otpManager.sendOtp(any(), any(), any())) - .thenThrow(new ResidentServiceException(ResidentErrorCode.SEND_OTP_FAILED.getErrorCode(), - ResidentErrorCode.SEND_OTP_FAILED.getErrorMessage())); - assertEquals(responseEntity.getStatusCode(), proxyOtpService.sendOtp(requestDTO).getStatusCode()); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpFailure() { - MainRequestDTO requestDTO1 = new MainRequestDTO<>(); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("11111"); - otpRequestDTOV3.setUserId("ka@gm.com"); - otpRequestDTOV3.setTransactionId("122222222"); - requestDTO1.setRequest(otpRequestDTOV3); - assertEquals("12345", proxyOtpService.validateWithUserIdOtp(requestDTO1).getT2()); - } - - @Test - public void testValidateOtpSuccess() throws ResidentServiceCheckedException, ApisResourceAccessException { - MainRequestDTO requestDTO1 = new MainRequestDTO<>(); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("11111"); - otpRequestDTOV3.setUserId("ka@gm.com"); - otpRequestDTOV3.setTransactionId("122222222"); - requestDTO1.setRequest(otpRequestDTOV3); - Mockito.when(otpManager.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(true); - Mockito.when(otpManager.updateUserId(Mockito.anyString(), Mockito.anyString())).thenReturn(Tuples.of(new Object(), "12345")); - assertEquals("12345", proxyOtpService.validateWithUserIdOtp(requestDTO1).getT2()); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpFailureResidentServiceException() throws ResidentServiceCheckedException, ApisResourceAccessException { - MainRequestDTO requestDTO1 = new MainRequestDTO<>(); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("11111"); - otpRequestDTOV3.setUserId("ka@gm.com"); - otpRequestDTOV3.setTransactionId("122222222"); - requestDTO1.setRequest(otpRequestDTOV3); - Mockito.when(otpManager.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())). - thenThrow(new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), - ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage())); - assertEquals("12345", proxyOtpService.validateWithUserIdOtp(requestDTO1).getT2()); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpFailureRuntimeException() throws ResidentServiceCheckedException, ApisResourceAccessException { - MainRequestDTO requestDTO1 = new MainRequestDTO<>(); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("11111"); - otpRequestDTOV3.setUserId("ka@gm.com"); - otpRequestDTOV3.setTransactionId("122222222"); - requestDTO1.setRequest(otpRequestDTOV3); - Mockito.when(otpManager.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())). - thenThrow(new RuntimeException()); - assertEquals("12345", proxyOtpService.validateWithUserIdOtp(requestDTO1).getT2()); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpFailureResidentServiceCheckedException() throws ResidentServiceCheckedException, ApisResourceAccessException { - MainRequestDTO requestDTO1 = new MainRequestDTO<>(); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("11111"); - otpRequestDTOV3.setUserId("ka@gm.com"); - otpRequestDTOV3.setTransactionId("122222222"); - requestDTO1.setRequest(otpRequestDTOV3); - Mockito.when(otpManager.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())). - thenThrow(new ResidentServiceCheckedException()); - assertEquals("12345", proxyOtpService.validateWithUserIdOtp(requestDTO1).getT2()); - } - - @Test(expected = ResidentServiceException.class) - public void testValidateOtpFailureApiResourceException() throws ResidentServiceCheckedException, ApisResourceAccessException { - MainRequestDTO requestDTO1 = new MainRequestDTO<>(); - OtpRequestDTOV3 otpRequestDTOV3 = new OtpRequestDTOV3(); - otpRequestDTOV3.setOtp("11111"); - otpRequestDTOV3.setUserId("ka@gm.com"); - otpRequestDTOV3.setTransactionId("122222222"); - requestDTO1.setRequest(otpRequestDTOV3); - Mockito.when(otpManager.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())). - thenThrow(new ApisResourceAccessException()); - assertEquals("12345", proxyOtpService.validateWithUserIdOtp(requestDTO1).getT2()); - } - -} \ No newline at end of file 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/test/validator/RequestValidatorTest.java index eae6fb5a652..b4046fad600 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/test/validator/RequestValidatorTest.java @@ -29,8 +29,6 @@ import io.mosip.kernel.core.idvalidator.spi.UinValidator; import io.mosip.kernel.core.idvalidator.spi.VidValidator; import io.mosip.kernel.core.util.DateUtils; -import io.mosip.preregistration.application.dto.TransliterationRequestDTO; -import io.mosip.preregistration.core.common.dto.MainRequestDTO; import io.mosip.resident.constant.AuthTypeStatus; import io.mosip.resident.constant.CardType; import io.mosip.resident.constant.IdType; @@ -1624,24 +1622,6 @@ public void testValidateRevokeVidRequestWrapper() throws Exception{ requestValidator.validateRevokeVidRequestWrapper(requestWrapper, "v1"); } - @Test(expected = InvalidInputException.class) - public void testValidateId() throws Exception{ - ReflectionTestUtils.setField(requestValidator, "transliterateId", "mosip.resident.transliteration.transliterate"); - MainRequestDTO requestDTO = new MainRequestDTO<>(); - TransliterationRequestDTO transliterationRequestDTO = new TransliterationRequestDTO(); - requestDTO.setId(null); - requestValidator.validateId(requestDTO); - } - - @Test(expected = InvalidInputException.class) - public void testValidateTransliterationId() throws Exception{ - ReflectionTestUtils.setField(requestValidator, "transliterateId", "mosip.resident.transliteration.transliterate"); - MainRequestDTO requestDTO = new MainRequestDTO<>(); - TransliterationRequestDTO transliterationRequestDTO = new TransliterationRequestDTO(); - requestDTO.setId("mosip"); - requestValidator.validateId(requestDTO); - } - @Test(expected = InvalidInputException.class) public void testValidateRequestNewApi() throws Exception{ RequestWrapper request = new RequestWrapper<>(); @@ -2069,19 +2049,6 @@ public void testNullUserIdAndTransactionId(){ requestValidator.validateUserIdAndTransactionId(null, "3232323232"); } - @Test - public void testValidateTransliterationIdSuccess() throws Exception{ - ReflectionTestUtils.setField(requestValidator, "transliterateId", "mosip.resident.transliteration.transliterate"); - MainRequestDTO requestDTO = new MainRequestDTO<>(); - TransliterationRequestDTO transliterationRequestDTO = new TransliterationRequestDTO(); - transliterationRequestDTO.setFromFieldLang("eng"); - transliterationRequestDTO.setToFieldLang("fra"); - transliterationRequestDTO.setFromFieldValue("demo"); - requestDTO.setRequest(transliterationRequestDTO); - requestDTO.setId("mosip.resident.transliteration.transliterate"); - requestValidator.validateId(requestDTO); - } - @Test(expected = InvalidInputException.class) public void testValidateOnlyLanguageCode(){ requestValidator.validateOnlyLanguageCode(null);