-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #594 from yashmsonkusare/develop
MOSIP-28900:Added the test cases for PolicyManagementController
- Loading branch information
Showing
2 changed files
with
328 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- ------------------------------------------------------------------------------------------------- | ||
-- 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 | ||
|
||
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; | ||
|
||
ALTER TABLE pms.ftp_chip_detail DROP COLUMN approval_status; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
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.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 +55,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 +75,7 @@ public class PolicyManagementControllerTest { | |
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
@Mock | ||
private PolicyManagementService policyManagementService; | ||
|
||
@Autowired | ||
|
@@ -85,9 +84,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 +522,292 @@ private PolicyFilterValueDto createPolicyFilterRequest() { | |
policyFilterValueDto.setFilters(filterDtos); | ||
return policyFilterValueDto; | ||
} | ||
@Test | ||
public void definePolicyGroupTest001(){ | ||
PolicyGroupCreateRequestDto createRequestDto = new PolicyGroupCreateRequestDto(); | ||
createRequestDto.setName("Name"); | ||
createRequestDto.setDesc("desc"); | ||
RequestWrapper<PolicyGroupCreateRequestDto> 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<PolicyGroupCreateResponseDto> 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<SearchFilter> 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<String> values=new ArrayList<>(); | ||
String s="Values"; | ||
values.add(s); | ||
searchFilter1.setValues(values); | ||
searchFilter1.setType("type"); | ||
filters.add(searchFilter1); | ||
searchDto.setFilters(filters); | ||
List<SearchSort> sort=new ArrayList<>(); | ||
SearchSort searchSort1=new SearchSort(); | ||
searchSort1.setSortField("sortfield"); | ||
searchSort1.setSortType("stype"); | ||
sort.add(searchSort1); | ||
searchDto.setSort(sort); | ||
searchDto.setPagination(pagination); | ||
RequestWrapper<SearchDto> requestWrapper = new RequestWrapper<>(); | ||
requestWrapper.setVersion("1.2.1"); | ||
requestWrapper.setId("id"); | ||
requestWrapper.setMetadata("metadata"); | ||
requestWrapper.setRequest(searchDto); | ||
PageResponseDto<PolicyGroup> mockedPageResponseDto = new PageResponseDto<>(); | ||
Mockito.when(policyManagementService.searchPolicyGroup(searchDto)).thenReturn(mockedPageResponseDto); | ||
ResponseWrapper<PageResponseDto<PolicyGroup>> 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<PolicyGroupUpdateRequestDto> 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<PolicyGroupCreateResponseDto> 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", "[email protected]"); | ||
createRequestDto.setPolicies(jsonObject); | ||
RequestWrapper<PolicyCreateRequestDto> 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<PolicyCreateResponseDto> 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<PolicyGroupUpdateRequestDto> requestWrapper = new RequestWrapper<>(); | ||
requestWrapper.setVersion("1.2.0"); | ||
requestWrapper.setId("id"); | ||
requestWrapper.setMetadata("metadata"); | ||
Mockito.when(policyManagementService.publishPolicy(policygroupId, policyId)).thenReturn(mockedResponseDto); | ||
ResponseWrapper<PolicyResponseDto> 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", "[email protected]"); | ||
updateRequestDto.setPolicies(jsonObject); | ||
updateRequestDto.setVersion("1.12.2"); | ||
updateRequestDto.setPolicyGroupName("pgname"); | ||
updateRequestDto.setDesc("desc"); | ||
updateRequestDto.setName("name"); | ||
RequestWrapper<PolicyUpdateRequestDto> requestWrapper = new RequestWrapper<>(); | ||
requestWrapper.setMetadata("metadata"); | ||
requestWrapper.setVersion("1.12.2"); | ||
requestWrapper.setId("id"); | ||
requestWrapper.setRequest(updateRequestDto); | ||
ResponseWrapper<PolicyCreateResponseDto> response = policyManagementController.updatePolicyDetails(requestWrapper, policyId); | ||
assertNotNull(response); | ||
} | ||
@Test | ||
public void testUpdatePolicyStatus() throws Exception { | ||
PolicyStatusUpdateRequestDto statusUpdateRequest = new PolicyStatusUpdateRequestDto(); | ||
statusUpdateRequest.setStatus("active"); | ||
RequestWrapper<PolicyStatusUpdateRequestDto> 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<PolicyResponseDto> mockedResponseList = new ArrayList<>(); | ||
Mockito.when(policyManagementService.findAllPolicies()).thenReturn(mockedResponseList); | ||
ResponseWrapper<List<PolicyResponseDto>> 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<PolicyResponseDto> response = policyManagementController.getPolicy(policyId); | ||
response.setVersion("version"); | ||
response.setId("id"); | ||
List<ServiceError> 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<PolicyWithAuthPolicyDto> response = policyManagementController.getPolicyGroup(policygroupId); | ||
assertNotNull(response); | ||
assertNotNull(response.getResponse()); | ||
assertEquals(mockedResponseDto, response.getResponse()); | ||
} | ||
@Test | ||
public void testGetPolicyGroup() throws JsonParseException, JsonMappingException, IOException { | ||
List<PolicyWithAuthPolicyDto> mockedResponseList = new ArrayList<>(); | ||
Mockito.when(policyManagementService.getPolicyGroup()).thenReturn(mockedResponseList); | ||
ResponseWrapper<List<PolicyWithAuthPolicyDto>> response = policyManagementController.getPolicyGroup(); | ||
assertNotNull(response); | ||
assertNotNull(response.getResponse()); | ||
assertEquals(mockedResponseList, response.getResponse()); | ||
} | ||
@Test | ||
public void testSearchPolicyGroup001() { | ||
SearchDto searchDto = new SearchDto(); | ||
RequestWrapper<SearchDto> requestWrapper = new RequestWrapper<>(); | ||
requestWrapper.setRequest(searchDto); | ||
PageResponseDto<PolicyGroup> mockedResponse = new PageResponseDto<>(); | ||
Mockito.when(policyManagementService.searchPolicyGroup(searchDto)).thenReturn(mockedResponse); | ||
ResponseWrapper<PageResponseDto<PolicyGroup>> 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<PolicyResponseDto> response = policyManagementController.getPartnersPolicy(partnerId, policyId); | ||
assertNotNull(response); | ||
assertNotNull(response.getResponse()); | ||
assertEquals(mockedResponseDto, response.getResponse()); | ||
} | ||
@Test | ||
public void testSearchPolicy() { | ||
PolicySearchDto policySearchDto = new PolicySearchDto(); | ||
RequestWrapper<PolicySearchDto> requestWrapper = new RequestWrapper<>(); | ||
requestWrapper.setRequest(policySearchDto); | ||
PageResponseDto<SearchAuthPolicy> mockedResponse = new PageResponseDto<>(); | ||
Mockito.when(policyManagementService.searchPolicy(policySearchDto)).thenReturn(mockedResponse); | ||
ResponseWrapper<PageResponseDto<SearchAuthPolicy>> 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<String, Object> mockedResponse = new KeyValuePair<>("aaa",122); | ||
Mockito.when(policyManagementService.getValueForKey(key)).thenReturn(mockedResponse); | ||
ResponseWrapper<KeyValuePair<String, Object>> response = policyManagementController.getValueForKey(key); | ||
assertNotNull(response); | ||
assertNotNull(response.getResponse()); | ||
assertEquals(mockedResponse, response.getResponse()); | ||
} | ||
@Test | ||
public void testPolicyGroupFilterValues() { | ||
FilterValueDto filterValueDto = new FilterValueDto(); | ||
List<SearchFilter> optionalFilters=new ArrayList<>(); | ||
filterValueDto.setOptionalFilters(optionalFilters); | ||
List <FilterDto> filters=new ArrayList<>(); | ||
filterValueDto.setFilters(filters); | ||
RequestWrapper<FilterValueDto> requestWrapper = new RequestWrapper<>(); | ||
requestWrapper.setRequest(filterValueDto); | ||
FilterResponseCodeDto mockedResponse = new FilterResponseCodeDto(); | ||
Mockito.when(policyManagementService.policyGroupFilterValues(filterValueDto)).thenReturn(mockedResponse); | ||
ResponseWrapper<FilterResponseCodeDto> 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 <FilterDto> filters=new ArrayList<>(); | ||
policyFilterValueDto.setFilters(filters); | ||
List<SearchFilter> optionalFilters=new ArrayList<>(); | ||
policyFilterValueDto.setOptionalFilters(optionalFilters); | ||
RequestWrapper<PolicyFilterValueDto> 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<FilterResponseCodeDto> 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<PolicyDetailsDto> mockedResponse = new ArrayList<>(); | ||
Mockito.when(policyManagementService.getActivePolicyDetailsByGroupName(groupName)).thenReturn(mockedResponse); | ||
ResponseWrapper<List<PolicyDetailsDto>> response = policyManagementController.getPoliciesByGroupName(groupName); | ||
assertNotNull(response); | ||
assertNotNull(response.getResponse()); | ||
assertEquals(mockedResponse, response.getResponse()); | ||
} | ||
} |