PolicyControllerV1 extends AbstractPolRepRestApiControllerV1 { @RequestMapping(value = "/policies/{policyId}/combined", method = RequestMethod.GET) public PolicyDto getPoliciesCombinedAsPolicySet( @PathVariable(value = "policyId") String policyId, @RequestParam(value = "wildcard", required = false) String wildcard, @RequestParam(value = "policySetId", required = false) String policySetId, @RequestParam(value = "policyCombiningAlgId", required = true) String policyCombiningAlgId) { return policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId); }  @RequestMapping(value = "/policies", method = RequestMethod.POST) PolicyMetadataContainerDto addPolicies(
			@Valid @RequestBody PolicyContentContainerDto addPolicyRequestContainerDto,
			@RequestParam(value = "force", required = false) boolean force); @RequestMapping(value = "/policies/{policyId}", method = RequestMethod.DELETE) void deletePolicy(@PathVariable(value = "policyId") String policyId,
			HttpServletResponse response); @RequestMapping(value = "/policies", method = RequestMethod.GET) PolicyMetadataContainerDto getAllPolicyMetadata(); @RequestMapping(value = "/policies/{policyId}", method = RequestMethod.GET) PolicyContainerDto getPolicies(
			@PathVariable(value = "policyId") String policyId,
			@RequestParam(value = "wildcard", required = false) String wildcard); @RequestMapping(value = "/policies/{policyId}/combined", method = RequestMethod.GET) PolicyDto getPoliciesCombinedAsPolicySet(
			@PathVariable(value = "policyId") String policyId,
			@RequestParam(value = "wildcard", required = false) String wildcard,
			@RequestParam(value = "policySetId", required = false) String policySetId,
			@RequestParam(value = "policyCombiningAlgId", required = true) String policyCombiningAlgId); @RequestMapping(value = "/policyCombiningAlgIds", method = RequestMethod.GET) Map<String, String> getPolicyCombiningAlgIds(); @RequestMapping(value = "/policies/{policyId}", method = RequestMethod.PUT) PolicyMetadataDto updatePolicy(
			@Valid @RequestBody PolicyContentDto updatePolicyRequestDto,
			@PathVariable(value = "policyId") String policyId);  }
@Test public void testGetPoliciesCombinedAsPolicySet_Fail_By_Has_Wildcard_Has_PolicySetId_No_PolicyCombiningAlgId() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = null; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenReturn(getPoliciesCombinedAsPolicySetResponseDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isBadRequest()); }
@SuppressWarnings("unchecked") @Test public void testGetPoliciesCombinedAsPolicySet_Fail_By_Throwing_DOMUtilsException() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenThrow(DOMUtilsException.class); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isPreconditionFailed()); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@SuppressWarnings("unchecked") @Test public void testGetPoliciesCombinedAsPolicySet_Fail_By_Throwing_InvalidPolicyCombiningAlgIdException() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenThrow(InvalidPolicyCombiningAlgIdException.class); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isBadRequest()); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@SuppressWarnings("unchecked") @Test public void testGetPoliciesCombinedAsPolicySet_Fail_By_Throwing_PolicyCombiningAlgIdNotFoundException() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenThrow(PolicyCombiningAlgIdNotFoundException.class); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isBadRequest()); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@SuppressWarnings("unchecked") @Test public void testGetPoliciesCombinedAsPolicySet_Fail_By_Throwing_PolicyIdNotFoundException() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenThrow(PolicyIdNotFoundException.class); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isPreconditionFailed()); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@SuppressWarnings("unchecked") @Test public void testGetPoliciesCombinedAsPolicySet_Fail_By_Throwing_PolicyNotFoundException() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenThrow(PolicyNotFoundException.class); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isNotFound()); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@Test public void testGetPoliciesCombinedAsPolicySet_Success_Has_Wildcard_Has_PolicySetId() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenReturn(getPoliciesCombinedAsPolicySetResponseDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", is(policySetId))) .andExpect(jsonPath("$.valid", is(policySetValid))) .andExpect( jsonPath( "$.policy", is(Base64Utils .encodeToString(getPoliciesCombinedAsPolicySetResponseDto .getPolicy())))); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@Test public void testGetPoliciesCombinedAsPolicySet_Success_Has_Wildcard_No_PolicySetId() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = null; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = "wildcard"; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenReturn(getPoliciesCombinedAsPolicySetResponseDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", is(policySetId))) .andExpect(jsonPath("$.valid", is(policySetValid))) .andExpect( jsonPath( "$.policy", is(Base64Utils .encodeToString(getPoliciesCombinedAsPolicySetResponseDto .getPolicy())))); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@Test public void testGetPoliciesCombinedAsPolicySet_Success_No_Wildcard_Has_PolicySetId() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = "policySetId"; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = null; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenReturn(getPoliciesCombinedAsPolicySetResponseDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", is(policySetId))) .andExpect(jsonPath("$.valid", is(policySetValid))) .andExpect( jsonPath( "$.policy", is(Base64Utils .encodeToString(getPoliciesCombinedAsPolicySetResponseDto .getPolicy())))); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }
@Test public void testGetPoliciesCombinedAsPolicySet_Success_No_Wildcard_No_PolicySetId() throws Exception { final String policyId = "policyId"; final String policySet = "policySet"; final String policySetId = null; final boolean policySetValid = true; final String policyCombiningAlgId = "policyCombiningAlgId"; final String wildcard = null; final PolicyDto getPoliciesCombinedAsPolicySetResponseDto = new PolicyDto(); getPoliciesCombinedAsPolicySetResponseDto.setId(policySetId); getPoliciesCombinedAsPolicySetResponseDto.setValid(policySetValid); getPoliciesCombinedAsPolicySetResponseDto.setPolicy(policySet .getBytes(DEFAULT_ENCODING)); final String uri = API + "/policies/" + policyId + "/combined"; when( policyService.getPoliciesCombinedAsPolicySet(policyId, wildcard, policySetId, policyCombiningAlgId)) .thenReturn(getPoliciesCombinedAsPolicySetResponseDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8) .param("wildcard", wildcard) .param("policySetId", policySetId) .param("policyCombiningAlgId", policyCombiningAlgId)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", is(policySetId))) .andExpect(jsonPath("$.valid", is(policySetValid))) .andExpect( jsonPath( "$.policy", is(Base64Utils .encodeToString(getPoliciesCombinedAsPolicySetResponseDto .getPolicy())))); verify(policyService, times(1)).getPoliciesCombinedAsPolicySet( policyId, wildcard, policySetId, policyCombiningAlgId); }