diff --git a/.github/workflows/db-test.yml b/.github/workflows/db-test.yml new file mode 100644 index 0000000000..c3ed7de2b3 --- /dev/null +++ b/.github/workflows/db-test.yml @@ -0,0 +1,37 @@ +name: PostgreSQL Test + +on: + release: + types: [published] + pull_request: + types: [opened, reopened, synchronize] + workflow_dispatch: + inputs: + message: + description: 'Message for manually triggering' + required: false + default: 'Triggered for Updates' + type: string + push: + branches: + - '!release-branch' + - release* + - master + - 1.* + - develop* + - MOSIP* + paths: + - 'db_scripts/**' + +jobs: + build-db-test: + strategy: + matrix: + include: + - DB_LOCATION: 'db_scripts/mosip_pms' + DB_NAME: 'mosip_pms' + fail-fast: false + name: ${{ matrix.DB_NAME }} + uses: mosip/kattu/.github/workflows/db-test.yml@master + with: + DB_LOCATION: ${{ matrix.DB_LOCATION}} diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index db27b6a745..9cd9465294 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -4,7 +4,7 @@ on: release: types: [published] pull_request: - types: [opened] + types: [opened, reopened, synchronize] workflow_dispatch: inputs: message: @@ -35,7 +35,8 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} publish_to_nexus: - if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' }}" + if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' && github.event_name != 'release' && github.event_name != 'prerelease' && github.event_name != 'publish' }}" + needs: build-maven-partner uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master with: @@ -85,4 +86,5 @@ jobs: OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} GPG_SECRET: ${{ secrets.GPG_SECRET }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} \ No newline at end of file + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + diff --git a/db_scripts/mosip_pms/deploy.sh b/db_scripts/mosip_pms/deploy.sh index 75055ed43d..0d0c3a8097 100644 --- a/db_scripts/mosip_pms/deploy.sh +++ b/db_scripts/mosip_pms/deploy.sh @@ -1,4 +1,4 @@ -#!/bin/sh + ## Properties file set -e properties_file="$1" diff --git a/db_scripts/mosip_pms/dml/pms-partner_policy_bioextract.csv b/db_scripts/mosip_pms/dml/pms-partner_policy_bioextract.csv index e55356be37..020d043cb6 100644 --- a/db_scripts/mosip_pms/dml/pms-partner_policy_bioextract.csv +++ b/db_scripts/mosip_pms/dml/pms-partner_policy_bioextract.csv @@ -1,22 +1,22 @@ id,part_id,policy_id,attribute_name,extractor_provider,extractor_provider_version,biometric_modality,biometric_sub_types,cr_by,cr_dtimes,upd_by,upd_dtimes -146098,mpartner-default-auth,mpolicy-default-auth,photo,mock,1.1,face,,admin,now(),admin,now() -146099,mpartner-default-auth,mpolicy-default-auth,iris,mock,1.1,iris,,admin,now(),admin,now() -146100,mpartner-default-auth,mpolicy-default-auth,fingerprint,mock,1.1,finger,,admin,now(),admin,now() -146101,mpartner-default-print,mpolicy-default-qrcode,photo,mock,1.1,face,,admin,now(),admin,now() -146102,mpartner-default-print,mpolicy-default-qrcode,iris,mock,1.1,iris,,admin,now(),admin,now() -146103,mpartner-default-print,mpolicy-default-qrcode,fingerprint,mock,1.1,finger,,admin,now(),admin,now() -146104,mpartner-default-print,mpolicy-default-euin,photo,mock,1.1,face,,admin,now(),admin,now() -146105,mpartner-default-print,mpolicy-default-euin,iris,mock,1.1,iris,,admin,now(),admin,now() -146106,mpartner-default-print,mpolicy-default-euin,fingerprint,mock,1.1,finger,,admin,now(),admin,now() -146107,mpartner-default-print,mpolicy-default-reprint,photo,mock,1.1,face,,admin,now(),admin,now() -146108,mpartner-default-print,mpolicy-default-reprint,iris,mock,1.1,iris,,admin,now(),admin,now() -146109,mpartner-default-print,mpolicy-default-reprint,fingerprint,mock,1.1,finger,,admin,now(),admin,now() -146110,mpartner-default-print,mpolicy-default-eUIN_with_QR,photo,mock,1.1,face,,admin,now(),admin,now() -146111,mpartner-default-print,mpolicy-default-eUIN_with_QR,iris,mock,1.1,iris,,admin,now(),admin,now() -146112,mpartner-default-print,mpolicy-default-eUIN_with_QR,fingerprint,mock,1.1,finger,,admin,now(),admin,now() -146113,mpartner-default-print,mpolicy-default-eUIN_with_faceQR,photo,mock,1.1,face,,admin,now(),admin,now() -146114,mpartner-default-print,mpolicy-default-eUIN_with_faceQR,iris,mock,1.1,iris,,admin,now(),admin,now() -146115,mpartner-default-print,mpolicy-default-eUIN_with_faceQR,fingerprint,mock,1.1,finger,,admin,now(),admin,now() -146116,mpartner-default-digitalcard,mpolicy-default-PDFCard,photo,mock,1.1,face,,admin,now(),admin,now() -146117,mpartner-default-digitalcard,mpolicy-default-PDFCard,iris,mock,1.1,iris,,admin,now(),admin,now() -146118,mpartner-default-digitalcard,mpolicy-default-PDFCard,fingerprint,mock,1.1,finger,,admin,now(),admin,now() +146098,mpartner-default-auth,mpolicy-default-auth,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146099,mpartner-default-auth,mpolicy-default-auth,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146100,mpartner-default-auth,mpolicy-default-auth,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() +146101,mpartner-default-print,mpolicy-default-qrcode,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146102,mpartner-default-print,mpolicy-default-qrcode,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146103,mpartner-default-print,mpolicy-default-qrcode,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() +146104,mpartner-default-print,mpolicy-default-euin,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146105,mpartner-default-print,mpolicy-default-euin,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146106,mpartner-default-print,mpolicy-default-euin,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() +146107,mpartner-default-print,mpolicy-default-reprint,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146108,mpartner-default-print,mpolicy-default-reprint,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146109,mpartner-default-print,mpolicy-default-reprint,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() +146110,mpartner-default-print,mpolicy-default-eUIN_with_QR,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146111,mpartner-default-print,mpolicy-default-eUIN_with_QR,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146112,mpartner-default-print,mpolicy-default-eUIN_with_QR,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() +146113,mpartner-default-print,mpolicy-default-eUIN_with_faceQR,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146114,mpartner-default-print,mpolicy-default-eUIN_with_faceQR,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146115,mpartner-default-print,mpolicy-default-eUIN_with_faceQR,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() +146116,mpartner-default-digitalcard,mpolicy-default-PDFCard,individualBiometrics,mock,1.1,face,,admin,now(),admin,now() +146117,mpartner-default-digitalcard,mpolicy-default-PDFCard,individualBiometrics,mock,1.1,iris,,admin,now(),admin,now() +146118,mpartner-default-digitalcard,mpolicy-default-PDFCard,individualBiometrics,mock,1.1,finger,,admin,now(),admin,now() diff --git a/db_scripts/mosip_pms/dml/pms-partner_type.csv b/db_scripts/mosip_pms/dml/pms-partner_type.csv index 3809c77f22..6c6e015c43 100644 --- a/db_scripts/mosip_pms/dml/pms-partner_type.csv +++ b/db_scripts/mosip_pms/dml/pms-partner_type.csv @@ -7,7 +7,7 @@ FTM_Provider,FTM Provider,TRUE,superadmin,now(),FALSE Online_Verification_Partner,Online_Verification_Partner,TRUE,superadmin,now(),TRUE ABIS_Partner,ABIS Partner,TRUE,superadmin,now(),TRUE Manual_Adjudication,Manual Adjudication,TRUE,superadmin,now(),TRUE -MISP_Partner,MISP_Partner,TRUE,superadmin,now(),TRUE +MISP_Partner,MISP_Partner,TRUE,superadmin,now(),FALSE Internal_Partner,Used internally to share certs,TRUE,superadmin,now(),TRUE SDK_Partner,SDK Partner,TRUE,superadmin,now(),FALSE Print_Partner,Print Partner,TRUE,superadmin,now(),TRUE diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/util/AuditUtil.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/util/AuditUtil.java index 3af1ac60c3..6fee1c51f9 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/util/AuditUtil.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/util/AuditUtil.java @@ -10,6 +10,7 @@ import javax.annotation.PostConstruct; +import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -341,4 +342,43 @@ private void handlException(HttpStatusCodeException ex) { } + public void setAuditRequestDto(ClientServiceAuditEnum clientServiceAuditEnum, String refId, String refIdType) { + AuditRequestDto auditRequestDto = new AuditRequestDto(); + auditRequestDto.setHostIp(hostIpAddress); + auditRequestDto.setHostName(hostName);; + auditRequestDto.setApplicationId(clientServiceAuditEnum.getApplicationId()); + auditRequestDto.setApplicationName(clientServiceAuditEnum.getApplicationName()); + auditRequestDto.setSessionUserId(SecurityContextHolder.getContext().getAuthentication().getName()); + auditRequestDto.setSessionUserName(SecurityContextHolder.getContext().getAuthentication().getName()); + auditRequestDto.setCreatedBy(SecurityContextHolder.getContext().getAuthentication().getName()); + auditRequestDto.setActionTimeStamp(DateUtils.getUTCCurrentDateTime()); + auditRequestDto.setDescription(clientServiceAuditEnum.getDescription()); + auditRequestDto.setEventType(clientServiceAuditEnum.getType()); + auditRequestDto.setEventName(clientServiceAuditEnum.getName()); + auditRequestDto.setModuleId(clientServiceAuditEnum.getModuleId()); + auditRequestDto.setModuleName(clientServiceAuditEnum.getModuleName()); + auditRequestDto.setEventId(clientServiceAuditEnum.getEventId()); + auditRequestDto.setId(refId); + auditRequestDto.setIdType(refIdType); + callAuditManager(auditRequestDto); + } + + public void setAuditRequestDto(ClientServiceAuditEnum clientServiceAuditEnum) { + AuditRequestDto auditRequestDto = new AuditRequestDto(); + auditRequestDto.setHostIp(hostIpAddress); + auditRequestDto.setHostName(hostName);; + auditRequestDto.setApplicationId(clientServiceAuditEnum.getApplicationId()); + auditRequestDto.setApplicationName(clientServiceAuditEnum.getApplicationName()); + auditRequestDto.setSessionUserId(SecurityContextHolder.getContext().getAuthentication().getName()); + auditRequestDto.setSessionUserName(SecurityContextHolder.getContext().getAuthentication().getName()); + auditRequestDto.setCreatedBy(SecurityContextHolder.getContext().getAuthentication().getName()); + auditRequestDto.setActionTimeStamp(DateUtils.getUTCCurrentDateTime()); + auditRequestDto.setDescription(clientServiceAuditEnum.getDescription()); + auditRequestDto.setEventType(clientServiceAuditEnum.getType()); + auditRequestDto.setEventName(clientServiceAuditEnum.getName()); + auditRequestDto.setModuleId(clientServiceAuditEnum.getModuleId()); + auditRequestDto.setModuleName(clientServiceAuditEnum.getModuleName()); + auditRequestDto.setEventId(clientServiceAuditEnum.getEventId()); + callAuditManager(auditRequestDto); + } } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/contant/ClientServiceAuditEnum.java b/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/contant/ClientServiceAuditEnum.java new file mode 100644 index 0000000000..3787e12d40 --- /dev/null +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/contant/ClientServiceAuditEnum.java @@ -0,0 +1,100 @@ +package io.mosip.pms.oidc.client.contant; + +import io.mosip.pms.partner.manager.constant.AuditConstant; + +public enum ClientServiceAuditEnum { + + CREATE_CLIENT("PMS_PRT_300", AuditConstant.AUDIT_SYSTEM, "POST CREATE OIDC CLIENT", + "Creating the OIDC Client", AuditConstant.PARTNER_MODULE_ID, AuditConstant.PARTNER_MODULE_NAME, "NO_ID", + "NO_ID_TYPE", AuditConstant.APPLICATION_NAME, AuditConstant.APPLICATION_ID), + CREATE_CLIENT_SUCCESS("PMS_PRT_301", AuditConstant.AUDIT_SYSTEM, "POST CREATE OIDC CLIENT", + "Creating the OIDC Client Success", AuditConstant.PARTNER_MODULE_ID, AuditConstant.PARTNER_MODULE_NAME, "NO_ID", + "NO_ID_TYPE", AuditConstant.APPLICATION_NAME, AuditConstant.APPLICATION_ID), + CREATE_CLIENT_FAILURE("PMS_PRT_302", AuditConstant.AUDIT_SYSTEM, "POST CREATE OIDC CLIENT", + "Creating the OIDC Client Failed", AuditConstant.PARTNER_MODULE_ID, AuditConstant.PARTNER_MODULE_NAME, "NO_ID", + "NO_ID_TYPE", AuditConstant.APPLICATION_NAME, AuditConstant.APPLICATION_ID), + UPDATE_CLIENT("PMS_PRT_303", AuditConstant.AUDIT_SYSTEM, "PUT UPDATE OIDC CLIENT", + "Updating OIDC Client", AuditConstant.PARTNER_MODULE_ID, AuditConstant.PARTNER_MODULE_NAME, "NO_ID", + "NO_ID_TYPE", AuditConstant.APPLICATION_NAME, AuditConstant.APPLICATION_ID), + UPDATE_CLIENT_SUCCESS("PMS_PRT_304", AuditConstant.AUDIT_SYSTEM, "PUT UPDATE OIDC CLIENT", + "Updating OIDC Client Success", AuditConstant.PARTNER_MODULE_ID, AuditConstant.PARTNER_MODULE_NAME, "NO_ID", + "NO_ID_TYPE", AuditConstant.APPLICATION_NAME, AuditConstant.APPLICATION_ID), + UPDATE_CLIENT_FAILURE("PMS_PRT_305", AuditConstant.AUDIT_SYSTEM, "PUT UPDATE OIDC CLIENT", + "Updating OIDC Client Failed", AuditConstant.PARTNER_MODULE_ID, AuditConstant.PARTNER_MODULE_NAME, "NO_ID", + "NO_ID_TYPE", AuditConstant.APPLICATION_NAME, AuditConstant.APPLICATION_ID); + + private final String eventId; + + private final String type; + + private String name; + + private String description; + + private String moduleId; + + private String moduleName; + + private String id; + + private String idType; + + private String applicationId; + + private String applicationName; + + public String getEventId() { + return eventId; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getModuleId() { + return moduleId; + } + + public String getModuleName() { + return moduleName; + } + + public String getId() { + return id; + } + + public String getIdType() { + return idType; + } + + public String getApplicationId() { + return applicationId; + } + + public String getApplicationName() { + return applicationName; + } + + ClientServiceAuditEnum(String eventId, String type, String name, String description, String moduleId, + String moduleName, String id, String idType, String applicationId, String applicationName) { + this.eventId = eventId; + this.type = type; + this.name = name; + this.description = description; + this.moduleId = moduleId; + this.moduleName = moduleName; + this.id = id; + this.idType = idType; + this.applicationId = applicationId; + this.applicationName = applicationName; + } + +} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/controller/ClientManagementController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/controller/ClientManagementController.java index 9793d0e2a7..f2ab2c1d01 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/controller/ClientManagementController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/controller/ClientManagementController.java @@ -1,5 +1,9 @@ package io.mosip.pms.oidc.client.controller; +import io.mosip.pms.device.util.AuditUtil; +import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import io.mosip.pms.common.request.dto.RequestWrapper; @@ -22,11 +26,16 @@ public class ClientManagementController { @Autowired ClientManagementService clientManagementService; + @Autowired + AuditUtil auditUtil; + + @RequestMapping(value = "/oidc/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseWrapper createClient( @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { var clientRespDto = clientManagementService.createOIDCClient(requestWrapper.getRequest()); var response = new ResponseWrapper(); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT,requestWrapper.getRequest().getName(),"clientID"); response.setResponse(clientRespDto); return response; } @@ -36,6 +45,7 @@ public ResponseWrapper updateClient(@PathVariable("client_ @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { var clientRespDto = clientManagementService.updateOIDCClient(clientId, requestWrapper.getRequest()); var response = new ResponseWrapper(); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT, clientId, "clientID"); response.setResponse(clientRespDto); return response; } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/service/impl/ClientManagementServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/service/impl/ClientManagementServiceImpl.java index 426514f995..eccf2449d3 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/service/impl/ClientManagementServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/service/impl/ClientManagementServiceImpl.java @@ -8,6 +8,9 @@ import java.util.Map; import java.util.Optional; import java.util.Set; + +import io.mosip.pms.device.util.AuditUtil; +import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.http.MediaType; @@ -96,6 +99,9 @@ public class ClientManagementServiceImpl implements ClientManagementService { @Autowired RestUtil restUtil; + @Autowired + AuditUtil auditUtil; + @Autowired private Environment environment; @@ -112,29 +118,39 @@ public ClientDetailResponse createOIDCClient(ClientDetailCreateRequest createReq Optional result = clientDetailRepository.findById(clientId); if (result.isPresent()) { LOGGER.error("createOIDCClient::Client with name {} already exists", createRequest.getName()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.DUPLICATE_CLIENT.getErrorCode(), ErrorCode.DUPLICATE_CLIENT.getErrorMessage()); } Optional partner = partnerRepository.findById(createRequest.getAuthPartnerId()); if(partner.isEmpty()) { LOGGER.error("createOIDCClient::AuthPartner with Id {} doesn't exists", createRequest.getAuthPartnerId()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.INVALID_PARTNERID.getErrorCode(), String .format(ErrorCode.INVALID_PARTNERID.getErrorMessage(), createRequest.getAuthPartnerId())); } if(!partner.get().getPartnerTypeCode().equalsIgnoreCase(AUTH_PARTNER_TYPE)) { LOGGER.error("createOIDCClient::{} cannot create OIDC Client", partner.get().getPartnerTypeCode()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.INVALID_PARTNER_TYPE.getErrorCode(), String .format(ErrorCode.INVALID_PARTNER_TYPE.getErrorMessage(), partner.get().getPartnerTypeCode())); } Optional policyFromDb = authPolicyRepository.findById(createRequest.getPolicyId()); if (!policyFromDb.isPresent()) { LOGGER.error("createOIDCClient::Policy with Id {} not exists", createRequest.getPolicyId()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.POLICY_NOT_EXIST.getErrorCode(), ErrorCode.POLICY_NOT_EXIST.getErrorMessage()); } AuthPolicy policy = policyFromDb.get(); if(!policy.getPolicy_type().equals(AUTH_POLICY_TYPE)) { LOGGER.error("createOIDCClient::Policy Type Mismatch. {} policy cannot be used to create OIDC Client",policy.getPolicy_type()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.PARTNER_POLICY_TYPE_MISMATCH.getErrorCode(), String .format(ErrorCode.PARTNER_POLICY_TYPE_MISMATCH.getErrorMessage())); } @@ -143,6 +159,8 @@ public ClientDetailResponse createOIDCClient(ClientDetailCreateRequest createReq if (policyMappingReqFromDb.isEmpty()) { LOGGER.error("createOIDCClient::Policy and partner mapping not exists for policy {} and partner {}", createRequest.getPolicyId(), createRequest.getAuthPartnerId()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.PARTNER_POLICY_MAPPING_NOT_EXISTS.getErrorCode(), ErrorCode.PARTNER_POLICY_MAPPING_NOT_EXISTS.getErrorMessage()); } @@ -152,6 +170,8 @@ public ClientDetailResponse createOIDCClient(ClientDetailCreateRequest createReq "createOIDCClient::Policy and partner mapping is not approved for policy {} and partner {} and status {}", createRequest.getPolicyId(), createRequest.getAuthPartnerId(), policyMappingReqFromDb.get(0).getStatusCode().equalsIgnoreCase("approved")); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE, createRequest.getName(), + "clientID"); throw new PartnerServiceException(ErrorCode.PARTNER_POLICY_NOT_APPROVED.getErrorCode(), ErrorCode.PARTNER_POLICY_NOT_APPROVED.getErrorMessage()); } @@ -169,6 +189,7 @@ public ClientDetailResponse createOIDCClient(ClientDetailCreateRequest createReq if (claims.isEmpty()) { LOGGER.error( "createOIDCClient::Partner has no User Claims"); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE); throw new PartnerServiceException(ErrorCode.PARTNER_HAVING_NO_CLAIMS.getErrorCode(), ErrorCode.PARTNER_HAVING_NO_CLAIMS.getErrorMessage()); } @@ -178,6 +199,7 @@ public ClientDetailResponse createOIDCClient(ClientDetailCreateRequest createReq if (acrValues.isEmpty()) { LOGGER.error( "createOIDCClient::Partner has no User Claims"); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_FAILURE); throw new PartnerServiceException(ErrorCode.PARTNER_HAVING_NO_ACRVALUES.getErrorCode(), ErrorCode.PARTNER_HAVING_NO_ACRVALUES.getErrorMessage()); } @@ -192,7 +214,9 @@ public ClientDetailResponse createOIDCClient(ClientDetailCreateRequest createReq clientDetailRepository.save(clientDetail); var response = new ClientDetailResponse(); response.setClientId(clientDetail.getId()); - response.setStatus(clientDetail.getStatus()); + response.setStatus(clientDetail.getStatus()); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT_SUCCESS,createRequest.getName(), + "clientID"); return response; } @@ -367,6 +391,7 @@ public ClientDetailResponse updateOIDCClient(String clientId, ClientDetailUpdate Optional result = clientDetailRepository.findById(clientId); if (!result.isPresent()) { LOGGER.error("updateOIDCClient::Client not exists with id {}", clientId); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT_FAILURE); throw new PartnerServiceException(ErrorCode.CLIENT_NOT_EXISTS.getErrorCode(), ErrorCode.CLIENT_NOT_EXISTS.getErrorMessage()); } @@ -385,8 +410,9 @@ public ClientDetailResponse updateOIDCClient(String clientId, ClientDetailUpdate response.setClientId(clientDetail.getId()); response.setStatus(clientDetail.getStatus()); notify(MapperUtils.mapClientDataToPublishDto(clientDetail), EventType.OIDC_CLIENT_UPDATED); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT_SUCCESS); return response; - } + } /** * diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java index 3879f26df4..f8728c6b8e 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java @@ -1,15 +1,28 @@ package io.mosip.pms.test.device.service.impl; -import static org.junit.Assert.assertTrue; +import static java.util.Collections.singletonList; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.io.IOException; +import java.io.InputStream; +import java.security.cert.Certificate; +import java.security.cert.CertificateFactory; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.*; +import io.mosip.pms.common.constant.EventType; +import io.mosip.pms.common.dto.Type; +import io.mosip.pms.common.helper.WebSubPublisher; +import io.mosip.pms.common.request.dto.ErrorResponse; +import io.mosip.pms.device.response.dto.FtpCertDownloadResponeDto; +import io.mosip.pms.partner.dto.DataShareDto; +import io.mosip.pms.partner.dto.DataShareResponseDto; +import io.mosip.pms.partner.exception.PartnerServiceException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -18,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.env.Environment; import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; @@ -57,7 +71,7 @@ public class FTPChipDetailServiceTest { @InjectMocks private FtpChipDetailService ftpChipDetailService = new FTPChipDetailServiceImpl(); - + @Mock SearchHelper searchHelper; @@ -74,6 +88,15 @@ public class FTPChipDetailServiceTest { @Autowired private ObjectMapper objectMapper; + + @Autowired + private FTPChipDetailServiceImpl fTPChipDetailServiceImpl; + + @MockBean + private WebSubPublisher webSubPublisher; + + @MockBean + private AuditUtil auditUtil; @Autowired @Qualifier("selfTokenRestTemplate") @@ -373,4 +396,602 @@ private FtpChipCertificateRequestDto createUploadrequest(Boolean isItForRegistra FtpChipCertificateRequestDto.setPartnerDomain("doamin"); return FtpChipCertificateRequestDto; } + + @Test (expected = RequestException.class) + public void testGetDataShareurl1() { + when(environment.getProperty((String) any())).thenReturn("Property"); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())) + .thenThrow(new RequestException("An error occurred", "An error occurred")); + ReflectionTestUtils.invokeMethod(ftpChipDetailService,"getDataShareurl","https://pmp.partner.testgetdata.share.url"); + verify(environment).getProperty((String) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + } + + @Test + public void testGetDataShareurl2() { + when(environment.getProperty((String) any())).thenReturn("Property"); + + DataShareDto dataShareDto = new DataShareDto(); + dataShareDto.setPolicyId("policyId"); + dataShareDto.setSignature("certsChain"); + dataShareDto.setSubscriberId("42"); + dataShareDto.setTransactionsAllowed(7); + dataShareDto.setUrl("https://pmp.partner.testgetdata.share.url"); + dataShareDto.setValidForInMinutes(1); + + DataShareResponseDto dataShareResponseDto = new DataShareResponseDto(); + dataShareResponseDto.setDataShare(dataShareDto); + dataShareResponseDto.setErrors(new ArrayList<>()); + dataShareResponseDto.setId("id"); + dataShareResponseDto.setResponsetime("certsChain"); + dataShareResponseDto.setVersion("1.0"); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())).thenReturn(dataShareResponseDto); + assertEquals("https://pmp.partner.testgetdata.share.url", + ReflectionTestUtils.invokeMethod(ftpChipDetailService,"getDataShareurl","https://pmp.partner.testgetdata.share.url")); + verify(environment).getProperty((String) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + } + + @Test (expected = PartnerServiceException.class) + public void testGetDataShareurl3() { + when(environment.getProperty((String) any())).thenReturn("Property"); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())).thenReturn(null); + ReflectionTestUtils.invokeMethod(ftpChipDetailService,"getDataShareurl","https://pmp.partner.testgetdata.share.url"); + verify(environment).getProperty((String) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + } + + @Test (expected = PartnerServiceException.class) + public void testGetDataShareurl4() { + when(environment.getProperty((String) any())).thenReturn(""); + + DataShareDto dataShareDto = new DataShareDto(); + dataShareDto.setPolicyId("policyId"); + dataShareDto.setSignature("Signature"); + dataShareDto.setSubscriberId("id"); + dataShareDto.setTransactionsAllowed(1); + dataShareDto.setUrl("https://pmp.partner.testgetdata.share.url"); + dataShareDto.setValidForInMinutes(1); + + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setErrorCode("An error occurred"); + errorResponse.setMessage("Not all who wander are lost"); + + ArrayList errorResponseList = new ArrayList<>(); + errorResponseList.add(errorResponse); + DataShareResponseDto dataShareResponseDto = mock(DataShareResponseDto.class); + when(dataShareResponseDto.getDataShare()).thenReturn(dataShareDto); + when(dataShareResponseDto.getErrors()).thenReturn(errorResponseList); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())).thenReturn(dataShareResponseDto); + ReflectionTestUtils.invokeMethod(ftpChipDetailService,"getDataShareurl","https://pmp.partner.testgetdata.share.url"); + verify(environment).getProperty((String) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + verify(dataShareResponseDto, atLeast(1)).getErrors(); + } + + @Test (expected = IllegalArgumentException.class) + public void testGetPartnerCertFromChain() throws Exception { + + ReflectionTestUtils.invokeMethod(ftpChipDetailService, "getPartnerCertFromChain", "Cert Chain"); + } + + @Test (expected = PartnerServiceException.class) + public void testGetPartnerCertFromChain2() throws Exception { + + ReflectionTestUtils.invokeMethod(ftpChipDetailService, "getPartnerCertFromChain", "PartnerServiceImpl"); + } + + @Test (expected = NullPointerException.class) + public void testGetPartnerCertFromChain3() throws Exception { + + ReflectionTestUtils.invokeMethod(ftpChipDetailService, "getPartnerCertFromChain", ""); + } + + @Test (expected = RequestException.class) + public void testUploadCertificate() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + + FTPChipDetail ftpChipDetail = new FTPChipDetail(); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(true); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(ftpChipDetail); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(ofResult); + + Partner partner = new Partner(); + partner.setAdditionalInfo("Additional Info"); + partner.setAddress("abc"); + partner.setApprovalStatus("Approval Status"); + partner.setCertificateAlias("Certificate Alias"); + partner.setContactNo("Contact No"); + partner.setCrBy("Cr By"); + partner.setCrDtimes(mock(Timestamp.class)); + partner.setDelDtimes(mock(Timestamp.class)); + partner.setEmailId("emailId"); + partner.setId("Id"); + partner.setIsActive(true); + partner.setIsDeleted(false); + partner.setLangCode("eng"); + partner.setLogoUrl("https://pms.net/partner"); + partner.setName("Name"); + partner.setPartnerPolicies(new ArrayList<>()); + partner.setPartnerPolicyRequests(new ArrayList<>()); + partner.setPartnerTypeCode("Partner Type Code"); + partner.setPolicyGroupId("PolicyGroupId"); + partner.setUpdBy("Upd By"); + partner.setUpdDtimes(mock(Timestamp.class)); + partner.setUserId("UserId"); + when(partnerServiceRepository.findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any())) + .thenReturn(partner); + ftpChipDetailService.uploadCertificate(new FtpChipCertificateRequestDto()); + verify(auditUtil).auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), + (String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(partnerServiceRepository).findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any()); + } + + @Test (expected = RequestException.class) + public void testUploadCertificate2() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(ftpChipDetailRepository.findById((String) any())) + .thenThrow(new RequestException("An error occurred", "An error occurred")); + + Partner partner = new Partner(); + partner.setAdditionalInfo("Additional Info"); + partner.setAddress("abc"); + partner.setApprovalStatus("Approval Status"); + partner.setCertificateAlias("Certificate Alias"); + partner.setContactNo("Contact No"); + partner.setCrBy("Cr By"); + partner.setCrDtimes(mock(Timestamp.class)); + partner.setDelDtimes(mock(Timestamp.class)); + partner.setEmailId("emailId"); + partner.setId("Id"); + partner.setIsActive(true); + partner.setIsDeleted(false); + partner.setLangCode("eng"); + partner.setLogoUrl("https://pms.net/partner"); + partner.setName("Name"); + partner.setPartnerPolicies(new ArrayList<>()); + partner.setPartnerPolicyRequests(new ArrayList<>()); + partner.setPartnerTypeCode("Partner Type Code"); + partner.setPolicyGroupId("PolicyGroupId"); + partner.setUpdBy("Upd By"); + partner.setUpdDtimes(mock(Timestamp.class)); + partner.setUserId("UserId"); + when(partnerServiceRepository.findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any())) + .thenReturn(partner); + ftpChipDetailService.uploadCertificate(new FtpChipCertificateRequestDto()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(partnerServiceRepository).findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any()); + } + + @Test (expected = RequestException.class) + public void testUploadCertificate3() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(Optional.empty()); + FTPChipDetail ftpChipDetail = mock(FTPChipDetail.class); + when(ftpChipDetail.getFtpProviderId()).thenReturn("Id"); + doNothing().when(ftpChipDetail).setActive(anyBoolean()); + doNothing().when(ftpChipDetail).setApprovalStatus((String) any()); + doNothing().when(ftpChipDetail).setCertificateAlias((String) any()); + doNothing().when(ftpChipDetail).setCrBy((String) any()); + doNothing().when(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDeleted(anyBoolean()); + doNothing().when(ftpChipDetail).setFtpChipDetailId((String) any()); + doNothing().when(ftpChipDetail).setFtpProviderId((String) any()); + doNothing().when(ftpChipDetail).setMake((String) any()); + doNothing().when(ftpChipDetail).setModel((String) any()); + doNothing().when(ftpChipDetail).setPartnerOrganizationName((String) any()); + doNothing().when(ftpChipDetail).setUpdBy((String) any()); + doNothing().when(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(false); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + + Partner partner = new Partner(); + partner.setAdditionalInfo("Additional Info"); + partner.setAddress("abc"); + partner.setApprovalStatus("Approval Status"); + partner.setCertificateAlias("Certificate Alias"); + partner.setContactNo("9087654321"); + partner.setCrBy("Cr By"); + partner.setCrDtimes(mock(Timestamp.class)); + partner.setDelDtimes(mock(Timestamp.class)); + partner.setEmailId("emailId"); + partner.setId("Id"); + partner.setIsActive(true); + partner.setIsDeleted(false); + partner.setLangCode("eng"); + partner.setLogoUrl("https://pms.net/partner"); + partner.setName("Name"); + partner.setPartnerPolicies(new ArrayList<>()); + partner.setPartnerPolicyRequests(new ArrayList<>()); + partner.setPartnerTypeCode("Partner Type Code"); + partner.setPolicyGroupId("PolicyGroupId"); + partner.setUpdBy("Upd By"); + partner.setUpdDtimes(mock(Timestamp.class)); + partner.setUserId("UserId"); + when(partnerServiceRepository.findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any())) + .thenReturn(partner); + ftpChipDetailService.uploadCertificate(new FtpChipCertificateRequestDto()); + verify(auditUtil).auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), + (String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(ftpChipDetail).setActive(anyBoolean()); + verify(ftpChipDetail).setApprovalStatus((String) any()); + verify(ftpChipDetail).setCertificateAlias((String) any()); + verify(ftpChipDetail).setCrBy((String) any()); + verify(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDeleted(anyBoolean()); + verify(ftpChipDetail).setFtpChipDetailId((String) any()); + verify(ftpChipDetail).setFtpProviderId((String) any()); + verify(ftpChipDetail).setMake((String) any()); + verify(ftpChipDetail).setModel((String) any()); + verify(ftpChipDetail).setPartnerOrganizationName((String) any()); + verify(ftpChipDetail).setUpdBy((String) any()); + verify(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + verify(partnerServiceRepository).findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any()); + } + + @Test (expected = RequestException.class) + public void testUploadCertificate4() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(environment.getProperty((String) any())).thenReturn("Property"); + FTPChipDetail ftpChipDetail = mock(FTPChipDetail.class); + when(ftpChipDetail.getFtpChipDetailId()).thenReturn("ChipId"); + when(ftpChipDetail.getFtpProviderId()).thenReturn("ProviderId"); + doNothing().when(ftpChipDetail).setActive(anyBoolean()); + doNothing().when(ftpChipDetail).setApprovalStatus((String) any()); + doNothing().when(ftpChipDetail).setCertificateAlias((String) any()); + doNothing().when(ftpChipDetail).setCrBy((String) any()); + doNothing().when(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDeleted(anyBoolean()); + doNothing().when(ftpChipDetail).setFtpChipDetailId((String) any()); + doNothing().when(ftpChipDetail).setFtpProviderId((String) any()); + doNothing().when(ftpChipDetail).setMake((String) any()); + doNothing().when(ftpChipDetail).setModel((String) any()); + doNothing().when(ftpChipDetail).setPartnerOrganizationName((String) any()); + doNothing().when(ftpChipDetail).setUpdBy((String) any()); + doNothing().when(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(false); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(ftpChipDetail); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(ofResult); + + Partner partner = new Partner(); + partner.setAdditionalInfo("Additional Info"); + partner.setAddress("abc"); + partner.setApprovalStatus("Approval Status"); + partner.setCertificateAlias("Certificate Alias"); + partner.setContactNo("9087654321"); + partner.setCrBy("Cr By"); + partner.setCrDtimes(mock(Timestamp.class)); + partner.setDelDtimes(mock(Timestamp.class)); + partner.setEmailId("emailId"); + partner.setId("Id"); + partner.setIsActive(true); + partner.setIsDeleted(false); + partner.setLangCode("eng"); + partner.setLogoUrl("https://pms.net/partner"); + partner.setName("Name"); + partner.setPartnerPolicies(new ArrayList<>()); + partner.setPartnerPolicyRequests(new ArrayList<>()); + partner.setPartnerTypeCode("Partner Type Code"); + partner.setPolicyGroupId("PolicyGroupId"); + partner.setUpdBy("Upd By"); + partner.setUpdDtimes(mock(Timestamp.class)); + partner.setUserId("UserId"); + when(partnerServiceRepository.findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any())) + .thenReturn(partner); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())) + .thenThrow(new RequestException("An error occurred", "An error occurred")); + ftpChipDetailService.uploadCertificate(new FtpChipCertificateRequestDto("ProviderId", "ChipId", true, "Certificate Data", + "Organization Name", "Partner Domain")); + verify(environment).getProperty((String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(ftpChipDetail).getFtpChipDetailId(); + verify(ftpChipDetail).getFtpProviderId(); + verify(ftpChipDetail).setActive(anyBoolean()); + verify(ftpChipDetail).setApprovalStatus((String) any()); + verify(ftpChipDetail).setCertificateAlias((String) any()); + verify(ftpChipDetail).setCrBy((String) any()); + verify(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDeleted(anyBoolean()); + verify(ftpChipDetail).setFtpChipDetailId((String) any()); + verify(ftpChipDetail).setFtpProviderId((String) any()); + verify(ftpChipDetail).setMake((String) any()); + verify(ftpChipDetail).setModel((String) any()); + verify(ftpChipDetail).setPartnerOrganizationName((String) any()); + verify(ftpChipDetail).setUpdBy((String) any()); + verify(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + verify(partnerServiceRepository).findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue((String) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + } + + @Test (expected = RequestException.class) + public void testGetCertificate() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(environment.getProperty((String) any())).thenReturn("Property"); + + FTPChipDetail ftpChipDetail = new FTPChipDetail(); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(false); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(ftpChipDetail); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(ofResult); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())) + .thenThrow(new RequestException("An error occurred", "An error occurred")); + ftpChipDetailService.getCertificate(new FtpChipCertDownloadRequestDto("ChipId")); + verify(environment).getProperty((String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(restUtil).getApi((String) any(), (Map) any(), (Class) any()); + } + + @Test (expected = RequestException.class) + public void testGetCertificate2() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(environment.getProperty((String) any())).thenReturn("Property"); + FTPChipDetail ftpChipDetail = mock(FTPChipDetail.class); + when(ftpChipDetail.getCertificateAlias()).thenReturn(null); + doNothing().when(ftpChipDetail).setActive(anyBoolean()); + doNothing().when(ftpChipDetail).setApprovalStatus((String) any()); + doNothing().when(ftpChipDetail).setCertificateAlias((String) any()); + doNothing().when(ftpChipDetail).setCrBy((String) any()); + doNothing().when(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDeleted(anyBoolean()); + doNothing().when(ftpChipDetail).setFtpChipDetailId((String) any()); + doNothing().when(ftpChipDetail).setFtpProviderId((String) any()); + doNothing().when(ftpChipDetail).setMake((String) any()); + doNothing().when(ftpChipDetail).setModel((String) any()); + doNothing().when(ftpChipDetail).setPartnerOrganizationName((String) any()); + doNothing().when(ftpChipDetail).setUpdBy((String) any()); + doNothing().when(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(false); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(ftpChipDetail); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(ofResult); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())).thenReturn("Api"); + ftpChipDetailService.getCertificate(new FtpChipCertDownloadRequestDto("ChipId")); + verify(auditUtil).auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), + (String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(ftpChipDetail).getCertificateAlias(); + verify(ftpChipDetail).setActive(anyBoolean()); + verify(ftpChipDetail).setApprovalStatus((String) any()); + verify(ftpChipDetail).setCertificateAlias((String) any()); + verify(ftpChipDetail).setCrBy((String) any()); + verify(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDeleted(anyBoolean()); + verify(ftpChipDetail).setFtpChipDetailId((String) any()); + verify(ftpChipDetail).setFtpProviderId((String) any()); + verify(ftpChipDetail).setMake((String) any()); + verify(ftpChipDetail).setModel((String) any()); + verify(ftpChipDetail).setPartnerOrganizationName((String) any()); + verify(ftpChipDetail).setUpdBy((String) any()); + verify(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + } + + @Test (expected = RequestException.class) + public void testGetCertificate4() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(environment.getProperty((String) any())).thenReturn("Property"); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(Optional.empty()); + FTPChipDetail ftpChipDetail = mock(FTPChipDetail.class); + when(ftpChipDetail.getCertificateAlias()).thenReturn("Certificate Alias"); + doNothing().when(ftpChipDetail).setActive(anyBoolean()); + doNothing().when(ftpChipDetail).setApprovalStatus((String) any()); + doNothing().when(ftpChipDetail).setCertificateAlias((String) any()); + doNothing().when(ftpChipDetail).setCrBy((String) any()); + doNothing().when(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDeleted(anyBoolean()); + doNothing().when(ftpChipDetail).setFtpChipDetailId((String) any()); + doNothing().when(ftpChipDetail).setFtpProviderId((String) any()); + doNothing().when(ftpChipDetail).setMake((String) any()); + doNothing().when(ftpChipDetail).setModel((String) any()); + doNothing().when(ftpChipDetail).setPartnerOrganizationName((String) any()); + doNothing().when(ftpChipDetail).setUpdBy((String) any()); + doNothing().when(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(false); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())).thenReturn("Api"); + ftpChipDetailService.getCertificate(new FtpChipCertDownloadRequestDto("ChipId")); + verify(auditUtil).auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), + (String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(ftpChipDetail).setActive(anyBoolean()); + verify(ftpChipDetail).setApprovalStatus((String) any()); + verify(ftpChipDetail).setCertificateAlias((String) any()); + verify(ftpChipDetail).setCrBy((String) any()); + verify(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDeleted(anyBoolean()); + verify(ftpChipDetail).setFtpChipDetailId((String) any()); + verify(ftpChipDetail).setFtpProviderId((String) any()); + verify(ftpChipDetail).setMake((String) any()); + verify(ftpChipDetail).setModel((String) any()); + verify(ftpChipDetail).setPartnerOrganizationName((String) any()); + verify(ftpChipDetail).setUpdBy((String) any()); + verify(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + } + + + @Test (expected = IllegalArgumentException.class) + @Ignore + public void testGetCertificate5() throws IOException { + doNothing().when(auditUtil) + .auditRequest((String) any(), (String) any(), (String) any(), (String) any(), (String) any(), (String) any()); + when(environment.getProperty((String) any())).thenReturn("Property"); + FTPChipDetail ftpChipDetail = mock(FTPChipDetail.class); + when(ftpChipDetail.getCertificateAlias()).thenReturn("Certificate Alias"); + doNothing().when(ftpChipDetail).setActive(anyBoolean()); + doNothing().when(ftpChipDetail).setApprovalStatus((String) any()); + doNothing().when(ftpChipDetail).setCertificateAlias((String) any()); + doNothing().when(ftpChipDetail).setCrBy((String) any()); + doNothing().when(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + doNothing().when(ftpChipDetail).setDeleted(anyBoolean()); + doNothing().when(ftpChipDetail).setFtpChipDetailId((String) any()); + doNothing().when(ftpChipDetail).setFtpProviderId((String) any()); + doNothing().when(ftpChipDetail).setMake((String) any()); + doNothing().when(ftpChipDetail).setModel((String) any()); + doNothing().when(ftpChipDetail).setPartnerOrganizationName((String) any()); + doNothing().when(ftpChipDetail).setUpdBy((String) any()); + doNothing().when(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + ftpChipDetail.setActive(true); + ftpChipDetail.setApprovalStatus("Approval Status"); + ftpChipDetail.setCertificateAlias("Certificate Alias"); + ftpChipDetail.setCrBy("Cr By"); + ftpChipDetail.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + ftpChipDetail.setDeleted(false); + ftpChipDetail.setFtpChipDetailId("ChipId"); + ftpChipDetail.setFtpProviderId("ProviderId"); + ftpChipDetail.setMake("Make"); + ftpChipDetail.setModel("Model"); + ftpChipDetail.setPartnerOrganizationName("Partner Organization Name"); + ftpChipDetail.setUpdBy("Upd By"); + ftpChipDetail.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(ftpChipDetail); + when(ftpChipDetailRepository.findById((String) any())).thenReturn(ofResult); + + FtpCertDownloadResponeDto ftpCertDownloadResponeDto = new FtpCertDownloadResponeDto(); + ftpCertDownloadResponeDto.setCertificateData("Certificate Data"); + ftpCertDownloadResponeDto.setTimestamp(LocalDateTime.of(1, 1, 1, 1, 1)); + when(objectMapper.readValue((String) any(), (Class) any())) + .thenReturn(ftpCertDownloadResponeDto); + when(objectMapper.writeValueAsString((Object) any())).thenReturn("42"); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())) + .thenReturn(new HashMap<>()); + assertSame(ftpCertDownloadResponeDto, + ftpChipDetailService.getCertificate(new FtpChipCertDownloadRequestDto("ChipId"))); + verify(environment).getProperty((String) any()); + verify(ftpChipDetailRepository).findById((String) any()); + verify(ftpChipDetail, atLeast(1)).getCertificateAlias(); + verify(ftpChipDetail).setActive(anyBoolean()); + verify(ftpChipDetail).setApprovalStatus((String) any()); + verify(ftpChipDetail).setCertificateAlias((String) any()); + verify(ftpChipDetail).setCrBy((String) any()); + verify(ftpChipDetail).setCrDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDelDtimes((LocalDateTime) any()); + verify(ftpChipDetail).setDeleted(anyBoolean()); + verify(ftpChipDetail).setFtpChipDetailId((String) any()); + verify(ftpChipDetail).setFtpProviderId((String) any()); + verify(ftpChipDetail).setMake((String) any()); + verify(ftpChipDetail).setModel((String) any()); + verify(ftpChipDetail).setPartnerOrganizationName((String) any()); + verify(ftpChipDetail).setUpdBy((String) any()); + verify(ftpChipDetail).setUpdDtimes((LocalDateTime) any()); + verify(objectMapper).readValue((String) any(), (Class) any()); + verify(objectMapper).writeValueAsString((Object) any()); + verify(restUtil).getApi((String) any(), (Map) any(), (Class) any()); + } + + @Test (expected = Exception.class) + public void testNotify() { + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + ReflectionTestUtils.invokeMethod(fTPChipDetailServiceImpl,"notify","Cert Data", "Partner Domain"); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test (expected = Exception.class) + public void testNotify2() { + doThrow(new RequestException("An error occurred", "An error occurred")).when(webSubPublisher) + .notify((EventType) any(), (Map) any(), (Type) any()); + ReflectionTestUtils.invokeMethod(fTPChipDetailServiceImpl,"notify","Cert Data", "Partner Domain"); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/oidc/service/impl/ClientManagementServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/oidc/service/impl/ClientManagementServiceImplTest.java index 3ab6833843..b596687461 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/oidc/service/impl/ClientManagementServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/oidc/service/impl/ClientManagementServiceImplTest.java @@ -1,11 +1,33 @@ package io.mosip.pms.test.oidc.service.impl; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.UndeclaredThrowableException; +import java.sql.Ref; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import io.mosip.pms.common.constant.EventType; +import io.mosip.pms.common.dto.ClientPublishDto; +import io.mosip.pms.common.dto.PartnerDataPublishDto; +import io.mosip.pms.common.dto.PolicyPublishDto; +import io.mosip.pms.common.dto.Type; +import io.mosip.pms.common.entity.AuthPolicy; +import io.mosip.pms.common.entity.ClientDetail; +import io.mosip.pms.common.entity.Partner; +import io.mosip.pms.common.entity.PolicyGroup; +import io.mosip.pms.common.exception.ApiAccessibleException; +import io.mosip.pms.common.repository.PartnerRepository; +import io.mosip.pms.common.util.MapperUtils; +import io.mosip.pms.device.util.AuditUtil; +import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum; +import io.mosip.pms.oidc.client.dto.*; +import io.mosip.pms.partner.response.dto.PartnerCertDownloadResponeDto; +import org.json.simple.JSONObject; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -13,9 +35,14 @@ import org.springframework.beans.factory.annotation.Autowired; 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.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertTrue; + +import static io.mosip.pms.common.util.UserDetailUtil.getLoggedInUserId; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; import com.fasterxml.jackson.databind.ObjectMapper; @@ -24,10 +51,10 @@ import io.mosip.pms.common.repository.ClientDetailRepository; import io.mosip.pms.common.repository.PartnerPolicyRequestRepository; import io.mosip.pms.common.util.RestUtil; -import io.mosip.pms.oidc.client.dto.ClientDetailCreateRequest; import io.mosip.pms.oidc.client.service.impl.ClientManagementServiceImpl; import io.mosip.pms.partner.constant.ErrorCode; import io.mosip.pms.partner.exception.PartnerServiceException; +import org.springframework.web.multipart.MultipartFile; @RunWith(SpringRunner.class) @SpringBootTest @@ -36,6 +63,12 @@ public class ClientManagementServiceImplTest { @Autowired private ClientManagementServiceImpl serviceImpl; + @Mock + private Environment environment; + + @Mock + PartnerRepository partnerRepository; + @Mock ClientDetailRepository clientDetailRepository; @@ -45,6 +78,9 @@ public class ClientManagementServiceImplTest { @Mock PartnerPolicyRequestRepository partnerPolicyRequestRepository; + @MockBean + private AuditUtil auditUtil; + @MockBean private RestUtil restUtil; @@ -94,4 +130,879 @@ public void createClientTest() throws Exception { } } + @Test (expected = Exception.class) + public void testCreateOIDCClient02() throws Exception { + ClientDetailCreateRequest clientDetailCreateRequest = new ClientDetailCreateRequest(); + clientDetailCreateRequest.setPublicKey(new HashMap<>()); + serviceImpl.createOIDCClient(clientDetailCreateRequest); + } + + @Test (expected = Exception.class) + public void testCreateOIDCClient03() throws Exception { + ClientDetailCreateRequest clientDetailCreateRequest = mock(ClientDetailCreateRequest.class); + when(clientDetailCreateRequest.getPublicKey()).thenReturn(new HashMap<>()); + serviceImpl.createOIDCClient(clientDetailCreateRequest); + verify(clientDetailCreateRequest).getPublicKey(); + } + + @Test (expected = PartnerServiceException.class) + public void testCreateOIDCClient04() throws Exception { + ClientDetailCreateRequest createRequest = new ClientDetailCreateRequest(); + createRequest.setName("ClientName"); + createRequest.setAuthPartnerId("AuthPartnerId"); + createRequest.setPolicyId("PolicyID"); + List clientAuthMethods = new ArrayList(); + clientAuthMethods.add("private_key_jwt"); + createRequest.setClientAuthMethods(clientAuthMethods); + List setGrantTypes = new ArrayList(); + setGrantTypes.add("authorization_code"); + createRequest.setGrantTypes(setGrantTypes); + createRequest.setLogoUri("https://testcase.pms.net/browse/OIDCClient.png"); + List setRedirectUris = new ArrayList(); + setRedirectUris.add("https://testcase.pms.net/browse/OIDCClient"); + createRequest.setRedirectUris(setRedirectUris); + createRequest.setPublicKey(public_key); + + serviceImpl.createOIDCClient(createRequest); + } + + @Test (expected = PartnerServiceException.class) + public void testCreateOIDCClient05() throws Exception { + ClientDetailCreateRequest createRequest = new ClientDetailCreateRequest(); + createRequest.setName("ClientName"); + createRequest.setAuthPartnerId("AuthPartnerId"); + createRequest.setPolicyId("PolicyID"); + List clientAuthMethods = new ArrayList(); + clientAuthMethods.add("private_key_jwt"); + createRequest.setClientAuthMethods(clientAuthMethods); + List setGrantTypes = new ArrayList(); + setGrantTypes.add("authorization_code"); + createRequest.setGrantTypes(setGrantTypes); + createRequest.setLogoUri("https://testcase.pms.net/browse/OIDCClient.png"); + List setRedirectUris = new ArrayList(); + setRedirectUris.add("https://testcase.pms.net/browse/OIDCClient"); + createRequest.setRedirectUris(setRedirectUris); + createRequest.setPublicKey(public_key); + + ClientDetail clientDetail = new ClientDetail(); + clientDetail.setPublicKey("public_key"); + clientDetail.setId("clientId"); + clientDetail.setName(createRequest.getName()); + clientDetail.setRpId(createRequest.getAuthPartnerId()); + clientDetail.setPolicyId(createRequest.getPolicyId()); + clientDetail.setLogoUri(createRequest.getLogoUri()); + clientDetail.setRedirectUris(String.join(",", createRequest.getRedirectUris())); + clientDetail.setClaims("claims"); + clientDetail.setAcrValues( "acrValues"); + clientDetail.setStatus("ACTIVE"); + clientDetail.setGrantTypes(String.join(",", createRequest.getGrantTypes())); + clientDetail.setClientAuthMethods(String.join(",", createRequest.getClientAuthMethods())); + clientDetail.setCreatedDateTime(LocalDateTime.now(ZoneId.of("UTC"))); + clientDetail.setCreatedBy(getLoggedInUserId()); + + serviceImpl.createOIDCClient(createRequest); + assertEquals(createRequest,clientDetail); + } + + + @Test (expected = PartnerServiceException.class) + public void testCreateOIDCClient06() throws Exception { + + ClientDetailCreateRequest createRequest = new ClientDetailCreateRequest(); + createRequest.setName("ClientName"); + createRequest.setAuthPartnerId("AuthPartnerId"); + createRequest.setPolicyId("PolicyID"); + List clientAuthMethods = new ArrayList(); + clientAuthMethods.add("private_key_jwt"); + createRequest.setClientAuthMethods(clientAuthMethods); + List setGrantTypes = new ArrayList(); + setGrantTypes.add("authorization_code"); + createRequest.setGrantTypes(setGrantTypes); + createRequest.setLogoUri("https://testcase.pms.net/browse/OIDCClient.png"); + List setRedirectUris = new ArrayList(); + setRedirectUris.add("https://testcase.pms.net/browse/OIDCClient"); + createRequest.setRedirectUris(setRedirectUris); + createRequest.setPublicKey(public_key); + + when(environment.getProperty(any(String.class))).thenReturn("https://testcase.pms.net/browse/OIDCClient.png"); + when(clientDetailRepository.findById(any(String.class))).thenReturn(Optional.empty()); + when(partnerRepository.findById(any(String.class))).thenReturn(Optional.of(new Partner())); + + ClientDetailResponse response = serviceImpl.createOIDCClient(createRequest); + + assertNotNull(response); + } + + @Test (expected = PartnerServiceException.class) + public void testCreateOIDCClient07() throws Exception { + + when(environment.getProperty("auth.url")).thenReturn("https://pms.net/partner"); + when(clientDetailRepository.findById(anyString())).thenReturn(Optional.empty()); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(new Partner())); + + ClientDetailCreateRequest createRequest = new ClientDetailCreateRequest(); + createRequest.setName("ClientName"); + createRequest.setAuthPartnerId("AuthPartnerId"); + createRequest.setPolicyId("PolicyID"); + List clientAuthMethods = new ArrayList(); + clientAuthMethods.add("private_key_jwt"); + createRequest.setClientAuthMethods(clientAuthMethods); + List setGrantTypes = new ArrayList(); + setGrantTypes.add("authorization_code"); + createRequest.setGrantTypes(setGrantTypes); + createRequest.setLogoUri("https://testcase.pms.net/browse/OIDCClient.png"); + List setRedirectUris = new ArrayList(); + setRedirectUris.add("https://testcase.pms.net/browse/OIDCClient"); + createRequest.setRedirectUris(setRedirectUris); + createRequest.setPublicKey(public_key); + + ClientDetailResponse response = serviceImpl.createOIDCClient(createRequest); + + assertNotNull(response); + } + + @Test(expected = PartnerServiceException.class) + public void testCreateOIDCClient08() throws Exception { + + when(clientDetailRepository.findById(anyString())).thenReturn(Optional.of(new ClientDetail())); + + ClientDetailCreateRequest createRequest = new ClientDetailCreateRequest(); + createRequest.setName("ClientName"); + createRequest.setAuthPartnerId("AuthPartnerId"); + createRequest.setPolicyId("PolicyID"); + List clientAuthMethods = new ArrayList(); + clientAuthMethods.add("private_key_jwt"); + createRequest.setClientAuthMethods(clientAuthMethods); + List setGrantTypes = new ArrayList(); + setGrantTypes.add("authorization_code"); + createRequest.setGrantTypes(setGrantTypes); + createRequest.setLogoUri("https://testcase.pms.net/browse/OIDCClient.png"); + List setRedirectUris = new ArrayList(); + setRedirectUris.add("https://testcase.pms.net/browse/OIDCClient"); + createRequest.setRedirectUris(setRedirectUris); + createRequest.setPublicKey(public_key); + + serviceImpl.createOIDCClient(createRequest); + } + + @Test + public void testUpdateOIDCClient() throws Exception { + doNothing().when(auditUtil).setAuditRequestDto((ClientServiceAuditEnum) any()); + + ClientDetail clientDetail = new ClientDetail(); + clientDetail.setAcrValues("value"); + clientDetail.setClaims("Claims"); + clientDetail.setClientAuthMethods("Client Auth Methods"); + clientDetail.setCreatedBy("Cr By"); + clientDetail.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail.setGrantTypes("Grant Types"); + clientDetail.setId("Id"); + clientDetail.setIsDeleted(false); + clientDetail.setLogoUri("Logo Uri"); + clientDetail.setName("Name"); + clientDetail.setPolicyId("PolicyId"); + clientDetail.setPublicKey("Public Key"); + clientDetail.setRedirectUris("Redirect Uris"); + clientDetail.setRpId("RpId"); + clientDetail.setStatus("Status"); + clientDetail.setUpdatedBy("UpdatedBy"); + clientDetail.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(clientDetail); + + ClientDetail clientDetail1 = new ClientDetail(); + clientDetail1.setAcrValues("value"); + clientDetail1.setClaims("Claims"); + clientDetail1.setClientAuthMethods("Client Auth Methods"); + clientDetail1.setCreatedBy("Cr By"); + clientDetail1.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail1.setGrantTypes("Grant Types"); + clientDetail1.setId("Id"); + clientDetail1.setIsDeleted(false); + clientDetail1.setLogoUri("Logo Uri"); + clientDetail1.setName("Name"); + clientDetail1.setPolicyId("PolicyId"); + clientDetail1.setPublicKey("Public Key"); + clientDetail1.setRedirectUris("Redirect Uris"); + clientDetail1.setRpId("RpId"); + clientDetail1.setStatus("Status"); + clientDetail1.setUpdatedBy("UpdatedBy"); + clientDetail1.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + when(environment.getProperty(any(String.class))).thenReturn("Property"); + when(clientDetailRepository.save((ClientDetail) any())).thenReturn(clientDetail1); + when(clientDetailRepository.findById((String) any())).thenReturn(ofResult); + doNothing().when(restUtil) + .putApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), (Object) any(), + (Class) any()); + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + + ClientDetailUpdateRequest clientDetailUpdateRequest = new ClientDetailUpdateRequest(); + clientDetailUpdateRequest.setClientAuthMethods(new ArrayList<>()); + clientDetailUpdateRequest.setClientName("ClientName"); + clientDetailUpdateRequest.setGrantTypes(new ArrayList<>()); + clientDetailUpdateRequest.setLogoUri("Logo Uri"); + clientDetailUpdateRequest.setRedirectUris(new ArrayList<>()); + clientDetailUpdateRequest.setStatus("Status"); + ClientDetailResponse actualUpdateOIDCClientResult = serviceImpl.updateOIDCClient("Id", + clientDetailUpdateRequest); + assertEquals("Id", actualUpdateOIDCClientResult.getClientId()); + assertEquals("Status", actualUpdateOIDCClientResult.getStatus()); + verify(auditUtil).setAuditRequestDto((ClientServiceAuditEnum) any()); + verify(clientDetailRepository).save((ClientDetail) any()); + verify(clientDetailRepository).findById((String) any()); + verify(restUtil).putApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test (expected = PartnerServiceException.class) + public void testUpdateOIDCClient2() throws Exception { + doNothing().when(auditUtil).setAuditRequestDto((ClientServiceAuditEnum) any()); + + ClientDetail clientDetail = new ClientDetail(); + clientDetail.setAcrValues("value"); + clientDetail.setClaims("Claims"); + clientDetail.setClientAuthMethods("Client Auth Methods"); + clientDetail.setCreatedBy("Cr By"); + clientDetail.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail.setGrantTypes("Grant Types"); + clientDetail.setId("Id"); + clientDetail.setIsDeleted(false); + clientDetail.setLogoUri("Logo Uri"); + clientDetail.setName("Name"); + clientDetail.setPolicyId("PolicyId"); + clientDetail.setPublicKey("Public Key"); + clientDetail.setRedirectUris("Redirect Uris"); + clientDetail.setRpId("RpId"); + clientDetail.setStatus("Status"); + clientDetail.setUpdatedBy("UpdatedBy"); + clientDetail.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(clientDetail); + + ClientDetail clientDetail1 = new ClientDetail(); + clientDetail1.setAcrValues("value"); + clientDetail1.setClaims("Claims"); + clientDetail1.setClientAuthMethods("Client Auth Methods"); + clientDetail1.setCreatedBy("Cr By"); + clientDetail1.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail1.setGrantTypes("Grant Types"); + clientDetail1.setId("Id"); + clientDetail1.setIsDeleted(false); + clientDetail1.setLogoUri("Logo Uri"); + clientDetail1.setName("Name"); + clientDetail1.setPolicyId("PolicyId"); + clientDetail1.setPublicKey("Public Key"); + clientDetail1.setRedirectUris("Redirect Uris"); + clientDetail1.setRpId("RpId"); + clientDetail1.setStatus("Status"); + clientDetail1.setUpdatedBy("UpdatedBy"); + clientDetail1.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + when(clientDetailRepository.save((ClientDetail) any())).thenReturn(clientDetail1); + when(clientDetailRepository.findById((String) any())).thenReturn(ofResult); + when(environment.getProperty((String) any())).thenReturn("Property"); + doNothing().when(restUtil) + .putApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + doThrow(new PartnerServiceException("An error occurred", "An error occurred")).when(webSubPublisher) + .notify((EventType) any(), (Map) any(), (Type) any()); + + ClientDetailUpdateRequest clientDetailUpdateRequest = new ClientDetailUpdateRequest(); + clientDetailUpdateRequest.setClientAuthMethods(new ArrayList<>()); + clientDetailUpdateRequest.setClientName("ClientName"); + clientDetailUpdateRequest.setGrantTypes(new ArrayList<>()); + clientDetailUpdateRequest.setLogoUri("Logo Uri"); + clientDetailUpdateRequest.setRedirectUris(new ArrayList<>()); + clientDetailUpdateRequest.setStatus("Status"); + serviceImpl.updateOIDCClient("Id", clientDetailUpdateRequest); + verify(clientDetailRepository).save((ClientDetail) any()); + verify(clientDetailRepository).findById((String) any()); + verify(environment).getProperty((String) any()); + verify(restUtil).putApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test + public void testGetClientDetails() { + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setCrBy("Cr By"); + policyGroup.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setDesc("The characteristics of someone or something"); + policyGroup.setId("Id"); + policyGroup.setIsActive(true); + policyGroup.setIsDeleted(false); + policyGroup.setName("Name"); + policyGroup.setUpdBy("Upd By"); + policyGroup.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setUserId("UserId"); + + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.SetVersion("1.0"); + authPolicy.setCrBy("Cr By"); + authPolicy.setCrDtimes(mock(Timestamp.class)); + authPolicy.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setDescr("Descr"); + authPolicy.setId("Id"); + authPolicy.setIsActive(true); + authPolicy.setIsDeleted(false); + authPolicy.setName("Name"); + authPolicy.setPolicyFileId("Field"); + authPolicy.setPolicyGroup(policyGroup); + authPolicy.setPolicySchema("Schema"); + authPolicy.setPolicy_type("Policy Type"); + authPolicy.setUpdBy("Upd By"); + authPolicy.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setValidFromDate(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setValidToDate(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(authPolicy); + when(authPolicyRepository.findById((String) any())).thenReturn(ofResult); + + io.mosip.pms.common.entity.ClientDetail clientDetail = new io.mosip.pms.common.entity.ClientDetail(); + clientDetail.setAcrValues("values"); + clientDetail.setClaims("Claims"); + clientDetail.setClientAuthMethods("Client Auth Methods"); + clientDetail.setCreatedBy("Cr By"); + clientDetail.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail.setGrantTypes("Grant Types"); + clientDetail.setId("Id"); + clientDetail.setIsDeleted(false); + clientDetail.setLogoUri("Logo Uri"); + clientDetail.setName("Name"); + clientDetail.setPolicyId("PolicyId"); + clientDetail.setPublicKey("Public Key"); + clientDetail.setRedirectUris("Redirect Uris"); + clientDetail.setRpId("RpId"); + clientDetail.setStatus("Status"); + clientDetail.setUpdatedBy("UpdatedBy"); + clientDetail.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult1 = Optional.of(clientDetail); + when(clientDetailRepository.findById((String) any())).thenReturn(ofResult1); + io.mosip.pms.oidc.client.dto.ClientDetail actualClientDetails = serviceImpl + .getClientDetails("Id"); + assertEquals(1, actualClientDetails.getAcrValues().size()); + assertEquals("Status", actualClientDetails.getStatus()); + assertEquals("RpId", actualClientDetails.getRelyingPartyId()); + assertEquals(1, actualClientDetails.getRedirectUris().size()); + assertEquals("Public Key", actualClientDetails.getPublicKey()); + assertEquals("Name", actualClientDetails.getPolicyName()); + assertEquals("PolicyId", actualClientDetails.getPolicyId()); + assertEquals("Name", actualClientDetails.getName()); + assertEquals("Logo Uri", actualClientDetails.getLogoUri()); + assertEquals("Id", actualClientDetails.getId()); + assertEquals(1, actualClientDetails.getGrantTypes().size()); + assertEquals(1, actualClientDetails.getClientAuthMethods().size()); + assertEquals(1, actualClientDetails.getClaims().size()); + verify(authPolicyRepository).findById((String) any()); + verify(clientDetailRepository).findById((String) any()); + } + + @Test (expected = PartnerServiceException.class) + public void testGetClientDetails2() { + when(authPolicyRepository.findById((String) any())) + .thenThrow(new PartnerServiceException("An error occurred", "An error occurred")); + + io.mosip.pms.common.entity.ClientDetail clientDetail = new io.mosip.pms.common.entity.ClientDetail(); + clientDetail.setAcrValues("values"); + clientDetail.setClaims("Claims"); + clientDetail.setClientAuthMethods("Client Auth Methods"); + clientDetail.setCreatedBy("Cr By"); + clientDetail.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail.setGrantTypes("Grant Types"); + clientDetail.setId("Id"); + clientDetail.setIsDeleted(false); + clientDetail.setLogoUri("Logo Uri"); + clientDetail.setName("Name"); + clientDetail.setPolicyId("PolicyId"); + clientDetail.setPublicKey("Public Key"); + clientDetail.setRedirectUris("Redirect Uris"); + clientDetail.setRpId("RpId"); + clientDetail.setStatus("Status"); + clientDetail.setUpdatedBy("UpdatedBy"); + clientDetail.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + Optional ofResult = Optional.of(clientDetail); + when(clientDetailRepository.findById((String) any())).thenReturn(ofResult); + serviceImpl.getClientDetails("Id"); + verify(authPolicyRepository).findById((String) any()); + verify(clientDetailRepository).findById((String) any()); + } + + @Test + public void testNotify() { + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + + PartnerDataPublishDto partnerDataPublishDto = new PartnerDataPublishDto(); + partnerDataPublishDto.setCertificateData("Certificate Data"); + partnerDataPublishDto.setPartnerId("PartnerId"); + partnerDataPublishDto.setPartnerName("Partner Name"); + partnerDataPublishDto.setPartnerStatus("Partner Status"); + + PolicyPublishDto policyPublishDto = new PolicyPublishDto(); + policyPublishDto.setPolicy(new JSONObject()); + policyPublishDto.setPolicyCommenceOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyDescription("Policy Description"); + policyPublishDto.setPolicyExpiresOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyId("PolicyId"); + policyPublishDto.setPolicyName("Policy Name"); + policyPublishDto.setPolicyStatus("Policy Status"); + + ClientPublishDto clientPublishDto = new ClientPublishDto(); + clientPublishDto.setAuthContextRefs(new ArrayList<>()); + clientPublishDto.setClientAuthMethods(new ArrayList<>()); + clientPublishDto.setClientId("ClientId"); + clientPublishDto.setClientName("ClientName"); + clientPublishDto.setClientStatus("Client Status"); + clientPublishDto.setUserClaims(new ArrayList<>()); + ReflectionTestUtils.invokeMethod(serviceImpl, "notify", partnerDataPublishDto, policyPublishDto, clientPublishDto, + EventType.MISP_UPDATED); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test + public void testNotify2() { + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + + PartnerDataPublishDto partnerDataPublishDto = new PartnerDataPublishDto(); + partnerDataPublishDto.setCertificateData("Certificate Data"); + partnerDataPublishDto.setPartnerId("PartnerId"); + partnerDataPublishDto.setPartnerName("Partner Name"); + partnerDataPublishDto.setPartnerStatus("Partner Status"); + + PolicyPublishDto policyPublishDto = new PolicyPublishDto(); + policyPublishDto.setPolicy(new JSONObject()); + policyPublishDto.setPolicyCommenceOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyDescription("Policy Description"); + policyPublishDto.setPolicyExpiresOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyId("PolicyId"); + policyPublishDto.setPolicyName("Policy Name"); + policyPublishDto.setPolicyStatus("Policy Status"); + + ClientPublishDto clientPublishDto = new ClientPublishDto(); + clientPublishDto.setAuthContextRefs(new ArrayList<>()); + clientPublishDto.setClientAuthMethods(new ArrayList<>()); + clientPublishDto.setClientId("ClientId"); + clientPublishDto.setClientName("ClientName"); + clientPublishDto.setClientStatus("Client Status"); + clientPublishDto.setUserClaims(new ArrayList<>()); + ReflectionTestUtils.invokeMethod(serviceImpl, "notify", partnerDataPublishDto, policyPublishDto, clientPublishDto, + EventType.POLICY_UPDATED); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test + public void testNotify3() { + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + + PartnerDataPublishDto partnerDataPublishDto = new PartnerDataPublishDto(); + partnerDataPublishDto.setCertificateData("Certificate Data"); + partnerDataPublishDto.setPartnerId("PartnerId"); + partnerDataPublishDto.setPartnerName("Partner Name"); + partnerDataPublishDto.setPartnerStatus("Partner Status"); + + PolicyPublishDto policyPublishDto = new PolicyPublishDto(); + policyPublishDto.setPolicy(new JSONObject()); + policyPublishDto.setPolicyCommenceOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyDescription("Policy Description"); + policyPublishDto.setPolicyExpiresOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyId("PolicyId"); + policyPublishDto.setPolicyName("Policy Name"); + policyPublishDto.setPolicyStatus("Policy Status"); + + ClientPublishDto clientPublishDto = new ClientPublishDto(); + clientPublishDto.setAuthContextRefs(new ArrayList<>()); + clientPublishDto.setClientAuthMethods(new ArrayList<>()); + clientPublishDto.setClientId("ClientId"); + clientPublishDto.setClientName("ClientName"); + clientPublishDto.setClientStatus("Client Status"); + clientPublishDto.setUserClaims(new ArrayList<>()); + ReflectionTestUtils.invokeMethod(serviceImpl, "notify", partnerDataPublishDto, policyPublishDto, clientPublishDto, + EventType.APIKEY_UPDATED); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test + public void testNotify4() { + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + + PartnerDataPublishDto partnerDataPublishDto = new PartnerDataPublishDto(); + partnerDataPublishDto.setCertificateData("Certificate Data"); + partnerDataPublishDto.setPartnerId("PartnerId"); + partnerDataPublishDto.setPartnerName("Partner Name"); + partnerDataPublishDto.setPartnerStatus("Partner Status"); + + PolicyPublishDto policyPublishDto = new PolicyPublishDto(); + policyPublishDto.setPolicy(new JSONObject()); + policyPublishDto.setPolicyCommenceOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyDescription("Policy Description"); + policyPublishDto.setPolicyExpiresOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyId("PolicyId"); + policyPublishDto.setPolicyName("Policy Name"); + policyPublishDto.setPolicyStatus("Policy Status"); + + ClientPublishDto clientPublishDto = new ClientPublishDto(); + clientPublishDto.setAuthContextRefs(new ArrayList<>()); + clientPublishDto.setClientAuthMethods(new ArrayList<>()); + clientPublishDto.setClientId("ClientId"); + clientPublishDto.setClientName("ClientName"); + clientPublishDto.setClientStatus("Client Status"); + clientPublishDto.setUserClaims(new ArrayList<>()); + ReflectionTestUtils.invokeMethod(serviceImpl, "notify", partnerDataPublishDto, policyPublishDto, clientPublishDto, + EventType.PARTNER_UPDATED); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test + public void testNotify5() { + doNothing().when(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + + PartnerDataPublishDto partnerDataPublishDto = new PartnerDataPublishDto(); + partnerDataPublishDto.setCertificateData("Certificate Data"); + partnerDataPublishDto.setPartnerId("PartnerId"); + partnerDataPublishDto.setPartnerName("Partner Name"); + partnerDataPublishDto.setPartnerStatus("Partner Status"); + + PolicyPublishDto policyPublishDto = new PolicyPublishDto(); + policyPublishDto.setPolicy(new JSONObject()); + policyPublishDto.setPolicyCommenceOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyDescription("Policy Description"); + policyPublishDto.setPolicyExpiresOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyId("PolicyId"); + policyPublishDto.setPolicyName("Policy Name"); + policyPublishDto.setPolicyStatus("Policy Status"); + + ClientPublishDto clientPublishDto = new ClientPublishDto(); + clientPublishDto.setAuthContextRefs(new ArrayList<>()); + clientPublishDto.setClientAuthMethods(new ArrayList<>()); + clientPublishDto.setClientId("ClientId"); + clientPublishDto.setClientName("ClientName"); + clientPublishDto.setClientStatus("Client Status"); + clientPublishDto.setUserClaims(new ArrayList<>()); + ReflectionTestUtils.invokeMethod(serviceImpl, "notify", partnerDataPublishDto, policyPublishDto, clientPublishDto, + EventType.CA_CERTIFICATE_UPLOADED); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test (expected = PartnerServiceException.class) + public void testNotify6() { + doThrow(new PartnerServiceException("An error occurred", "An error occurred")).when(webSubPublisher) + .notify((EventType) any(), (Map) any(), (Type) any()); + + PartnerDataPublishDto partnerDataPublishDto = new PartnerDataPublishDto(); + partnerDataPublishDto.setCertificateData("Certificate Data"); + partnerDataPublishDto.setPartnerId("PartnerId"); + partnerDataPublishDto.setPartnerName("Partner Name"); + partnerDataPublishDto.setPartnerStatus("Partner Status"); + + PolicyPublishDto policyPublishDto = new PolicyPublishDto(); + policyPublishDto.setPolicy(new JSONObject()); + policyPublishDto.setPolicyCommenceOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyDescription("Policy Description"); + policyPublishDto.setPolicyExpiresOn(LocalDateTime.of(1, 1, 1, 1, 1)); + policyPublishDto.setPolicyId("PolicyId"); + policyPublishDto.setPolicyName("Policy Name"); + policyPublishDto.setPolicyStatus("Policy Status"); + + ClientPublishDto clientPublishDto = new ClientPublishDto(); + clientPublishDto.setAuthContextRefs(new ArrayList<>()); + clientPublishDto.setClientAuthMethods(new ArrayList<>()); + clientPublishDto.setClientId("ClientId"); + clientPublishDto.setClientName("ClientName"); + clientPublishDto.setClientStatus("Client Status"); + clientPublishDto.setUserClaims(new ArrayList<>()); + ReflectionTestUtils.invokeMethod(serviceImpl, "notify", partnerDataPublishDto, policyPublishDto, clientPublishDto, + EventType.MISP_UPDATED); + verify(webSubPublisher).notify((EventType) any(), (Map) any(), (Type) any()); + } + + @Test + public void testGetPolicyObject() { + ReflectionTestUtils.invokeMethod(serviceImpl,"getPolicyObject","Policy"); + ReflectionTestUtils.invokeMethod(serviceImpl,"getPolicyObject","Auth"); + ReflectionTestUtils.invokeMethod(serviceImpl,"getPolicyObject",""); + ReflectionTestUtils.invokeMethod(serviceImpl,"getPolicyObject","Policy123"); + ReflectionTestUtils.invokeMethod(serviceImpl,"getPolicyObject","123Policy"); + } + + @Test (expected = PartnerServiceException.class) + public void testPublishClientData() { + when(environment.getProperty((String) any())).thenReturn("Property"); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())) + .thenThrow(new PartnerServiceException("An error occurred", "An error occurred")); + + Partner partner = new Partner(); + partner.setAdditionalInfo("Additional Info"); + partner.setAddress("abc"); + partner.setApprovalStatus("Approval Status"); + partner.setCertificateAlias("Certificate Alias"); + partner.setContactNo("9087654321"); + partner.setCrBy("Cr By"); + partner.setCrDtimes(mock(Timestamp.class)); + partner.setDelDtimes(mock(Timestamp.class)); + partner.setEmailId("emailId"); + partner.setId("Id"); + partner.setIsActive(true); + partner.setIsDeleted(false); + partner.setLangCode("eng"); + partner.setLogoUrl("https://pms.net/partner"); + partner.setName("Name"); + partner.setPartnerPolicies(new ArrayList<>()); + partner.setPartnerPolicyRequests(new ArrayList<>()); + partner.setPartnerTypeCode("Partner Type Code"); + partner.setPolicyGroupId("PolicyGroupId"); + partner.setUpdBy("Upd By"); + partner.setUpdDtimes(mock(Timestamp.class)); + partner.setUserId("UserId"); + + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setCrBy("Cr By"); + policyGroup.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setDesc("The characteristics of someone or something"); + policyGroup.setId("Id"); + policyGroup.setIsActive(true); + policyGroup.setIsDeleted(false); + policyGroup.setName("Name"); + policyGroup.setUpdBy("Upd By"); + policyGroup.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setUserId("UserId"); + + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.SetVersion("1.0"); + authPolicy.setCrBy("Cr By"); + authPolicy.setCrDtimes(mock(Timestamp.class)); + authPolicy.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setDescr("Descr"); + authPolicy.setId("Id"); + authPolicy.setIsActive(true); + authPolicy.setIsDeleted(false); + authPolicy.setName("Name"); + authPolicy.setPolicyFileId("FileId"); + authPolicy.setPolicyGroup(policyGroup); + authPolicy.setPolicySchema("Schema"); + authPolicy.setPolicy_type("Policy Type"); + authPolicy.setUpdBy("Upd By"); + authPolicy.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setValidFromDate(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setValidToDate(LocalDateTime.of(1, 1, 1, 1, 1)); + + ClientDetail clientDetail = new ClientDetail(); + clientDetail.setAcrValues("values"); + clientDetail.setClaims("Claims"); + clientDetail.setClientAuthMethods("Client Auth Methods"); + clientDetail.setCreatedBy("Cr By"); + clientDetail.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail.setGrantTypes("Grant Types"); + clientDetail.setId("Id"); + clientDetail.setIsDeleted(false); + clientDetail.setLogoUri("Logo Uri"); + clientDetail.setName("Name"); + clientDetail.setPolicyId("PolicyId"); + clientDetail.setPublicKey("Public Key"); + clientDetail.setRedirectUris("Redirect Uris"); + clientDetail.setRpId("RpId"); + clientDetail.setStatus("Status"); + clientDetail.setUpdatedBy("UpdatedBy"); + clientDetail.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + ReflectionTestUtils.invokeMethod(serviceImpl,"publishClientData",partner,authPolicy,clientDetail); + verify(environment).getProperty((String) any()); + verify(restUtil).getApi((String) any(), (Map) any(), (Class) any()); + verify(MapperUtils.mapDataToPublishDto(partner, ReflectionTestUtils.invokeMethod(serviceImpl,"getPartnerCertificate",(partner.getCertificateAlias())))); + verify(MapperUtils.mapPolicyToPublishDto(authPolicy, ReflectionTestUtils.invokeMethod(serviceImpl,"getPolicyObject",(authPolicy.getPolicyFileId())))); + verify(MapperUtils.mapClientDataToPublishDto(clientDetail)); + verify(ReflectionTestUtils.invokeMethod(serviceImpl,"notify", (any(PartnerDataPublishDto.class)), any(PolicyPublishDto.class), any(ClientPublishDto.class), + eq(EventType.OIDC_CLIENT_CREATED))); + } + + @Test (expected = UndeclaredThrowableException.class) + public void testCallIdpService01() throws Exception { + when(objectMapper.readValue((String) any(), (Class>) any())).thenReturn(new HashMap<>()); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())) + .thenThrow(new PartnerServiceException("An error occurred", "An error occurred")); + + ClientDetail clientDetail = new ClientDetail(); + clientDetail.setAcrValues("values"); + clientDetail.setClaims("Claims"); + clientDetail.setClientAuthMethods("Client Auth Methods"); + clientDetail.setCreatedBy("Cr By"); + clientDetail.setCreatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + clientDetail.setGrantTypes("Grant Types"); + clientDetail.setId("Id"); + clientDetail.setIsDeleted(false); + clientDetail.setLogoUri("Logo Uri"); + clientDetail.setName("Name"); + clientDetail.setPolicyId("PolicyId"); + clientDetail.setPublicKey("Public Key"); + clientDetail.setRedirectUris("Redirect Uris"); + clientDetail.setRpId("RpId"); + clientDetail.setStatus("Status"); + clientDetail.setUpdatedBy("UpdatedBy"); + clientDetail.setUpdatedDateTime(LocalDateTime.of(1, 1, 1, 1, 1)); + + CreateClientRequestDto dto = new CreateClientRequestDto(); + dto.setClientId(clientDetail.getId()); + dto.setClientName(clientDetail.getName()); + dto.setRelyingPartyId(clientDetail.getRpId()); + dto.setLogoUri(clientDetail.getLogoUri()); + dto.setPublicKey(objectMapper.readValue(clientDetail.getPublicKey(), Map.class)); + dto.setUserClaims(Collections.singletonList((clientDetail.getClaims()))); + dto.setAuthContextRefs(Collections.singletonList(clientDetail.getAcrValues())); + dto.setRedirectUris(Collections.singletonList(clientDetail.getRedirectUris())); + dto.setGrantTypes(Collections.singletonList(clientDetail.getGrantTypes())); + dto.setClientAuthMethods(Collections.singletonList(clientDetail.getClientAuthMethods())); + ReflectionTestUtils.invokeMethod(serviceImpl,"callIdpService",clientDetail,"calleeApi",true); + verify(objectMapper).readValue((String) any(), (Class>) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + } + + @Test (expected = NullPointerException.class) + public void testGetReqAttributeFromPolicyJson() { + + JSONObject policyObject = new JSONObject(); + policyObject.put("id","001"); + policyObject.put("name","Policy"); + + ReflectionTestUtils.invokeMethod(serviceImpl,"getReqAttributeFromPolicyJson",policyObject,"Parent Attribute", "Child Attribute", + "Filter Attribute"); + } + + @Test (expected = ApiAccessibleException.class) + public void testMakeCreateIDPServiceCall01() throws JsonProcessingException { + ClientDetailResponse clientDetailResponse = new ClientDetailResponse(); + clientDetailResponse.setClientId("ClientId"); + clientDetailResponse.setStatus("Status"); + when(objectMapper.readValue((String) any(), (Class) any())) + .thenReturn(clientDetailResponse); + when(objectMapper.writeValueAsString((Object) any())).thenReturn("123"); + when(restUtil.postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any())).thenReturn(new HashMap<>()); + assertSame(clientDetailResponse, ReflectionTestUtils.invokeMethod(serviceImpl,"makeCreateIDPServiceCall","Request","Callee Api")); + verify(objectMapper).readValue((String) any(), (Class) any()); + verify(objectMapper).writeValueAsString((Object) any()); + verify(restUtil).postApi((String) any(), (List) any(), (String) any(), (String) any(), (MediaType) any(), + (Object) any(), (Class) any()); + } + + @Test (expected = PartnerServiceException.class) + public void testGetPartnerCertificate01() { + when(environment.getProperty((String) any())).thenReturn("Property"); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())) + .thenThrow(new PartnerServiceException("An error occurred", "An error occurred")); + ReflectionTestUtils.invokeMethod(serviceImpl,"getPartnerCertificate","Certificate Alias"); + verify(environment).getProperty((String) any()); + verify(restUtil).getApi((String) any(), (Map) any(), (Class) any()); + } + + @Test (expected = ApiAccessibleException.class) + public void testGetPartnerCertificate02() throws JsonProcessingException { + when(environment.getProperty((String) any())).thenReturn("Property"); + + PartnerCertDownloadResponeDto partnerCertDownloadResponeDto = new PartnerCertDownloadResponeDto(); + partnerCertDownloadResponeDto.setCertificateData("Certificate Data"); + partnerCertDownloadResponeDto.setTimestamp(LocalDateTime.of(1, 1, 1, 1, 1)); + when(objectMapper.readValue((String) any(), (Class) any())) + .thenReturn(partnerCertDownloadResponeDto); + when(objectMapper.writeValueAsString((Object) any())).thenReturn("123"); + when(restUtil.getApi((String) any(), (Map) any(), (Class) any())) + .thenReturn(new HashMap<>()); + assertEquals("Certificate Data", ReflectionTestUtils.invokeMethod(serviceImpl,"getPartnerCertificate","Certificate Alias")); + verify(environment).getProperty((String) any()); + verify(objectMapper).readValue((String) any(), (Class) any()); + verify(objectMapper).writeValueAsString((Object) any()); + verify(restUtil).getApi((String) any(), (Map) any(), (Class) any()); + } + + @Test (expected = PartnerServiceException.class) + //@Ignore + public void testCreateOIDCClient01() throws Exception { + + ClientDetailCreateRequest createRequest = new ClientDetailCreateRequest(); + createRequest.setName("ClientName"); + createRequest.setAuthPartnerId("mosip_partnerorg1665194709609"); + createRequest.setPolicyId("53704"); + List clientAuthMethods = new ArrayList(); + clientAuthMethods.add("private_key_jwt"); + createRequest.setClientAuthMethods(clientAuthMethods); + List setGrantTypes = new ArrayList(); + setGrantTypes.add("authorization_code"); + createRequest.setGrantTypes(setGrantTypes); + createRequest.setLogoUri("https://testcase.pms.net/browse/OIDCClient.png"); + List setRedirectUris = new ArrayList(); + setRedirectUris.add("https://testcase.pms.net/browse/OIDCClient"); + createRequest.setRedirectUris(setRedirectUris); + createRequest.setPublicKey(public_key); + + Partner partner = new Partner(); + partner.setAdditionalInfo("Additional Info"); + partner.setAddress("abc"); + partner.setApprovalStatus("Approval Status"); + partner.setCertificateAlias("Certificate Alias"); + partner.setContactNo("9087654321"); + partner.setCrBy("Cr By"); + partner.setCrDtimes(mock(Timestamp.class)); + partner.setDelDtimes(mock(Timestamp.class)); + partner.setEmailId("emailId"); + partner.setId("mosip_partnerorg1665194709609"); + partner.setIsActive(true); + partner.setIsDeleted(false); + partner.setLangCode("eng"); + partner.setLogoUrl("https://pms.net/partner"); + partner.setName("auth"); + partner.setPartnerPolicies(new ArrayList<>()); + partner.setPartnerPolicyRequests(new ArrayList<>()); + partner.setPartnerTypeCode("Auth_Policy"); + partner.setPolicyGroupId("mosip_partnerorg1665194709609"); + partner.setUpdBy("Upd By"); + partner.setUpdDtimes(mock(Timestamp.class)); + partner.setUserId("UserId"); + + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setCrBy("Cr By"); + policyGroup.setCrDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setDesc("The characteristics of someone or something"); + policyGroup.setId("mosip_partnerorg1665194709609"); + policyGroup.setIsActive(true); + policyGroup.setIsDeleted(false); + policyGroup.setName("Name"); + policyGroup.setUpdBy("Upd By"); + policyGroup.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + policyGroup.setUserId("UserId"); + + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.SetVersion("1.0"); + authPolicy.setCrBy("Cr By"); + authPolicy.setCrDtimes(mock(Timestamp.class)); + authPolicy.setDelDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setDescr("Descr"); + authPolicy.setId("mosip_partnerorg1665194709609"); + authPolicy.setIsActive(true); + authPolicy.setIsDeleted(false); + authPolicy.setName("Name"); + authPolicy.setPolicyFileId("42"); + authPolicy.setPolicyGroup(policyGroup); + authPolicy.setPolicySchema("Schema"); + authPolicy.setPolicy_type("Policy Type"); + authPolicy.setUpdBy("Upd By"); + authPolicy.setUpdDtimes(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setValidFromDate(LocalDateTime.of(1, 1, 1, 1, 1)); + authPolicy.setValidToDate(LocalDateTime.of(1, 1, 1, 1, 1)); + + when(clientDetailRepository.findById(anyString())).thenReturn(Optional.empty()); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + when(authPolicyRepository.findById(anyString())).thenReturn(Optional.of(authPolicy)); + + ClientDetailResponse response = serviceImpl.createOIDCClient(createRequest); + + assertNotNull(response); + } + + @Test + public void testConvertStringToList01() { + String inputString = "id,name,email"; + List expectedList = Arrays.asList("id", "name", "email"); + List resultList = ReflectionTestUtils.invokeMethod(serviceImpl, "convertStringToList", inputString); + assertEquals(expectedList, resultList); + } + } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerManagementControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerManagementControllerTest.java index bd546b8648..df82f4b403 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerManagementControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerManagementControllerTest.java @@ -1,15 +1,22 @@ package io.mosip.pms.test.partner.controller; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doNothing; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import io.mosip.pms.partner.manager.controller.PartnerManagementController; +import lombok.SneakyThrows; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -218,4 +225,122 @@ public void activateDeactivatePartnerAPIKey() throws Exception { mockMvc.perform(MockMvcRequestBuilders.patch("/partners/1234/policy/456/apiKey/status").contentType(MediaType.APPLICATION_JSON_VALUE) .content(objectMapper.writeValueAsString(request))).andExpect(MockMvcResultMatchers.status().isOk()); } + + @Test (expected = Exception.class) + public void testGetPartnersDetails() { + PartnerManagementController partnerManagementController = new PartnerManagementController(); + partnerManagementController.getPartnersDeatils(Optional.of("1234")); + } + + @Test (expected = Exception.class) + public void testApproveRejectPolicyMappings() { + + PartnerManagementController partnerManagementController = new PartnerManagementController(); + + StatusRequestDto statusRequestDto = new StatusRequestDto(); + statusRequestDto.setStatus("Status"); + + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setId("mosip.partnermanagement.partners.policy.mapping"); + requestWrapper.setMetadata("{}"); + requestWrapper.setRequest(statusRequestDto); + requestWrapper.setRequesttime(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime()); + requestWrapper.setVersion("1.0"); + partnerManagementController.approveRejectPolicyMappings(requestWrapper, "MappingKey"); + } + + @Test (expected = Exception.class) + public void testApproveRejectPolicyMappings2() { + + PartnerManagementController partnerManagementController = new PartnerManagementController(); + + StatusRequestDto statusRequestDto = new StatusRequestDto(); + statusRequestDto.setStatus("Status"); + RequestWrapper requestWrapper = (RequestWrapper) mock(RequestWrapper.class); + when(requestWrapper.getId()).thenReturn("mosip.partnermanagement.partners.policy.mapping"); + when(requestWrapper.getVersion()).thenReturn("1.0"); + doNothing().when(requestWrapper).setId((String) any()); + doNothing().when(requestWrapper).setMetadata((Object) any()); + doNothing().when(requestWrapper).setRequest((StatusRequestDto) any()); + doNothing().when(requestWrapper).setRequesttime((LocalDateTime) any()); + doNothing().when(requestWrapper).setVersion((String) any()); + requestWrapper.setId("mosip.partnermanagement.partners.policy.mapping"); + requestWrapper.setMetadata("{}"); + requestWrapper.setRequest(statusRequestDto); + requestWrapper.setRequesttime(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime()); + requestWrapper.setVersion("1.0"); + partnerManagementController.approveRejectPolicyMappings(requestWrapper, "MappingKey"); + } + + @SneakyThrows + @Test + public void testActivateDeactivatePartnerAPIKey() { + PartnerManagementController partnerManagementController = new PartnerManagementController(); + + APIkeyStatusUpdateRequestDto apIkeyStatusUpdateRequestDto = new APIkeyStatusUpdateRequestDto(); + apIkeyStatusUpdateRequestDto.setLabel("Label"); + apIkeyStatusUpdateRequestDto.setStatus("Status"); + + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setId("mosip.partnermanagement.partners.policy.mapping"); + requestWrapper.setMetadata("{}"); + requestWrapper.setRequest(apIkeyStatusUpdateRequestDto); + requestWrapper.setRequesttime(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime()); + requestWrapper.setVersion("1.0"); + Mockito.when(partnerManagementService.updateAPIKeyStatus("1234","456",apIkeyStatusUpdateRequestDto)) + .thenReturn("Success"); + mockMvc.perform(MockMvcRequestBuilders.patch("/partners/1234/policy/456/apiKey/status").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(MockMvcResultMatchers.status().isUnauthorized()); + } + + @SneakyThrows + @Test (expected = Exception.class) + public void testActivateDeactivatePartnerAPIKey2() { + + PartnerManagementController partnerManagementController = new PartnerManagementController(); + + APIkeyStatusUpdateRequestDto apIkeyStatusUpdateRequestDto = new APIkeyStatusUpdateRequestDto(); + apIkeyStatusUpdateRequestDto.setLabel("Label"); + apIkeyStatusUpdateRequestDto.setStatus("Status"); + RequestWrapper requestWrapper = (RequestWrapper) mock(RequestWrapper.class); + when(requestWrapper.getId()).thenReturn("id"); + when(requestWrapper.getVersion()).thenReturn("1.0"); + doNothing().when(requestWrapper).setId((String) any()); + doNothing().when(requestWrapper).setMetadata((Object) any()); + doNothing().when(requestWrapper).setRequest((APIkeyStatusUpdateRequestDto) any()); + doNothing().when(requestWrapper).setRequesttime((LocalDateTime) any()); + doNothing().when(requestWrapper).setVersion((String) any()); + requestWrapper.setId("mosip.partnermanagement.partners.policy.mapping"); + requestWrapper.setMetadata("{}"); + requestWrapper.setRequest(apIkeyStatusUpdateRequestDto); + requestWrapper.setRequesttime(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime()); + requestWrapper.setVersion("1.0"); + Mockito.when(partnerManagementService.updateAPIKeyStatus("1234","456",apIkeyStatusUpdateRequestDto)) + .thenReturn("Success"); + + partnerManagementController.activateDeactivatePartnerAPIKey("1234", "456", requestWrapper); + + mockMvc.perform(MockMvcRequestBuilders.patch("/partners/1234/policy/456/apiKey/status").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(MockMvcResultMatchers.status().isOk()); + } + + @Test (expected = Exception.class) + public void testActivateDeactivatePartnerAPIKey3() { + + PartnerManagementController partnerManagementController = new PartnerManagementController(); + + APIkeyStatusUpdateRequestDto apIkeyStatusUpdateRequestDto = new APIkeyStatusUpdateRequestDto(); + apIkeyStatusUpdateRequestDto.setLabel("Label"); + apIkeyStatusUpdateRequestDto.setStatus("Status"); + + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setId("mosip.partnermanagement.partners.policy.mapping"); + requestWrapper.setMetadata("{}"); + requestWrapper.setRequest(apIkeyStatusUpdateRequestDto); + requestWrapper.setRequesttime(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime()); + requestWrapper.setVersion("1.0"); + partnerManagementController.activateDeactivatePartnerAPIKey("123", "456", requestWrapper); + + } + }