From 5fb9b5049eca0ce1110241ad51702a51e631f63e Mon Sep 17 00:00:00 2001 From: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:51:16 +0530 Subject: [PATCH 01/15] MOSIP-25622 : Updated OIDC Client Details For Audit Purpose --- .../io/mosip/pms/device/util/AuditUtil.java | 40 +++++++ .../contant/ClientServiceAuditEnum.java | 100 ++++++++++++++++++ .../ClientManagementController.java | 58 +++++++--- .../impl/ClientManagementServiceImpl.java | 30 +++++- 4 files changed, 212 insertions(+), 16 deletions(-) create mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/oidc/client/contant/ClientServiceAuditEnum.java 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 0ffd0c8b42..e77fe5c535 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..68e5177602 --- /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_100", 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_200", 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_300", 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_600", 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_700", 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_800", 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..b954a04f52 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,29 +26,55 @@ public class ClientManagementController { @Autowired ClientManagementService clientManagementService; + @Autowired + AuditUtil auditUtil; + + String msg = "mosip.clientmanagement.clients.retrieve"; + + String version = "1.0"; + @RequestMapping(value = "/oidc/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseWrapper createClient( + public ResponseEntity> createClient( @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { - var clientRespDto = clientManagementService.createOIDCClient(requestWrapper.getRequest()); - var response = new ResponseWrapper(); - response.setResponse(clientRespDto); - return response; + //var clientRespDto = clientManagementService.createOIDCClient(requestWrapper.getRequest()); + ResponseWrapper response = new ResponseWrapper<>(); + //var response = new ResponseWrapper(); + ClientDetailResponse clientDetailResponse = null; + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT,requestWrapper.getRequest().getName(),"clientID"); + clientDetailResponse = clientManagementService.createOIDCClient(requestWrapper.getRequest()); + //response.setResponse(clientRespDto); + response.setId(requestWrapper.getId()); + response.setVersion(requestWrapper.getVersion()); + response.setResponse(clientDetailResponse); + return new ResponseEntity<>(response, HttpStatus.OK); } @RequestMapping(value = "/oidc/client/{client_id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseWrapper updateClient(@PathVariable("client_id") String clientId, + public ResponseEntity> updateClient(@PathVariable("client_id") String clientId, @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { - var clientRespDto = clientManagementService.updateOIDCClient(clientId, requestWrapper.getRequest()); - var response = new ResponseWrapper(); - response.setResponse(clientRespDto); - return response; + //var clientRespDto = clientManagementService.updateOIDCClient(clientId, requestWrapper.getRequest()); + ResponseWrapper response = new ResponseWrapper<>(); + //var response = new ResponseWrapper(); + ClientDetailResponse clientDetailResponse = null; + ClientDetailUpdateRequest updateRequest = requestWrapper.getRequest(); + auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT, clientId, "clientID"); + clientDetailResponse = clientManagementService.updateOIDCClient(clientId, updateRequest); + response.setId(requestWrapper.getId()); + response.setVersion(requestWrapper.getVersion()); + response.setResponse(clientDetailResponse); + return new ResponseEntity<>(response, HttpStatus.OK); } @RequestMapping(value = "/oidc/client/{client_id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseWrapper getClient(@PathVariable("client_id") String clientId) + public ResponseEntity> getClient(@PathVariable("client_id") String clientId) throws Exception { - var response = new ResponseWrapper(); - response.setResponse(clientManagementService.getClientDetails(clientId)); - return response; + ResponseWrapper response = new ResponseWrapper<>(); + ClientDetail clientDetail = null; + clientDetail = clientManagementService.getClientDetails(clientId); + //var response = new ResponseWrapper(); + response.setId(msg); + response.setVersion(version); + response.setResponse(clientDetail); + return new ResponseEntity<>(response, HttpStatus.OK); } } 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 4d2443db27..3c7fb560bd 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; @@ -95,6 +98,9 @@ public class ClientManagementServiceImpl implements ClientManagementService { @Autowired RestUtil restUtil; + @Autowired + AuditUtil auditUtil; + @Autowired private Environment environment; @@ -111,29 +117,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())); } @@ -142,6 +158,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()); } @@ -151,6 +169,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()); } @@ -168,6 +188,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()); } @@ -177,6 +198,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()); } @@ -191,7 +213,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; } @@ -366,6 +390,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()); } @@ -384,8 +409,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; - } + } /** * From 7281baddb46391e1be82c69ba5462d3d54435b55 Mon Sep 17 00:00:00 2001 From: Gokulraj C <110164849+GOKULRAJ136@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:58:26 +0530 Subject: [PATCH 02/15] Remove Commented Codes --- .../oidc/client/controller/ClientManagementController.java | 6 ------ 1 file changed, 6 deletions(-) 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 b954a04f52..0e912754dd 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 @@ -36,13 +36,10 @@ public class ClientManagementController { @RequestMapping(value = "/oidc/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> createClient( @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { - //var clientRespDto = clientManagementService.createOIDCClient(requestWrapper.getRequest()); ResponseWrapper response = new ResponseWrapper<>(); - //var response = new ResponseWrapper(); ClientDetailResponse clientDetailResponse = null; auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT,requestWrapper.getRequest().getName(),"clientID"); clientDetailResponse = clientManagementService.createOIDCClient(requestWrapper.getRequest()); - //response.setResponse(clientRespDto); response.setId(requestWrapper.getId()); response.setVersion(requestWrapper.getVersion()); response.setResponse(clientDetailResponse); @@ -52,9 +49,7 @@ public ResponseEntity> createClient( @RequestMapping(value = "/oidc/client/{client_id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> updateClient(@PathVariable("client_id") String clientId, @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { - //var clientRespDto = clientManagementService.updateOIDCClient(clientId, requestWrapper.getRequest()); ResponseWrapper response = new ResponseWrapper<>(); - //var response = new ResponseWrapper(); ClientDetailResponse clientDetailResponse = null; ClientDetailUpdateRequest updateRequest = requestWrapper.getRequest(); auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT, clientId, "clientID"); @@ -71,7 +66,6 @@ public ResponseEntity> getClient(@PathVariable("cl ResponseWrapper response = new ResponseWrapper<>(); ClientDetail clientDetail = null; clientDetail = clientManagementService.getClientDetails(clientId); - //var response = new ResponseWrapper(); response.setId(msg); response.setVersion(version); response.setResponse(clientDetail); From e9c6a33b49a6bf402f9e54d7f5b5b522b114f0af Mon Sep 17 00:00:00 2001 From: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com> Date: Thu, 13 Apr 2023 09:31:30 +0530 Subject: [PATCH 03/15] Updated EvenID's --- .../oidc/client/contant/ClientServiceAuditEnum.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 index 68e5177602..3787e12d40 100644 --- 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 @@ -4,22 +4,22 @@ public enum ClientServiceAuditEnum { - CREATE_CLIENT("PMS_PRT_100", AuditConstant.AUDIT_SYSTEM, "POST CREATE OIDC CLIENT", + 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_200", AuditConstant.AUDIT_SYSTEM, "POST CREATE OIDC CLIENT", + 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_300", AuditConstant.AUDIT_SYSTEM, "POST CREATE OIDC CLIENT", + 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_600", AuditConstant.AUDIT_SYSTEM, "PUT UPDATE OIDC CLIENT", + 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_700", AuditConstant.AUDIT_SYSTEM, "PUT UPDATE OIDC CLIENT", + 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_800", AuditConstant.AUDIT_SYSTEM, "PUT UPDATE OIDC CLIENT", + 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); From 83ea6375413f4100fcb73e274d4f3bd9a0411eac Mon Sep 17 00:00:00 2001 From: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com> Date: Thu, 13 Apr 2023 09:56:09 +0530 Subject: [PATCH 04/15] Updated the return type in the controller --- .../ClientManagementController.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) 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 0e912754dd..29d37eeaf1 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 @@ -34,41 +34,36 @@ public class ClientManagementController { String version = "1.0"; @RequestMapping(value = "/oidc/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> createClient( + public ResponseWrapper createClient( @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { - ResponseWrapper response = new ResponseWrapper<>(); - ClientDetailResponse clientDetailResponse = null; + var clientRespDto = clientManagementService.createOIDCClient(requestWrapper.getRequest()); + var response = new ResponseWrapper(); auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT,requestWrapper.getRequest().getName(),"clientID"); - clientDetailResponse = clientManagementService.createOIDCClient(requestWrapper.getRequest()); response.setId(requestWrapper.getId()); response.setVersion(requestWrapper.getVersion()); - response.setResponse(clientDetailResponse); - return new ResponseEntity<>(response, HttpStatus.OK); + response.setResponse(clientRespDto); + return response; } @RequestMapping(value = "/oidc/client/{client_id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> updateClient(@PathVariable("client_id") String clientId, + public ResponseWrapper updateClient(@PathVariable("client_id") String clientId, @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { - ResponseWrapper response = new ResponseWrapper<>(); - ClientDetailResponse clientDetailResponse = null; - ClientDetailUpdateRequest updateRequest = requestWrapper.getRequest(); + var clientRespDto = clientManagementService.updateOIDCClient(clientId, requestWrapper.getRequest()); + var response = new ResponseWrapper(); auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT, clientId, "clientID"); - clientDetailResponse = clientManagementService.updateOIDCClient(clientId, updateRequest); response.setId(requestWrapper.getId()); response.setVersion(requestWrapper.getVersion()); - response.setResponse(clientDetailResponse); - return new ResponseEntity<>(response, HttpStatus.OK); + response.setResponse(clientRespDto); + return response; } @RequestMapping(value = "/oidc/client/{client_id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getClient(@PathVariable("client_id") String clientId) + public ResponseWrapper getClient(@PathVariable("client_id") String clientId) throws Exception { - ResponseWrapper response = new ResponseWrapper<>(); - ClientDetail clientDetail = null; - clientDetail = clientManagementService.getClientDetails(clientId); + var response = new ResponseWrapper(); + response.setResponse(clientManagementService.getClientDetails(clientId)); response.setId(msg); response.setVersion(version); - response.setResponse(clientDetail); - return new ResponseEntity<>(response, HttpStatus.OK); + return response; } } From 4e51f6f2c1d7315f8aa76abd331e5f7dacbf3856 Mon Sep 17 00:00:00 2001 From: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:30:34 +0530 Subject: [PATCH 05/15] Removed Set Items --- .../client/controller/ClientManagementController.java | 9 --------- 1 file changed, 9 deletions(-) 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 29d37eeaf1..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 @@ -29,9 +29,6 @@ public class ClientManagementController { @Autowired AuditUtil auditUtil; - String msg = "mosip.clientmanagement.clients.retrieve"; - - String version = "1.0"; @RequestMapping(value = "/oidc/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseWrapper createClient( @@ -39,8 +36,6 @@ public ResponseWrapper createClient( var clientRespDto = clientManagementService.createOIDCClient(requestWrapper.getRequest()); var response = new ResponseWrapper(); auditUtil.setAuditRequestDto(ClientServiceAuditEnum.CREATE_CLIENT,requestWrapper.getRequest().getName(),"clientID"); - response.setId(requestWrapper.getId()); - response.setVersion(requestWrapper.getVersion()); response.setResponse(clientRespDto); return response; } @@ -51,8 +46,6 @@ public ResponseWrapper updateClient(@PathVariable("client_ var clientRespDto = clientManagementService.updateOIDCClient(clientId, requestWrapper.getRequest()); var response = new ResponseWrapper(); auditUtil.setAuditRequestDto(ClientServiceAuditEnum.UPDATE_CLIENT, clientId, "clientID"); - response.setId(requestWrapper.getId()); - response.setVersion(requestWrapper.getVersion()); response.setResponse(clientRespDto); return response; } @@ -62,8 +55,6 @@ public ResponseWrapper getClient(@PathVariable("client_id") String throws Exception { var response = new ResponseWrapper(); response.setResponse(clientManagementService.getClientDetails(clientId)); - response.setId(msg); - response.setVersion(version); return response; } } From c7f4df876f4accea3cb21689e5a14065cd26f441 Mon Sep 17 00:00:00 2001 From: GOKULRAJ136 <110164849+GOKULRAJ136@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:30:58 +0530 Subject: [PATCH 06/15] Added Test Cases for Increasing the coverage PMS --- .../impl/FTPChipDetailServiceTest.java | 637 +++++++++++- .../impl/ClientManagementServiceImplTest.java | 923 +++++++++++++++++- .../PartnerManagementControllerTest.java | 125 +++ 3 files changed, 1671 insertions(+), 14 deletions(-) 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); + + } + } From 53f6779cfd18ce5ab520bb2a9c7784227db22561 Mon Sep 17 00:00:00 2001 From: Keshav Mishra Date: Wed, 6 Sep 2023 17:57:43 +0530 Subject: [PATCH 07/15] [MOSIP-29315] Signed-off-by: Keshav Mishra --- db_scripts/mosip_pms/ddl/pms-oidc_client.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db_scripts/mosip_pms/ddl/pms-oidc_client.sql b/db_scripts/mosip_pms/ddl/pms-oidc_client.sql index b32edcc7c0..dd7ec35e8f 100644 --- a/db_scripts/mosip_pms/ddl/pms-oidc_client.sql +++ b/db_scripts/mosip_pms/ddl/pms-oidc_client.sql @@ -38,7 +38,7 @@ CREATE TABLE pms.oidc_client( CONSTRAINT uq_oidc_client_public_key UNIQUE (public_key) ); -- ddl-end -- -COMMENT ON TABLE pms.oidc_client.id IS 'Client ID: Unique id assigned to registered OIDC client.'; +COMMENT ON TABLE pms.oidc_client IS 'Client ID: Unique id assigned to registered OIDC client.'; -- ddl-end -- COMMENT ON COLUMN pms.oidc_client.name IS 'Client Name: Registered name of OIDC client.'; -- ddl-end -- @@ -62,4 +62,3 @@ COMMENT ON COLUMN pms.oidc_client.claims IS 'Requested Claims: claims json as pe -- ddl-end -- COMMENT ON COLUMN pms.oidc_client.acr_values IS 'Allowed Authentication context References(acr) json'; -- ddl-end -- - From 75a41b04ec1921a6698d6eeca6891a7dd5bab3e5 Mon Sep 17 00:00:00 2001 From: bhumi46 <111699703+bhumi46@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:12:46 +0530 Subject: [PATCH 08/15] [MOSIP-29256] updated reusable worklows (#602) * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows --- .github/workflows/mavenpublish.yml | 214 -------------- .github/workflows/postgres-init_trigger.yml | 83 ------ .github/workflows/push-trigger.yml | 88 ++++++ .github/workflows/push_trigger.yml | 311 -------------------- .github/workflows/release-changes.yml | 26 ++ .github/workflows/release_changes.yml | 56 ---- .github/workflows/release_trigger.yml | 209 ------------- .github/workflows/tag.yml | 33 +++ 8 files changed, 147 insertions(+), 873 deletions(-) delete mode 100644 .github/workflows/mavenpublish.yml delete mode 100644 .github/workflows/postgres-init_trigger.yml create mode 100644 .github/workflows/push-trigger.yml delete mode 100644 .github/workflows/push_trigger.yml create mode 100644 .github/workflows/release-changes.yml delete mode 100644 .github/workflows/release_changes.yml delete mode 100644 .github/workflows/release_trigger.yml create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/mavenpublish.yml b/.github/workflows/mavenpublish.yml deleted file mode 100644 index 331c817d32..0000000000 --- a/.github/workflows/mavenpublish.yml +++ /dev/null @@ -1,214 +0,0 @@ -# This workflow will build a package using Maven and then publish it nexus when a pull request is merged -# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path - -name: Maven Package upon a pull request - -on: - pull_request: - types: [closed] - -jobs: - build: - - runs-on: ubuntu-latest - if: github.event.pull_request.merged == true - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd partner - mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - - publish_to_nexus: - - runs-on: ubuntu-latest - if: github.event.pull_request.merged == true - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false " > $GITHUB_WORKSPACE/settings.xml - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - - name: Build with Maven - run: cd partner && mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Publish the maven package - run: | - chmod +x ./deploy.sh - ./deploy.sh partner $GITHUB_WORKSPACE/settings.xml SNAPSHOT - env: - GPG_TTY: $(tty) - - docker-policy-management-service: - needs: build - - runs-on: ubuntu-latest - env: - NAMESPACE: mosipdev - SERVICE_NAME: policy-management-service - SERVICE_LOCATION: partner/policy-management-service - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the policy-management-service - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - VERSION=$BRANCH_NAME - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - docker-partner-management-service: - needs: build - - runs-on: ubuntu-latest - env: - NAMESPACE: mosipdev - SERVICE_NAME: partner-management-service - SERVICE_LOCATION: partner/partner-management-service - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the partner-management-service - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - VERSION=$BRANCH_NAME - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION \ No newline at end of file diff --git a/.github/workflows/postgres-init_trigger.yml b/.github/workflows/postgres-init_trigger.yml deleted file mode 100644 index 3de4c6f32c..0000000000 --- a/.github/workflows/postgres-init_trigger.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Trigger postgres-init repo upon db scripts updates - -on: - push: - branches: - - master - - 1.* - - develop - - release* - paths: - - db_release_scripts/** - - db_scripts/** - -jobs: - paths-filter: - runs-on: ubuntu-latest - outputs: - db_release_scripts: ${{ steps.filter.outputs.db_release_scripts }} - db_scripts: ${{ steps.filter.outputs.db_scripts }} - steps: - - uses: actions/checkout@v2 - - uses: dorny/paths-filter@v2 - id: filter - with: - base: ${{ github.ref }} - filters: | - db_release_scripts: - - 'db_release_scripts/**' - db_scripts: - - 'db_scripts/**' - - # run only if 'db_release_scripts' files were changed - db_release_scripts_updates: - needs: paths-filter - if: needs.paths-filter.outputs.db_release_scripts == 'true' - runs-on: ubuntu-latest - steps: - - name: Check for updates - run: echo "Updates are present in db_release_scripts directory, Triggering postgres-init repo" - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,job,took,ref # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_DEVOPS }} # required - if: success() # Pick up events when the job is successful. - - # run only if not 'db_release_scripts' files were changed - - name: Check for no updates - if: needs.paths-filter.outputs.db_release_scripts != 'true' - run: echo "Updates are not present in db_release_scripts directory" - - # run only if 'db_scripts' files were changed - db_scripts_updates: - needs: paths-filter - if: needs.paths-filter.outputs.db_scripts == 'true' - runs-on: ubuntu-latest - steps: - - name: Check for updates - run: echo "Updates are present in db_scripts directory, Triggering postgres-init repo" - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,job,took,ref # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_DEVOPS }} # required - if: success() # Pick up events when the job is successful. - - # run only if not 'db_scripts' files were changed - - name: Check for no updates - if: needs.paths-filter.outputs.db_scripts != 'true' - run: echo "Updates are not present in db_scripts directory" - - # This job is to trigger postgres-init repo. - trigger-postgres_init_repo: - runs-on: ubuntu-latest - steps: - - uses: peter-evans/repository-dispatch@v2 - with: - token: ${{ secrets.ACTION_PAT }} - repository: mosip/postgres-init - base: ${{ github.ref }} - event-type: db-event diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml new file mode 100644 index 0000000000..db27b6a745 --- /dev/null +++ b/.github/workflows/push-trigger.yml @@ -0,0 +1,88 @@ +name: Maven Package upon a push + +on: + release: + types: [published] + pull_request: + types: [opened] + 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* + +jobs: + build-maven-partner: + uses: mosip/kattu/.github/workflows/maven-build.yml@master + with: + SERVICE_LOCATION: ./partner + BUILD_ARTIFACT: partner + secrets: + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + publish_to_nexus: + if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' }}" + needs: build-maven-partner + uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master + with: + SERVICE_LOCATION: ./partner + secrets: + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + build-dockers: + needs: build-maven-partner + strategy: + matrix: + include: + - SERVICE_LOCATION: 'partner/partner-management-service' + SERVICE_NAME: 'partner-management-service' + BUILD_ARTIFACT: 'partner' + - SERVICE_LOCATION: 'partner/policy-management-service' + SERVICE_NAME: 'policy-management-service' + BUILD_ARTIFACT: 'partner' + fail-fast: false + name: ${{ matrix.SERVICE_NAME }} + uses: mosip/kattu/.github/workflows/docker-build.yml@master + with: + SERVICE_LOCATION: ${{ matrix.SERVICE_LOCATION }} + SERVICE_NAME: ${{ matrix.SERVICE_NAME }} + BUILD_ARTIFACT: ${{ matrix.BUILD_ARTIFACT }} + secrets: + DEV_NAMESPACE_DOCKER_HUB: ${{ secrets.DEV_NAMESPACE_DOCKER_HUB }} + ACTOR_DOCKER_HUB: ${{ secrets.ACTOR_DOCKER_HUB }} + RELEASE_DOCKER_HUB: ${{ secrets.RELEASE_DOCKER_HUB }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + sonar_analysis: + needs: build-maven-partner + if: "${{ github.event_name != 'pull_request' }}" + uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master + with: + SERVICE_LOCATION: ./partner + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + ORG_KEY: ${{ secrets.ORG_KEY }} + OSSRH_USER: ${{ secrets.OSSRH_USER }} + 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 diff --git a/.github/workflows/push_trigger.yml b/.github/workflows/push_trigger.yml deleted file mode 100644 index d2a76d7f9e..0000000000 --- a/.github/workflows/push_trigger.yml +++ /dev/null @@ -1,311 +0,0 @@ -name: Maven Package upon a push - -on: - push: - branches: - - '!release-branch' - - release-1* - - master - - 1.* - - develop - -jobs: - build: - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd partner - mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,workflow,job # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - publish_to_nexus: - if: "!contains(github.ref, 'master')" - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false " > $GITHUB_WORKSPACE/settings.xml - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - name: Build with Maven - run: cd partner && mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Publish the maven package - run: | - chmod +x ./deploy.sh - cd partner && mvn deploy -s $GITHUB_WORKSPACE/settings.xml -f pom.xml - env: - GPG_TTY: $(tty) - # - uses: 8398a7/action-slack@v3 - # with: - # status: ${{ job.status }} - # fields: repo,message,commit,workflow,job # selectable (default: repo,message) - # env: - # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVOPS_WEBHOOK }} # required - # if: failure() # Pick up events even if the job fails or is canceled.D - - docker-policy-management-service: - needs: build - - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets.dev_namespace_docker_hub }} - SERVICE_NAME: policy-management-service - SERVICE_LOCATION: partner/policy-management-service - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the policy-management-service - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --build-arg SOURCE=mosip --build-arg COMMIT_HASH=$(git rev-parse HEAD) --build-arg COMMIT_ID=$(git rev-parse --short HEAD) --build-arg BUILD_TIME=${{steps.date.outputs.date}} --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - if [[ $BRANCH_NAME == master ]]; then - VERSION=latest - else - VERSION=$BRANCH_NAME - fi - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,workflow,job # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVOPS_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - docker-partner-management-service: - needs: build - - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets.dev_namespace_docker_hub }} - SERVICE_NAME: partner-management-service - SERVICE_LOCATION: partner/partner-management-service - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the partner-management-service - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --build-arg SOURCE=mosip --build-arg COMMIT_HASH=$(git rev-parse HEAD) --build-arg COMMIT_ID=$(git rev-parse --short HEAD) --build-arg BUILD_TIME=${{steps.date.outputs.date}} --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - if [[ $BRANCH_NAME == master ]]; then - VERSION=latest - else - VERSION=$BRANCH_NAME - fi - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,workflow,job # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVOPS_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - sonar_analysis: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd partner - mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Analyze with SonarCloud - run: | - cd partner - mvn -B -Dgpg.skip verify sonar:sonar -Dsonar.projectKey=mosip_${{ github.event.repository.name }} -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - - diff --git a/.github/workflows/release-changes.yml b/.github/workflows/release-changes.yml new file mode 100644 index 0000000000..2579ea836f --- /dev/null +++ b/.github/workflows/release-changes.yml @@ -0,0 +1,26 @@ +name: Release/pre-release Preparation. + +on: + workflow_dispatch: + inputs: + MESSAGE: + description: 'Triggered for release or pe-release' + required: false + default: 'Release Preparation' + RELEASE_TAG: + description: 'tag to update' + required: true + SNAPSHOT_TAG: + description: 'tag to be replaced' + required: true + BASE: + description: 'base branch for PR' + required: true +jobs: + maven-release-preparation: + uses: mosip/kattu/.github/workflows/release-changes.yml@master + with: + MESSAGE: ${{ inputs.MESSAGE }} + RELEASE_TAG: ${{ inputs.RELEASE_TAG }} + SNAPSHOT_TAG: ${{ inputs.SNAPSHOT_TAG }} + BASE: ${{ inputs.BASE }} \ No newline at end of file diff --git a/.github/workflows/release_changes.yml b/.github/workflows/release_changes.yml deleted file mode 100644 index cc9c2956d9..0000000000 --- a/.github/workflows/release_changes.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Release/pre-release Preparation. - -on: - workflow_dispatch: - inputs: - message: - description: 'Triggered for release or pe-release' - required: false - default: 'Release Preparation' - releaseTags: - description: 'tag to update' - required: true - snapshotTags: - description: 'tag to be replaced' - required: true - base: - description: 'base branch for PR' - required: true -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Mannualy changing the pom versions - run: find . -type f -name "*pom.xml" -print0 | xargs -0 sed -i "s/${{ github.event.inputs.snapshotTags }}/${{ github.event.inputs.releaseTags }}/g" - - - name: Updating the Release URL in POM - run: | - cd .github/workflows - sed -i 's/OSSRH_SNAPSHOT_URL/RELEASE_URL/g' push_trigger.yml - - - name: Updating libs-snapshot-local to libs-release local for artifactory URL's. - run: find . -type f -name "*Dockerfile" -print0 | xargs -0 sed -i "s/libs-snapshot-local/libs-release-local/g" - - - name: removing -DskipTests - run: find . -type f -name "*push_trigger.yml" -print0 | xargs -0 sed -i "s/"-DskipTests"//g" - -# - name: removing --Dgpg.skip -# run: find . -type f -name "*push_trigger.yml" -print0 | xargs -0 sed -i "s/"-Dgpg.skip"//g" - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.ACTION_PAT }} - commit-message: Updated Pom versions for release changes - title: Release changes - body: Automated PR for ${{ github.event.inputs.releaseTags }} release. - branch: release-branch - delete-branch: true - base: ${{ github.event.inputs.base }} diff --git a/.github/workflows/release_trigger.yml b/.github/workflows/release_trigger.yml deleted file mode 100644 index 16c505237f..0000000000 --- a/.github/workflows/release_trigger.yml +++ /dev/null @@ -1,209 +0,0 @@ -name: Release maven packages and docker upon a release - -on: - release: - types: [published] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd partner - mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - - publish_to_nexus: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false " > $GITHUB_WORKSPACE/settings.xml - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - - name: Build with Maven - run: cd partner && mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml - - - name: Publish the maven package - run: | - chmod +x ./deploy.sh - ./deploy.sh partner $GITHUB_WORKSPACE/settings.xml .* - env: - GPG_TTY: $(tty) - - docker-policy-management-service: - needs: build - - runs-on: ubuntu-latest - env: - NAMESPACE: mosipdev - SERVICE_NAME: policy-management-service - SERVICE_LOCATION: partner/policy-management-service - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the policy-management-service - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - VERSION=$BRANCH_NAME - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - docker-partner-management-service: - needs: build - - runs-on: ubuntu-latest - env: - NAMESPACE: mosipdev - SERVICE_NAME: partner-management-service - SERVICE_LOCATION: partner/partner-management-service - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the partner-management-service - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - VERSION=$BRANCH_NAME - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION \ No newline at end of file diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000000..c4939a6e8c --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,33 @@ +name: Tagging of repos + +on: + workflow_dispatch: + inputs: + TAG: + description: 'Tag to be published' + required: true + type: string + BODY: + description: 'Release body message' + required: true + default: 'Changes in this Release' + type: string + PRE_RELEASE: + description: 'Pre-release? True/False' + required: true + default: False + type: string + DRAFT: + description: 'Draft? True/False' + required: false + default: False + type: string + +jobs: + tag-branch: + uses: mosip/kattu/.github/workflows/tag.yml@master + with: + TAG: ${{ inputs.TAG }} + BODY: ${{ inputs.BODY }} + PRE_RELEASE: ${{ inputs.PRE_RELEASE }} + DRAFT: ${{ inputs.DRAFT }} From 3106a98bc7d6a93be3adc623a46cb126d8259724 Mon Sep 17 00:00:00 2001 From: bhumi46 <111699703+bhumi46@users.noreply.github.com> Date: Mon, 25 Sep 2023 20:18:34 +0530 Subject: [PATCH 09/15] [MOSIP-29256] updated reusable worklows (#603) * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows * [MOSIP-29256] updated reusable worklows --- .github/workflows/release-changes.yml | 5 ++++- .github/workflows/tag.yml | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-changes.yml b/.github/workflows/release-changes.yml index 2579ea836f..783d4896a2 100644 --- a/.github/workflows/release-changes.yml +++ b/.github/workflows/release-changes.yml @@ -23,4 +23,7 @@ jobs: MESSAGE: ${{ inputs.MESSAGE }} RELEASE_TAG: ${{ inputs.RELEASE_TAG }} SNAPSHOT_TAG: ${{ inputs.SNAPSHOT_TAG }} - BASE: ${{ inputs.BASE }} \ No newline at end of file + BASE: ${{ inputs.BASE }} + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + ACTION_PAT: ${{ secrets.ACTION_PAT }} \ No newline at end of file diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index c4939a6e8c..c131f5aa9b 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -31,3 +31,5 @@ jobs: BODY: ${{ inputs.BODY }} PRE_RELEASE: ${{ inputs.PRE_RELEASE }} DRAFT: ${{ inputs.DRAFT }} + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} From 7a696df45eaf78ba5e420b20575549d084f15498 Mon Sep 17 00:00:00 2001 From: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:27:51 +0530 Subject: [PATCH 10/15] [MOSIP-29600]Update PartnerManagementServiceImpl.java (#605) * [MOSIP-29600]Update PartnerManagementServiceImpl.java Signed-off-by: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> * Update PartnerManagementServiceImplTest.java * Update AuthPolicyRepository.java * Update PolicyManagementService.java * Update PolicyServiceTest.java * Update PartnerServiceImplTest.java * Update PartnerManagementServiceImplTest.java * Update PartnerManagementServiceImpl.java * Update PartnerServiceImpl.java --------- Signed-off-by: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> --- .../impl/PartnerManagementServiceImpl.java | 24 +++++------ .../service/impl/PartnerServiceImpl.java | 2 +- .../PartnerManagementServiceImplTest.java | 40 +++++++++---------- .../service/impl/PartnerServiceImplTest.java | 14 +++---- .../repository/AuthPolicyRepository.java | 2 +- .../service/PolicyManagementService.java | 6 +-- .../test/service/PolicyServiceTest.java | 22 +++++----- 7 files changed, 54 insertions(+), 56 deletions(-) diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java index 67c3f9ad9b..2bcb22b33d 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java @@ -583,7 +583,18 @@ public APIKeyGenerateResponseDto generateAPIKey(String partnerId, APIKeyGenerate throw new PartnerManagerServiceException(ErrorCode.LOGGEDIN_USER_NOT_AUTHORIZED.getErrorCode(), ErrorCode.LOGGEDIN_USER_NOT_AUTHORIZED.getErrorMessage()); } - AuthPolicy validPolicy = authPolicyRepository.findByPolicyName(requestDto.getPolicyName()); + Optional partnerFromDb = partnerRepository.findById(partnerId); + if (partnerFromDb.isEmpty()) { + auditUtil.setAuditRequestDto(PartnerManageEnum.GENERATE_API_KEY_FAILURE, partnerId, "partnerId"); + throw new PartnerManagerServiceException(ErrorCode.PARTNER_ID_DOES_NOT_EXIST_EXCEPTION.getErrorCode(), + ErrorCode.PARTNER_ID_DOES_NOT_EXIST_EXCEPTION.getErrorMessage()); + } + if (!partnerFromDb.get().getIsActive()) { + auditUtil.setAuditRequestDto(PartnerManageEnum.GENERATE_API_KEY_FAILURE, partnerId, "partnerId"); + throw new PartnerManagerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), + ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); + } + AuthPolicy validPolicy = authPolicyRepository.findByPolicyGroupIdAndName(partnerFromDb.get().getPolicyGroupId(),requestDto.getPolicyName()); if(validPolicy == null) { auditUtil.setAuditRequestDto(PartnerManageEnum.GENERATE_API_KEY_FAILURE, partnerId, "partnerId"); throw new PartnerManagerServiceException(ErrorCode.POLICY_NOT_EXIST_EXCEPTION.getErrorCode(), @@ -597,17 +608,6 @@ public APIKeyGenerateResponseDto generateAPIKey(String partnerId, APIKeyGenerate throw new PartnerManagerServiceException(ErrorCode.PARTNER_POLICY_MAPPING_NOT_EXISTS.getErrorCode(), ErrorCode.PARTNER_POLICY_MAPPING_NOT_EXISTS.getErrorMessage()); } - Optional partnerFromDb = partnerRepository.findById(partnerId); - if (partnerFromDb.isEmpty()) { - auditUtil.setAuditRequestDto(PartnerManageEnum.GENERATE_API_KEY_FAILURE, partnerId, "partnerId"); - throw new PartnerManagerServiceException(ErrorCode.PARTNER_ID_DOES_NOT_EXIST_EXCEPTION.getErrorCode(), - ErrorCode.PARTNER_ID_DOES_NOT_EXIST_EXCEPTION.getErrorMessage()); - } - if (!partnerFromDb.get().getIsActive()) { - auditUtil.setAuditRequestDto(PartnerManageEnum.GENERATE_API_KEY_FAILURE, partnerId, "partnerId"); - throw new PartnerManagerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), - ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); - } PartnerPolicy policyByLabel = partnerPolicyRepository.findByPartnerIdPolicyIdAndLabel( partnerFromDb.get().getId(), validPolicy.getId(), requestDto.getLabel()); if(policyByLabel != null) { diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java index 78feaf5f24..562583d6e9 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java @@ -518,7 +518,7 @@ public PartnerResponse updatePartnerDetails(PartnerUpdateDto partnerUpdateReques } private AuthPolicy validatePolicyGroupAndPolicy(String policyGroupId, String policyName) { - AuthPolicy authPolicyFromDb = authPolicyRepository.findByPolicyGroupAndName(policyGroupId, policyName); + AuthPolicy authPolicyFromDb = authPolicyRepository.findByPolicyGroupIdAndName(policyGroupId, policyName); if (authPolicyFromDb == null) { auditUtil.setAuditRequestDto(PartnerServiceAuditEnum.SUBMIT_API_REQUEST_FAILURE, policyName, "policyName"); throw new PartnerServiceException(ErrorCode.POLICY_GROUP_POLICY_NOT_EXISTS.getErrorCode(), diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerManagementServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerManagementServiceImplTest.java index 40b26308dc..671e76e244 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerManagementServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerManagementServiceImplTest.java @@ -948,10 +948,11 @@ public void approveRejectPartnerPolicyMappingTest05() { public void generateAPIKeyTest() { APIKeyGenerateRequestDto request = new APIKeyGenerateRequestDto(); request.setLabel("unique"); - request.setPolicyName("policyName"); - Mockito.when(authPolicyRepository.findByPolicyName(request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); + request.setPolicyName("policyName"); + Optional newPartner = Optional.of(getPartner()); + Mockito.when(partnerRepository.findById("partner")).thenReturn(newPartner); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName(newPartner.get().getPolicyGroupId(),request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); Mockito.when((partnerPolicyRequestRepository.findByPartnerIdAndPolicyIdAndStatusCode(Mockito.any(),Mockito.any(),Mockito.any()))).thenReturn(List.of(getPartnerPolicyRequestData())); - Mockito.when(partnerRepository.findById("partner")).thenReturn(Optional.of(getPartner())); Mockito.when(partnerPolicyRepository.findByPartnerIdPolicyIdAndLabel("partner","234","unique")).thenReturn(getPartnerPolicy()); Map response = new HashMap<>(); response.put("response", getCertResponse()); @@ -964,39 +965,36 @@ public void generateAPIKeyTest() { }catch (PartnerManagerServiceException e) { assertTrue(e.getErrorCode().equals(ErrorCode.LOGGEDIN_USER_NOT_AUTHORIZED.getErrorCode())); } - - Mockito.when(authPolicyRepository.findByPolicyName(request.getPolicyName())).thenReturn(null); + Mockito.when(partnerRepository.findById("partner")).thenReturn(Optional.empty()); try { partnerManagementImpl.generateAPIKey("partner", request); }catch (PartnerManagerServiceException e) { - assertTrue(e.getErrorCode().equals(ErrorCode.POLICY_NOT_EXIST_EXCEPTION.getErrorCode())); + assertTrue(e.getErrorCode().equals(ErrorCode.PARTNER_ID_DOES_NOT_EXIST_EXCEPTION.getErrorCode())); } - Mockito.when(authPolicyRepository.findByPolicyName(request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); - Mockito.when((partnerPolicyRequestRepository.findByPartnerIdAndPolicyIdAndStatusCode(Mockito.any(),Mockito.any(),Mockito.any()))).thenReturn(Collections.emptyList()); + Optional partner = Optional.of(getPartner()); + partner.get().setIsActive(false); + Mockito.when(partnerRepository.findById("partner")).thenReturn(partner); try { partnerManagementImpl.generateAPIKey("partner", request); }catch (PartnerManagerServiceException e) { - assertTrue(e.getErrorCode().equals(ErrorCode.PARTNER_POLICY_MAPPING_NOT_EXISTS.getErrorCode())); + assertTrue(e.getErrorCode().equals(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode())); } - Mockito.when(authPolicyRepository.findByPolicyName(request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); - Mockito.when((partnerPolicyRequestRepository.findByPartnerIdAndPolicyIdAndStatusCode(Mockito.any(),Mockito.any(),Mockito.any()))).thenReturn(List.of(getPartnerPolicyRequestData())); - Mockito.when(partnerRepository.findById("partner")).thenReturn(Optional.empty()); + Mockito.when(partnerRepository.findById("partner")).thenReturn(newPartner); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName(request.getPolicyName(),newPartner.get().getPolicyGroupId())).thenReturn(null); try { partnerManagementImpl.generateAPIKey("partner", request); }catch (PartnerManagerServiceException e) { - assertTrue(e.getErrorCode().equals(ErrorCode.PARTNER_ID_DOES_NOT_EXIST_EXCEPTION.getErrorCode())); - } - Mockito.when(authPolicyRepository.findByPolicyName(request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); - Mockito.when((partnerPolicyRequestRepository.findByPartnerIdAndPolicyIdAndStatusCode(Mockito.any(),Mockito.any(),Mockito.any()))).thenReturn(List.of(getPartnerPolicyRequestData())); - Optional partner = Optional.of(getPartner()); - partner.get().setIsActive(false); - Mockito.when(partnerRepository.findById("partner")).thenReturn(partner); + assertTrue(e.getErrorCode().equals(ErrorCode.POLICY_NOT_EXIST_EXCEPTION.getErrorCode())); + } + Mockito.when(partnerRepository.findById("partner")).thenReturn(newPartner); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName(newPartner.get().getPolicyGroupId(),request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); + Mockito.when((partnerPolicyRequestRepository.findByPartnerIdAndPolicyIdAndStatusCode(Mockito.any(),Mockito.any(),Mockito.any()))).thenReturn(Collections.emptyList()); try { partnerManagementImpl.generateAPIKey("partner", request); }catch (PartnerManagerServiceException e) { - assertTrue(e.getErrorCode().equals(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode())); + assertTrue(e.getErrorCode().equals(ErrorCode.PARTNER_POLICY_MAPPING_NOT_EXISTS.getErrorCode())); } - Mockito.when(authPolicyRepository.findByPolicyName(request.getPolicyName())).thenReturn(getAuthPolicies().get(0)); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName(request.getPolicyName(),newPartner.get().getPolicyGroupId())).thenReturn(getAuthPolicies().get(0)); Mockito.when((partnerPolicyRequestRepository.findByPartnerIdAndPolicyIdAndStatusCode(Mockito.any(),Mockito.any(),Mockito.any()))).thenReturn(List.of(getPartnerPolicyRequestData())); Mockito.when(partnerRepository.findById("partner")).thenReturn(Optional.of(getPartner())); Mockito.when(partnerPolicyRepository.findByPartnerIdPolicyIdAndLabel("123456","234","unique")).thenReturn(getPartnerPolicy()); diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java index e67bbb27d5..65f8edc990 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java @@ -789,7 +789,7 @@ public void mapPartnerPolicyCredentialType_001() { Mockito.when(partnerRepository.findById("12345")).thenReturn(partner); Mockito.when(authPolicyRepository.findById("12345")).thenReturn(Optional.of(createAuthPolicy())); Mockito.when(authPolicyRepository - .findByPolicyGroupAndName(Mockito.anyString(), Mockito.anyString())).thenReturn(createAuthPolicy()); + .findByPolicyGroupIdAndName(Mockito.anyString(), Mockito.anyString())).thenReturn(createAuthPolicy()); pserviceImpl.mapPartnerPolicyCredentialType("euin", "12345", "12345"); } @@ -879,7 +879,7 @@ public void requestForPolicyMappingTest() { Optional partner = Optional.of(createPartner(true)); partner.get().setPartnerTypeCode("Auth_Partner"); Mockito.when(partnerRepository.findById("12345")).thenReturn(partner); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","policyName")).thenReturn(createAuthPolicy()); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","policyName")).thenReturn(createAuthPolicy()); Mockito.when(partnerPolicyRequestRepository.findByPartnerIdAndPolicyId("12345","123")).thenReturn(List.of(createPartnerPolicyRequest("approved"))); pserviceImpl.requestForPolicyMapping(request, "12345"); partner.get().setPolicyGroupId(null); @@ -921,7 +921,7 @@ public void requestForPolicyMappingTest() { } partner.get().setIsActive(true); Mockito.when(partnerRepository.findById("12345")).thenReturn(partner); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","policyName")).thenReturn(null); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","policyName")).thenReturn(null); try { pserviceImpl.requestForPolicyMapping(request, "12345"); }catch (PartnerServiceException e) { @@ -929,7 +929,7 @@ public void requestForPolicyMappingTest() { } AuthPolicy authPolicy = createAuthPolicy(); authPolicy.setIsActive(false); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","policyName")).thenReturn(authPolicy); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","policyName")).thenReturn(authPolicy); try { pserviceImpl.requestForPolicyMapping(request, "12345"); }catch (PartnerServiceException e) { @@ -938,7 +938,7 @@ public void requestForPolicyMappingTest() { authPolicy = createAuthPolicy(); authPolicy.setIsActive(true); authPolicy.setValidToDate(LocalDateTime.now().minusMonths(3)); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","policyName")).thenReturn(authPolicy); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","policyName")).thenReturn(authPolicy); try { pserviceImpl.requestForPolicyMapping(request, "12345"); }catch (PartnerServiceException e) { @@ -947,7 +947,7 @@ public void requestForPolicyMappingTest() { authPolicy = createAuthPolicy(); authPolicy.setIsActive(true); authPolicy.getPolicyGroup().setIsActive(false); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","policyName")).thenReturn(authPolicy); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","policyName")).thenReturn(authPolicy); try { pserviceImpl.requestForPolicyMapping(request, "12345"); }catch (PartnerServiceException e) { @@ -1264,4 +1264,4 @@ private String caCertResponse() { } -} \ No newline at end of file +} diff --git a/partner/pms-common/src/main/java/io/mosip/pms/common/repository/AuthPolicyRepository.java b/partner/pms-common/src/main/java/io/mosip/pms/common/repository/AuthPolicyRepository.java index 65344ae87b..1447139201 100644 --- a/partner/pms-common/src/main/java/io/mosip/pms/common/repository/AuthPolicyRepository.java +++ b/partner/pms-common/src/main/java/io/mosip/pms/common/repository/AuthPolicyRepository.java @@ -13,7 +13,7 @@ public interface AuthPolicyRepository extends JpaRepository{ @Query(value = "select * from auth_policy ap where ap.policy_group_id=?1 and ap.name = ?2",nativeQuery = true) - AuthPolicy findByPolicyGroupAndName(String policyGroupId, String name); + AuthPolicy findByPolicyGroupIdAndName(String policyGroupId, String name); @Query(value = "select * from auth_policy ap where ap.policy_group_id=?1 and ap.id = ?2",nativeQuery = true) AuthPolicy findByPolicyGroupAndId(String policyGroupId, String policyId); diff --git a/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java b/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java index aac9f31e14..95ab0c591c 100644 --- a/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java +++ b/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java @@ -294,7 +294,7 @@ public PolicyCreateResponseDto updatePolicies(PolicyUpdateRequestDto requestDto, throw new PolicyManagementServiceException(ErrorMessages.PUBLISHED_POLICY_NOT_UPDATED.getErrorCode(), ErrorMessages.PUBLISHED_POLICY_NOT_UPDATED.getErrorMessage()); } - AuthPolicy mappedPolicy = authPolicyRepository.findByPolicyGroupAndName(policyGroup.getId(), + AuthPolicy mappedPolicy = authPolicyRepository.findByPolicyGroupIdAndName(policyGroup.getId(), requestDto.getName()); if (mappedPolicy != null && !mappedPolicy.getName().equals(authPolicy.getName())) { auditUtil.setAuditRequestDto(PolicyManageEnum.UPDATE_POLICY_FAILURE, requestDto.getName(), "policyName"); @@ -354,7 +354,7 @@ private PolicyGroupCreateResponseDto savePolicyGroup(PolicyGroup policyGroup) { * @return */ private void validateAuthPolicyName(String policyGroupId, String auth_policy_name) { - AuthPolicy auth_policy_by_name = authPolicyRepository.findByPolicyGroupAndName(policyGroupId, auth_policy_name); + AuthPolicy auth_policy_by_name = authPolicyRepository.findByPolicyGroupIdAndName(policyGroupId, auth_policy_name); if (auth_policy_by_name != null) { auditUtil.setAuditRequestDto(PolicyManageEnum.CREATE_POLICY_FAILURE, auth_policy_name, "policyName"); throw new PolicyManagementServiceException( @@ -445,7 +445,7 @@ private PolicyResponseDto mapPolicyAndPolicyGroup(AuthPolicy authPolicy) private PolicyCreateResponseDto savePolicy(JSONObject policyJson, String oldPolicyName, String newPolicyName, String policyDesc, String policyGroupId, String policyType, String policyGroupName, String version, String authPolicyId) throws PolicyManagementServiceException, Exception { - AuthPolicy authPolicy = authPolicyRepository.findByPolicyGroupAndName(policyGroupId, oldPolicyName); + AuthPolicy authPolicy = authPolicyRepository.findByPolicyGroupIdAndName(policyGroupId, oldPolicyName); if (authPolicy != null) { authPolicy.setId(authPolicy.getId()); authPolicy.setDescr(policyDesc); diff --git a/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/service/PolicyServiceTest.java b/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/service/PolicyServiceTest.java index 30155ea3c9..a2456cec2a 100644 --- a/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/service/PolicyServiceTest.java +++ b/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/service/PolicyServiceTest.java @@ -338,7 +338,7 @@ public void createPoliciesTest_S004() throws PolicyManagementServiceException, E PolicyCreateRequestDto request = createPoliciesRequest(); request.setPolicyType("Data_Share"); Mockito.when(policyGroupRepository.findByName("Test_Policy_Group_001")).thenReturn(policyGroupData()); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","Test_001")).thenReturn(getAuthPolicy()); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","Test_001")).thenReturn(getAuthPolicy()); service.createPolicies(request); } @@ -376,7 +376,7 @@ public void createPoliciesTest_S007() throws PolicyManagementServiceException, E Mockito.when(mapper.readValue(new URL("http://localhost:8999/schema"), JsonNode.class)).thenReturn(actualObj); Mockito.when(policyGroupRepository.findByName("Test_Policy_Group_001")).thenReturn(policyGroupData()); Mockito.when(authPolicyRepository.findByName("Test")).thenReturn(getAuthPolicy()); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345","Test")).thenReturn(getAuthPolicy()); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345","Test")).thenReturn(getAuthPolicy()); try { service.createPolicies(request); }catch (PolicyManagementServiceException e) { @@ -571,7 +571,7 @@ public void updatePolicies_PolicyNameDuplicateTest() throws PolicyManagementServ AuthPolicy authPolicyName = getAuthPolicy(); authPolicyName.getPolicyGroup().setId("12345"); authPolicyName.setName("Test_01"); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(authPolicyName); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(authPolicyName); service.updatePolicies(request, "12345"); } @@ -597,7 +597,7 @@ public void updatePolicies_Test_01() throws PolicyManagementServiceException, Ex AuthPolicy authPolicyName = getAuthPolicy(); authPolicyName.getPolicyGroup().setId("12345"); authPolicyName.setName("Test_01"); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(authPolicyName); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(authPolicyName); service.updatePolicies(request, "12345"); } @@ -625,7 +625,7 @@ public void updatePolicies_Test_02() throws PolicyManagementServiceException, Ex authPolicyName.setPolicySchema("localhost"); authPolicyName.getPolicyGroup().setId("12345"); authPolicyName.setName("Test_01"); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(authPolicyName); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(authPolicyName); service.updatePolicies(request, "12345"); } @@ -654,7 +654,7 @@ public void updatePolicies_Test_03() throws PolicyManagementServiceException, Ex authPolicyName.getPolicyGroup().setId("12345"); authPolicyName.setName("Test_01"); authPolicyName.setPolicy_type("Auth"); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(authPolicyName); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(authPolicyName); ObjectMapper objectMapper = new ObjectMapper(); JsonNode actualObj = objectMapper.readTree(authPolicySchema); Mockito.when(mapper.readValue(new URL("http://localhost:8999/schema"), JsonNode.class)).thenReturn(actualObj); @@ -686,7 +686,7 @@ public void updatePolicies_Test_04() throws PolicyManagementServiceException, Ex authPolicyName.getPolicyGroup().setId("12345"); authPolicyName.setName("Test_01"); authPolicyName.setPolicy_type("Auth"); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test_01")).thenReturn(authPolicyName); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test_01")).thenReturn(authPolicyName); ObjectMapper objectMapper = new ObjectMapper(); JsonNode actualObj = objectMapper.readTree(authPolicySchema); Mockito.when(mapper.readValue(new URL("http://localhost:8999/schema"), JsonNode.class)).thenReturn(actualObj); @@ -738,7 +738,7 @@ public void publishPolicy_PolicyPublishedTest() throws JsonParseException, JsonM Mockito.when(authPolicyRepository.findByName("Test")).thenReturn(authPolicy); Optional policy = Optional.of(policyGroup); Mockito.when(policyGroupRepository.findByName("Test")).thenReturn(policy.get()); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(getAuthPolicy()); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(getAuthPolicy()); service.publishPolicy("Test", "Test"); } @@ -762,7 +762,7 @@ public void publishPolicyTest() throws JsonParseException, JsonMappingException, Mockito.when(authPolicyRepository.findById("Test")).thenReturn(Optional.of(authPolicy)); Optional policy = Optional.of(policyGroup); Mockito.when(policyGroupRepository.findById("Test")).thenReturn(policy); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(getAuthPolicy()); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(getAuthPolicy()); Mockito.when(policyGroupRepository.findById("12345")).thenReturn(policy); service.publishPolicy("Test", "Test"); } @@ -788,7 +788,7 @@ public void publishPolicyTest_02() throws JsonParseException, JsonMappingExcepti Mockito.when(authPolicyRepository.findById("Test")).thenReturn(Optional.of(authPolicy)); Optional policy = Optional.of(policyGroup); Mockito.when(policyGroupRepository.findById("Test")).thenReturn(policy); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(getAuthPolicy()); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(getAuthPolicy()); Mockito.when(policyGroupRepository.findById("12345")).thenReturn(policy); try { service.publishPolicy("Test", "Test"); @@ -821,7 +821,7 @@ public void publishPolicyTest_01() throws JsonParseException, JsonMappingExcepti AuthPolicy authPolicy01 = getAuthPolicy(); authPolicy01.setIsActive(false); authPolicy01.setPolicySchema("localhost"); - Mockito.when(authPolicyRepository.findByPolicyGroupAndName("12345", "Test")).thenReturn(authPolicy01); + Mockito.when(authPolicyRepository.findByPolicyGroupIdAndName("12345", "Test")).thenReturn(authPolicy01); Mockito.when(policyGroupRepository.findById("12345")).thenReturn(policy); service.publishPolicy("Test", "Test"); } From 5b9bb12fb055a85ab21e344c6c9e4c3600aae358 Mon Sep 17 00:00:00 2001 From: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:16:16 +0530 Subject: [PATCH 11/15] [DSD-3823]Update pms-partner_policy_bioextract.csv Signed-off-by: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> --- .../dml/pms-partner_policy_bioextract.csv | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) 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() From 1db249c24911ff28727dbb00c5b5a8441e1ae86a Mon Sep 17 00:00:00 2001 From: Rakshithb1 <79500257+Rakshithb1@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:20:30 +0530 Subject: [PATCH 12/15] [MOSIP-29918] added db-test.yml (#612) Signed-off-by: Rakshithb1 --- .github/workflows/db-test.yml | 39 ++++++++++++++++++++++++++++++++++ db_scripts/mosip_pms/deploy.sh | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/db-test.yml diff --git a/.github/workflows/db-test.yml b/.github/workflows/db-test.yml new file mode 100644 index 0000000000..430c25da0d --- /dev/null +++ b/.github/workflows/db-test.yml @@ -0,0 +1,39 @@ +name: PostgreSQL Test + +on: + release: + types: [published] + pull_request: + types: [opened, reopened, synchronize] + paths: + - 'db_scripts/**' + 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/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" From 9690a8aa0485ba4e62ecf8504297eabe473383ea Mon Sep 17 00:00:00 2001 From: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:56:21 +0530 Subject: [PATCH 13/15] Update pms-partner_type.csv Signed-off-by: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com> --- db_scripts/mosip_pms/dml/pms-partner_type.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 5496488d6f076b8f4e18fad4555d6cf1d1b11c50 Mon Sep 17 00:00:00 2001 From: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> Date: Mon, 25 Dec 2023 21:31:47 +0530 Subject: [PATCH 14/15] [MOSIP-29961] Updated push-trigger.yml (#621) * [MOSIP-29961] removed paths from db-test.yml Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> * [MOSIP-29961] Updated push-trigger.yml Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> --------- Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> --- .github/workflows/db-test.yml | 2 -- .github/workflows/push-trigger.yml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/db-test.yml b/.github/workflows/db-test.yml index 430c25da0d..c3ed7de2b3 100644 --- a/.github/workflows/db-test.yml +++ b/.github/workflows/db-test.yml @@ -5,8 +5,6 @@ on: types: [published] pull_request: types: [opened, reopened, synchronize] - paths: - - 'db_scripts/**' workflow_dispatch: inputs: message: diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index db27b6a745..c429dcc3d4 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: @@ -85,4 +85,4 @@ 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 }} From 3dc3bb918a0fdd0b85cb93ab9ff05005936cbb72 Mon Sep 17 00:00:00 2001 From: PRAFUL RAKHADE <99539100+Prafulrakhade@users.noreply.github.com> Date: Mon, 25 Dec 2023 21:33:27 +0530 Subject: [PATCH 15/15] [DSD-3932] removed release-changes.yml, tag.yml and updated push-trigger.yml file (#618) Signed-off-by: techno-467 --- .github/workflows/push-trigger.yml | 2 +- .github/workflows/release-changes.yml | 29 ---------------------- .github/workflows/tag.yml | 35 --------------------------- 3 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 .github/workflows/release-changes.yml delete mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index c429dcc3d4..6e58022b18 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -35,7 +35,7 @@ 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: diff --git a/.github/workflows/release-changes.yml b/.github/workflows/release-changes.yml deleted file mode 100644 index 783d4896a2..0000000000 --- a/.github/workflows/release-changes.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Release/pre-release Preparation. - -on: - workflow_dispatch: - inputs: - MESSAGE: - description: 'Triggered for release or pe-release' - required: false - default: 'Release Preparation' - RELEASE_TAG: - description: 'tag to update' - required: true - SNAPSHOT_TAG: - description: 'tag to be replaced' - required: true - BASE: - description: 'base branch for PR' - required: true -jobs: - maven-release-preparation: - uses: mosip/kattu/.github/workflows/release-changes.yml@master - with: - MESSAGE: ${{ inputs.MESSAGE }} - RELEASE_TAG: ${{ inputs.RELEASE_TAG }} - SNAPSHOT_TAG: ${{ inputs.SNAPSHOT_TAG }} - BASE: ${{ inputs.BASE }} - secrets: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - ACTION_PAT: ${{ secrets.ACTION_PAT }} \ No newline at end of file diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml deleted file mode 100644 index c131f5aa9b..0000000000 --- a/.github/workflows/tag.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Tagging of repos - -on: - workflow_dispatch: - inputs: - TAG: - description: 'Tag to be published' - required: true - type: string - BODY: - description: 'Release body message' - required: true - default: 'Changes in this Release' - type: string - PRE_RELEASE: - description: 'Pre-release? True/False' - required: true - default: False - type: string - DRAFT: - description: 'Draft? True/False' - required: false - default: False - type: string - -jobs: - tag-branch: - uses: mosip/kattu/.github/workflows/tag.yml@master - with: - TAG: ${{ inputs.TAG }} - BODY: ${{ inputs.BODY }} - PRE_RELEASE: ${{ inputs.PRE_RELEASE }} - DRAFT: ${{ inputs.DRAFT }} - secrets: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}