PolicyControllerV1 extends AbstractPolRepRestApiControllerV1 { @RequestMapping(value = "/policies/{policyId}", method = RequestMethod.PUT) public PolicyMetadataDto updatePolicy( @Valid @RequestBody PolicyContentDto updatePolicyRequestDto, @PathVariable(value = "policyId") String policyId) { return policyService.updatePolicy(updatePolicyRequestDto, policyId); }  @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);  }
@SuppressWarnings("unchecked") @Test public void testUpdatePolicy_Fail_By_Throwing_ConflictingRequestException() throws Exception { final String policyId = "policyId"; final boolean valid = true; final String policy = "policy"; final String uri = API + "/policies/" + policyId; final PolicyContentDto updatePolicyRequestDto = new PolicyContentDto(); updatePolicyRequestDto.setPolicy(policy.getBytes(DEFAULT_ENCODING)); final PolicyMetadataDto updatePolicyResponseDto = new PolicyMetadataDto(); updatePolicyResponseDto.setId(policyId); updatePolicyResponseDto.setValid(valid); when( policyService.updatePolicy(any(PolicyContentDto.class), eq(policyId))).thenThrow( ConflictingRequestException.class); mockMvc.perform( put(uri).contentType(APPLICATION_JSON_UTF8).content( convertObjectToJsonBytes(updatePolicyRequestDto))) .andExpect(status().isConflict()); verify(policyService, times(1)) .updatePolicy( argThat(matching((PolicyContentDto req) -> policy .equals(bytesToString(req)))), eq(policyId)); }
@SuppressWarnings("unchecked") @Test public void testUpdatePolicy_Fail_By_Throwing_DOMUtilsException() throws Exception { final String policyId = "policyId"; final boolean valid = true; final String policy = "policy"; final String uri = API + "/policies/" + policyId; final PolicyContentDto updatePolicyRequestDto = new PolicyContentDto(); updatePolicyRequestDto.setPolicy(policy.getBytes(DEFAULT_ENCODING)); final PolicyMetadataDto updatePolicyResponseDto = new PolicyMetadataDto(); updatePolicyResponseDto.setId(policyId); updatePolicyResponseDto.setValid(valid); when( policyService.updatePolicy(any(PolicyContentDto.class), eq(policyId))).thenThrow(DOMUtilsException.class); mockMvc.perform( put(uri).contentType(APPLICATION_JSON_UTF8).content( convertObjectToJsonBytes(updatePolicyRequestDto))) .andExpect(status().isPreconditionFailed()); verify(policyService, times(1)) .updatePolicy( argThat(matching((PolicyContentDto req) -> policy .equals(bytesToString(req)))), eq(policyId)); }
@SuppressWarnings("unchecked") @Test public void testUpdatePolicy_Fail_By_Throwing_PolicyIdNotFoundException() throws Exception { final String policyId = "policyId"; final boolean valid = true; final String policy = "policy"; final String uri = API + "/policies/" + policyId; final PolicyContentDto updatePolicyRequestDto = new PolicyContentDto(); updatePolicyRequestDto.setPolicy(policy.getBytes(DEFAULT_ENCODING)); final PolicyMetadataDto updatePolicyResponseDto = new PolicyMetadataDto(); updatePolicyResponseDto.setId(policyId); updatePolicyResponseDto.setValid(valid); when( policyService.updatePolicy(any(PolicyContentDto.class), eq(policyId))).thenThrow( PolicyIdNotFoundException.class); mockMvc.perform( put(uri).contentType(APPLICATION_JSON_UTF8).content( convertObjectToJsonBytes(updatePolicyRequestDto))) .andExpect(status().isPreconditionFailed()); verify(policyService, times(1)) .updatePolicy( argThat(matching((PolicyContentDto req) -> policy .equals(bytesToString(req)))), eq(policyId)); }
@SuppressWarnings("unchecked") @Test public void testUpdatePolicy_Fail_By_Throwing_PolicyNotFoundException() throws Exception { final String policyId = "policyId"; final boolean valid = true; final String policy = "policy"; final String uri = API + "/policies/" + policyId; final PolicyContentDto updatePolicyRequestDto = new PolicyContentDto(); updatePolicyRequestDto.setPolicy(policy.getBytes(DEFAULT_ENCODING)); final PolicyMetadataDto updatePolicyResponseDto = new PolicyMetadataDto(); updatePolicyResponseDto.setId(policyId); updatePolicyResponseDto.setValid(valid); when( policyService.updatePolicy(any(PolicyContentDto.class), eq(policyId))).thenThrow(PolicyNotFoundException.class); mockMvc.perform( put(uri).contentType(APPLICATION_JSON_UTF8).content( convertObjectToJsonBytes(updatePolicyRequestDto))) .andExpect(status().isNotFound()); verify(policyService, times(1)) .updatePolicy( argThat(matching((PolicyContentDto req) -> policy .equals(bytesToString(req)))), eq(policyId)); }
@Test public void testUpdatePolicy_Success() throws Exception { final String policyId = "policyId"; final boolean valid = true; final String policy = "policy"; final String uri = API + "/policies/" + policyId; final PolicyContentDto updatePolicyRequestDto = new PolicyContentDto(); updatePolicyRequestDto.setPolicy(policy.getBytes(DEFAULT_ENCODING)); final PolicyMetadataDto updatePolicyResponseDto = new PolicyMetadataDto(); updatePolicyResponseDto.setId(policyId); updatePolicyResponseDto.setValid(valid); when( policyService.updatePolicy(any(PolicyContentDto.class), eq(policyId))).thenReturn(updatePolicyResponseDto); mockMvc.perform( put(uri).contentType(APPLICATION_JSON_UTF8).content( convertObjectToJsonBytes(updatePolicyRequestDto))) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", is(policyId))) .andExpect(jsonPath("$.valid", is(valid))); verify(policyService, times(1)) .updatePolicy( argThat(matching((PolicyContentDto req) -> policy .equals(bytesToString(req)))), eq(policyId)); }