PolicyControllerV1 extends AbstractPolRepRestApiControllerV1 { @RequestMapping(value = "/policies/{policyId}", method = RequestMethod.GET) public PolicyContainerDto getPolicies( @PathVariable(value = "policyId") String policyId, @RequestParam(value = "wildcard", required = false) String wildcard) { return policyService.getPolicies(policyId, wildcard); }  @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 testGetPolicies_Success_Has_Wildcard_Multiple_Response() throws Exception { final String policyId1 = "policyId1"; final String policyId2 = "policyId2"; final boolean valid1 = true; final boolean valid2 = false; final String policy1 = "policy1"; final String policy2 = "policy2"; final String wildcard = "wildcard"; final PolicyDto getPolicyResponseDto1 = new PolicyDto(); getPolicyResponseDto1.setId(policyId1); getPolicyResponseDto1.setValid(valid1); getPolicyResponseDto1.setPolicy(policy1.getBytes(DEFAULT_ENCODING)); final PolicyDto getPolicyResponseDto2 = new PolicyDto(); getPolicyResponseDto2.setId(policyId2); getPolicyResponseDto2.setValid(valid2); getPolicyResponseDto2.setPolicy(policy2.getBytes(DEFAULT_ENCODING)); final PolicyContainerDto getPolicyResponseContainerDto = new PolicyContainerDto( getPolicyResponseDto1, getPolicyResponseDto2); final String uri = API + "/policies/" + policyId1; when(policyService.getPolicies(policyId1, wildcard)).thenReturn( getPolicyResponseContainerDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8).param("wildcard", wildcard)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect( jsonPath("$.policies", hasSize(getPolicyResponseContainerDto .getPolicies().size()))) .andExpect(jsonPath("$.policies[0].id", is(policyId1))) .andExpect(jsonPath("$.policies[0].valid", is(valid1))) .andExpect( jsonPath("$.policies[0].policy", is(Base64Utils .encodeToString(getPolicyResponseDto1 .getPolicy())))) .andExpect(jsonPath("$.policies[1].id", is(policyId2))) .andExpect(jsonPath("$.policies[1].valid", is(valid2))) .andExpect( jsonPath("$.policies[1].policy", is(Base64Utils .encodeToString(getPolicyResponseDto2 .getPolicy())))); verify(policyService, times(1)).getPolicies(policyId1, wildcard); }
@SuppressWarnings("unused") @Test public void testGetPolicies_Success_Has_Wildcard_Single_Response() throws Exception { final String policyId1 = "policyId"; final boolean valid1 = true; final String wildcard = "wildcard"; final String policy1 = "policy1"; final String policy2 = "policy2"; final PolicyDto getPolicyResponseDto1 = new PolicyDto(); getPolicyResponseDto1.setId(policyId1); getPolicyResponseDto1.setValid(valid1); getPolicyResponseDto1.setPolicy(policy1.getBytes(DEFAULT_ENCODING)); final PolicyContainerDto getPolicyResponseContainerDto = new PolicyContainerDto( getPolicyResponseDto1); final String uri = API + "/policies/" + policyId1; when(policyService.getPolicies(policyId1, wildcard)).thenReturn( getPolicyResponseContainerDto); mockMvc.perform( get(uri).contentType(APPLICATION_JSON_UTF8).param("wildcard", wildcard)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect( jsonPath("$.policies", hasSize(getPolicyResponseContainerDto .getPolicies().size()))) .andExpect(jsonPath("$.policies[0].id", is(policyId1))) .andExpect(jsonPath("$.policies[0].valid", is(valid1))) .andExpect( jsonPath("$.policies[0].policy", is(Base64Utils .encodeToString(getPolicyResponseDto1 .getPolicy())))); verify(policyService, times(1)).getPolicies(policyId1, wildcard); }
@SuppressWarnings("unused") @Test public void testGetPolicies_Success_No_Wildcard_Single_Response() throws Exception { final String policyId1 = "policyId"; final boolean valid1 = true; final String wildcard = null; final String policy1 = "policy1"; final String policy2 = "policy2"; final PolicyDto getPolicyResponseDto1 = new PolicyDto(); getPolicyResponseDto1.setId(policyId1); getPolicyResponseDto1.setValid(valid1); getPolicyResponseDto1.setPolicy(policy1.getBytes(DEFAULT_ENCODING)); final PolicyContainerDto getPolicyResponseContainerDto = new PolicyContainerDto( getPolicyResponseDto1); final String uri = API + "/policies/" + policyId1; when(policyService.getPolicies(policyId1, wildcard)).thenReturn( getPolicyResponseContainerDto); mockMvc.perform(get(uri).contentType(APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect( jsonPath("$.policies", hasSize(getPolicyResponseContainerDto .getPolicies().size()))) .andExpect(jsonPath("$.policies[0].id", is(policyId1))) .andExpect(jsonPath("$.policies[0].valid", is(valid1))) .andExpect( jsonPath("$.policies[0].policy", is(Base64Utils .encodeToString(getPolicyResponseDto1 .getPolicy())))); verify(policyService, times(1)).getPolicies(policyId1, wildcard); }