From bd02db18c000defbeb4ec4ca6755fbcf1e4421f8 Mon Sep 17 00:00:00 2001 From: yashmsonkusare Date: Thu, 13 Apr 2023 11:21:22 +0530 Subject: [PATCH 1/4] Added revoke scripts for 1.2.0 Signed-off-by: Yash S <119652212+yashmsonkusare@users.noreply.github.com> --- db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql diff --git a/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql b/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql new file mode 100644 index 0000000000..93803a6a7d --- /dev/null +++ b/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql @@ -0,0 +1,14 @@ +-- ------------------------------------------------------------------------------------------------- +-- Database Name: mosip_pms +-- Release Version : 1.2.0 +-- ------------------------------------------------------------------------------------------------- + +\c mosip_pms sysadmin + +ALTER TABLE pms.device_detail DROP CONSTRAINT fk_devdtl_id; + +ALTER TABLE pms.reg_device_sub_type DROP CONSTRAINT fk_rdstyp_dtype_code; + +ALTER TABLE pms.partner DROP COLUMN lang_code; + +ALTER TABLE pms.partner_h DROP COLUMN lang_code; \ No newline at end of file From 50dd6dac6b6cfbc5f49d739e46c4353ff18e902c Mon Sep 17 00:00:00 2001 From: Yash S <119652212+yashmsonkusare@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:44:51 +0530 Subject: [PATCH 2/4] Updated 1.2.0_revoke.sql Signed-off-by: Yash S <119652212+yashmsonkusare@users.noreply.github.com> --- .../mosip_pms/sql/1.2.0_revoke.sql | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql b/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql index 93803a6a7d..c3b2632474 100644 --- a/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql +++ b/db_release_scripts/mosip_pms/sql/1.2.0_revoke.sql @@ -1,7 +1,12 @@ -- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_pms --- Release Version : 1.2.0 --- ------------------------------------------------------------------------------------------------- +-- Database Name : mosip_pms +-- Release Version : 1.2.0 +-- Purpose : Revoking Database Alter deployement done for release in PMS DB. +-- Create By : Yash Mohan +-- Created Date : Apr-2023 +-- +-- Modified Date Modified By Comments / Remarks +-- -------------------------------------------------------------------------------------------------- \c mosip_pms sysadmin @@ -9,6 +14,10 @@ ALTER TABLE pms.device_detail DROP CONSTRAINT fk_devdtl_id; ALTER TABLE pms.reg_device_sub_type DROP CONSTRAINT fk_rdstyp_dtype_code; +ALTER TABLE pms.partner_policy DROP COLUMN label; + ALTER TABLE pms.partner DROP COLUMN lang_code; -ALTER TABLE pms.partner_h DROP COLUMN lang_code; \ No newline at end of file +ALTER TABLE pms.partner_h DROP COLUMN lang_code; + +ALTER TABLE pms.ftp_chip_detail DROP COLUMN approval_status; From 85626f12c4e1289a77da9b9638eacb2734ee71a1 Mon Sep 17 00:00:00 2001 From: yashmsonkusare Date: Thu, 10 Aug 2023 17:30:11 +0530 Subject: [PATCH 3/4] MOSIP-28900:Asdded the test cases for PolicyManagementController Signed-off-by: Yash S <119652212+yashmsonkusare@users.noreply.github.com> --- .../PolicyManagementControllerTest.java | 324 +++++++++++++++++- 1 file changed, 306 insertions(+), 18 deletions(-) diff --git a/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java b/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java index 9472971dbb..6072d8d983 100644 --- a/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java +++ b/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java @@ -1,18 +1,32 @@ package io.mosip.pms.policy.test.controller; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.text.ParseException; +import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import io.mosip.pms.policy.controller.PolicyManagementController; +import io.mosip.pms.policy.dto.*; +import io.mosip.pms.policy.errorMessages.ServiceError; +import org.jose4j.json.JsonUtil; import org.json.simple.JSONObject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -42,25 +56,11 @@ import io.mosip.pms.common.dto.SearchSort; import io.mosip.pms.common.entity.PolicyGroup; import io.mosip.pms.common.validator.FilterColumnValidator; -import io.mosip.pms.policy.dto.FilterResponseCodeDto; -import io.mosip.pms.policy.dto.PolicyCreateRequestDto; -import io.mosip.pms.policy.dto.PolicyCreateResponseDto; -import io.mosip.pms.policy.dto.PolicyDetailsDto; -import io.mosip.pms.policy.dto.PolicyGroupCreateRequestDto; -import io.mosip.pms.policy.dto.PolicyGroupCreateResponseDto; -import io.mosip.pms.policy.dto.PolicyGroupUpdateRequestDto; -import io.mosip.pms.policy.dto.PolicyResponseDto; -import io.mosip.pms.policy.dto.PolicyStatusUpdateRequestDto; -import io.mosip.pms.policy.dto.PolicyStatusUpdateResponseDto; -import io.mosip.pms.policy.dto.PolicyUpdateRequestDto; -import io.mosip.pms.policy.dto.PolicyWithAuthPolicyDto; -import io.mosip.pms.policy.dto.RequestWrapper; -import io.mosip.pms.policy.dto.ResponseWrapper; import io.mosip.pms.policy.errorMessages.PolicyManagementServiceException; import io.mosip.pms.policy.service.PolicyManagementService; import io.mosip.pms.policy.test.PolicyServiceTest; import io.mosip.pms.policy.util.AuditUtil; - +import org.mockito.Mockito; /** * @author Nagarjuna Kuchi @@ -76,7 +76,7 @@ public class PolicyManagementControllerTest { @Autowired private MockMvc mockMvc; - @MockBean + @Mock private PolicyManagementService policyManagementService; @Autowired @@ -85,9 +85,10 @@ public class PolicyManagementControllerTest { @Mock FilterColumnValidator filterColumnValidator; - @MockBean + @Mock private AuditUtil audit; - + @InjectMocks + PolicyManagementController policyManagementController; FilterDto filterDto = new FilterDto(); SearchFilter searchFilter = new SearchFilter(); @@ -522,5 +523,292 @@ private PolicyFilterValueDto createPolicyFilterRequest() { policyFilterValueDto.setFilters(filterDtos); return policyFilterValueDto; } + @Test + public void definePolicyGroupTest001(){ + PolicyGroupCreateRequestDto createRequestDto = new PolicyGroupCreateRequestDto(); + createRequestDto.setName("Name"); + createRequestDto.setDesc("desc"); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setId("id"); + requestWrapper.setVersion("1.2.0"); + requestWrapper.setMetadata("metadata"); + requestWrapper.setRequesttime(LocalDateTime.now()); + requestWrapper.setRequest(createRequestDto); + PolicyGroupCreateResponseDto mockedResponseDto = new PolicyGroupCreateResponseDto(); + Mockito.when(policyManagementService.createPolicyGroup(createRequestDto)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.definePolicyGroup(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.CREATE_POLICY_GROUP, createRequestDto.getName(), "policyGroupName"); + } + @Test + public void testSearchPolicyGroup() { + SearchDto searchDto = new SearchDto(); + List filters=new ArrayList<>(); + SearchFilter searchFilter1=new SearchFilter(); + searchFilter1.setFromValue("fvalue"); + searchFilter1.setValue("value"); + searchFilter1.setColumnName("cname"); + searchFilter1.setToValue("to value"); + searchFilter1.setFromValue("from value"); + List values=new ArrayList<>(); + String s="Values"; + values.add(s); + searchFilter1.setValues(values); + searchFilter1.setType("type"); + filters.add(searchFilter1); + searchDto.setFilters(filters); + List sort=new ArrayList<>(); + SearchSort searchSort1=new SearchSort(); + searchSort1.setSortField("sortfield"); + searchSort1.setSortType("stype"); + sort.add(searchSort1); + searchDto.setSort(sort); + searchDto.setPagination(pagination); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setVersion("1.2.1"); + requestWrapper.setId("id"); + requestWrapper.setMetadata("metadata"); + requestWrapper.setRequest(searchDto); + PageResponseDto mockedPageResponseDto = new PageResponseDto<>(); + Mockito.when(policyManagementService.searchPolicyGroup(searchDto)).thenReturn(mockedPageResponseDto); + ResponseWrapper> response = policyManagementController.searchPolicyGroup(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedPageResponseDto, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.SEARCH_POLICY_GROUP); + } + @Test + public void testUpdatePolicyGroup() { + String policyGroupId = "policyGroupId"; + PolicyGroupUpdateRequestDto updateRequestDto = new PolicyGroupUpdateRequestDto(); + updateRequestDto.setDesc("desc"); + updateRequestDto.setName("name"); + updateRequestDto.setIsActive(true); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setId("id"); + requestWrapper.setVersion("1.2.0"); + requestWrapper.setMetadata("metadata"); + requestWrapper.setRequest(updateRequestDto); + PolicyGroupCreateResponseDto mockedResponseDto = new PolicyGroupCreateResponseDto(); + Mockito.when(policyManagementService.updatePolicyGroup(updateRequestDto, policyGroupId)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.updatePolicyGroup(policyGroupId, requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.UPDATE_POLICY_GROUP, updateRequestDto.getName(), "policyGroupName"); + } + @Test + public void testDefinePolicy() throws Exception { + PolicyCreateRequestDto createRequestDto = new PolicyCreateRequestDto(); + createRequestDto.setPolicyId("id"); + createRequestDto.setDesc("desc"); + createRequestDto.setPolicyType("ptype"); + createRequestDto.setPolicyGroupName("pgn"); + createRequestDto.setVersion("1.2.0"); + createRequestDto.setName("name"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "John Wick"); + jsonObject.put("age", 58); + jsonObject.put("email", "xyz@gmail.com"); + createRequestDto.setPolicies(jsonObject); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setMetadata("metadata"); + requestWrapper.setId("id"); + requestWrapper.setVersion("1.2.0"); + requestWrapper.setRequest(createRequestDto); + PolicyCreateResponseDto mockedResponseDto = new PolicyCreateResponseDto(); + Mockito.when(policyManagementService.createPolicies(createRequestDto)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.definePolicy(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.CREATE_POLICY, createRequestDto.getName(), "policyName"); + } + @Test + public void testPublishPolicy() throws JsonParseException, JsonMappingException, IOException { + String policygroupId = "policyGroupId"; + String policyId = "policyId"; + PolicyResponseDto mockedResponseDto = new PolicyResponseDto(); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setVersion("1.2.0"); + requestWrapper.setId("id"); + requestWrapper.setMetadata("metadata"); + Mockito.when(policyManagementService.publishPolicy(policygroupId, policyId)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.publishPolicy(policygroupId, policyId); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.PUBLISH_POLICY, policyId, "policyId"); + } + @Test + public void testUpdatePolicyDetails() throws Exception { + String policyId = "policyId"; + PolicyUpdateRequestDto updateRequestDto = new PolicyUpdateRequestDto(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "Joey Tribbiani"); + jsonObject.put("age", 28); + jsonObject.put("email", "Joey@gmail.com"); + updateRequestDto.setPolicies(jsonObject); + updateRequestDto.setVersion("1.12.2"); + updateRequestDto.setPolicyGroupName("pgname"); + updateRequestDto.setDesc("desc"); + updateRequestDto.setName("name"); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setMetadata("metadata"); + requestWrapper.setVersion("1.12.2"); + requestWrapper.setId("id"); + requestWrapper.setRequest(updateRequestDto); + ResponseWrapper response = policyManagementController.updatePolicyDetails(requestWrapper, policyId); + assertNotNull(response); + } + @Test + public void testUpdatePolicyStatus() throws Exception { + PolicyStatusUpdateRequestDto statusUpdateRequest = new PolicyStatusUpdateRequestDto(); + statusUpdateRequest.setStatus("active"); + RequestWrapper requestDto = new RequestWrapper<>(); + requestDto.setId("id"); + requestDto.setVersion("1.2.3"); + requestDto.setMetadata("metadata"); + requestDto.setRequest(statusUpdateRequest); + } + @Test + public void testGetPolicies() throws FileNotFoundException, IOException, ParseException, ParseException, org.json.simple.parser.ParseException { + List mockedResponseList = new ArrayList<>(); + Mockito.when(policyManagementService.findAllPolicies()).thenReturn(mockedResponseList); + ResponseWrapper> response = policyManagementController.getPolicies(); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseList, response.getResponse()); + } + @Test + public void testGetPolicy() throws Exception { + String policyId = "policyId"; + PolicyResponseDto mockedResponseDto = new PolicyResponseDto(); + Mockito.when(policyManagementService.findPolicy(policyId)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.getPolicy(policyId); + response.setVersion("version"); + response.setId("id"); + List errors = new ArrayList<>(); + response.setErrors(errors); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + } + @Test + public void testGetPolicyGroup001() throws JsonParseException, JsonMappingException, IOException { + String policygroupId = "policygroupId"; + PolicyWithAuthPolicyDto mockedResponseDto = new PolicyWithAuthPolicyDto(); + Mockito.when(policyManagementService.getPolicyGroupPolicy(policygroupId)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.getPolicyGroup(policygroupId); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + } + @Test + public void testGetPolicyGroup() throws JsonParseException, JsonMappingException, IOException { + List mockedResponseList = new ArrayList<>(); + Mockito.when(policyManagementService.getPolicyGroup()).thenReturn(mockedResponseList); + ResponseWrapper> response = policyManagementController.getPolicyGroup(); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseList, response.getResponse()); + } + @Test + public void testSearchPolicyGroup001() { + SearchDto searchDto = new SearchDto(); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setRequest(searchDto); + PageResponseDto mockedResponse = new PageResponseDto<>(); + Mockito.when(policyManagementService.searchPolicyGroup(searchDto)).thenReturn(mockedResponse); + ResponseWrapper> response = policyManagementController.searchPolicyGroup(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponse, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.SEARCH_POLICY_GROUP); + } + @Test + public void testGetPartnersPolicy() throws JsonParseException, JsonMappingException, IOException { + String partnerId = "partnerId"; + String policyId = "policyId"; + PolicyResponseDto mockedResponseDto = new PolicyResponseDto(); + Mockito.when(policyManagementService.getPartnerMappedPolicy(partnerId, policyId)).thenReturn(mockedResponseDto); + ResponseWrapper response = policyManagementController.getPartnersPolicy(partnerId, policyId); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponseDto, response.getResponse()); + } + @Test + public void testSearchPolicy() { + PolicySearchDto policySearchDto = new PolicySearchDto(); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setRequest(policySearchDto); + PageResponseDto mockedResponse = new PageResponseDto<>(); + Mockito.when(policyManagementService.searchPolicy(policySearchDto)).thenReturn(mockedResponse); + ResponseWrapper> response = policyManagementController.searchPolicy(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponse, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.SEARCH_POLICY); + } + @Test + public void testGetValueForKey() { + String key = "configKey"; + KeyValuePair mockedResponse = new KeyValuePair<>("aaa",122); + Mockito.when(policyManagementService.getValueForKey(key)).thenReturn(mockedResponse); + ResponseWrapper> response = policyManagementController.getValueForKey(key); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponse, response.getResponse()); + } + @Test + public void testPolicyGroupFilterValues() { + FilterValueDto filterValueDto = new FilterValueDto(); + List optionalFilters=new ArrayList<>(); + filterValueDto.setOptionalFilters(optionalFilters); + List filters=new ArrayList<>(); + filterValueDto.setFilters(filters); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setRequest(filterValueDto); + FilterResponseCodeDto mockedResponse = new FilterResponseCodeDto(); + Mockito.when(policyManagementService.policyGroupFilterValues(filterValueDto)).thenReturn(mockedResponse); + ResponseWrapper response = policyManagementController.policyGroupFilterValues(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponse, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.FILTERVALUES_POLICY_GROUP); + } + @Test + public void testPolicyFilterValues() { + PolicyFilterValueDto policyFilterValueDto = new PolicyFilterValueDto(); + policyFilterValueDto.setPolicyType("ptype"); + List filters=new ArrayList<>(); + policyFilterValueDto.setFilters(filters); + List optionalFilters=new ArrayList<>(); + policyFilterValueDto.setOptionalFilters(optionalFilters); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setMetadata("metadata"); + requestWrapper.setId("id"); + requestWrapper.setVersion("1.2.2"); + requestWrapper.setRequest(policyFilterValueDto); + FilterResponseCodeDto mockedResponse = new FilterResponseCodeDto(); + Mockito.when(policyManagementService.policyFilterValues(policyFilterValueDto)).thenReturn(mockedResponse); + ResponseWrapper response = policyManagementController.policyFilterValues(requestWrapper); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponse, response.getResponse()); + verify(audit).setAuditRequestDto(PolicyManageEnum.FILTERVALUES_POLICY); + } + @Test + public void testGetPoliciesByGroupName() { + String groupName = "GroupName"; + List mockedResponse = new ArrayList<>(); + Mockito.when(policyManagementService.getActivePolicyDetailsByGroupName(groupName)).thenReturn(mockedResponse); + ResponseWrapper> response = policyManagementController.getPoliciesByGroupName(groupName); + assertNotNull(response); + assertNotNull(response.getResponse()); + assertEquals(mockedResponse, response.getResponse()); + } } From 9e0f866e10a4680b9fb5407acf86f4aa4ebfc164 Mon Sep 17 00:00:00 2001 From: Yash S <119652212+yashmsonkusare@users.noreply.github.com> Date: Tue, 23 Jan 2024 19:12:09 +0530 Subject: [PATCH 4/4] Fixed the test failures Signed-off-by: Yash S <119652212+yashmsonkusare@users.noreply.github.com> --- .../policy/test/controller/PolicyManagementControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java b/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java index 6072d8d983..77113157e8 100644 --- a/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java +++ b/partner/policy-management-service/src/test/java/io/mosip/pms/policy/test/controller/PolicyManagementControllerTest.java @@ -21,7 +21,6 @@ import io.mosip.pms.policy.controller.PolicyManagementController; import io.mosip.pms.policy.dto.*; import io.mosip.pms.policy.errorMessages.ServiceError; -import org.jose4j.json.JsonUtil; import org.json.simple.JSONObject; import org.junit.Before; import org.junit.Test;