@Test public void testGetPolicies_Wildcard_Used() { final String policyId = "policy*"; final String wildcard = "*"; final String policyIdLike = "policy%"; final Policy policy1 = mock(Policy.class); final Policy policy2 = mock(Policy.class); final List<Policy> policyList = Arrays.asList(policy1, policy2); final PolicyDto getPolicyResponseDto1 = mock(PolicyDto.class); final PolicyDto getPolicyResponseDto2 = mock(PolicyDto.class); when(policyRepository.findAllByIdLike(policyIdLike)).thenReturn( policyList); when(modelMapper.map(policy1, PolicyDto.class)).thenReturn( getPolicyResponseDto1); when(modelMapper.map(policy2, PolicyDto.class)).thenReturn( getPolicyResponseDto2); final PolicyContainerDto response = sut.getPolicies(policyId, wildcard); assertTrue(response.getPolicies().contains(getPolicyResponseDto1)); assertTrue(response.getPolicies().contains(getPolicyResponseDto2)); }
@Override @Transactional(readOnly = true) public PolicyContainerDto getPolicies(String policyId, String wildcard) { assertPolicyId(policyId); if (wildcard == null) { final Policy policy = policyRepository.findOne(policyId); assertPolicyNotNull(policy, policyId); final PolicyDto policyDto = modelMapper .map(policy, PolicyDto.class); return new PolicyContainerDto(policyDto); } else { wildcard = "".equals(wildcard) ? DEFAULT_WILDCARD : wildcard; final String policyIdLike = policyId.replace(wildcard, LIKE); final List<Policy> policies = policyRepository .findAllByIdLike(policyIdLike); assertPoliciesNotEmpty(policies, policyId, wildcard); final List<PolicyDto> policyDtos = policies.stream() .map(p -> modelMapper.map(p, PolicyDto.class)) .collect(toList()); return new PolicyContainerDto(policyDtos); } }
PolicyServiceImpl implements PolicyService { @Override @Transactional(readOnly = true) public PolicyContainerDto getPolicies(String policyId, String wildcard) { assertPolicyId(policyId); if (wildcard == null) { final Policy policy = policyRepository.findOne(policyId); assertPolicyNotNull(policy, policyId); final PolicyDto policyDto = modelMapper .map(policy, PolicyDto.class); return new PolicyContainerDto(policyDto); } else { wildcard = "".equals(wildcard) ? DEFAULT_WILDCARD : wildcard; final String policyIdLike = policyId.replace(wildcard, LIKE); final List<Policy> policies = policyRepository .findAllByIdLike(policyIdLike); assertPoliciesNotEmpty(policies, policyId, wildcard); final List<PolicyDto> policyDtos = policies.stream() .map(p -> modelMapper.map(p, PolicyDto.class)) .collect(toList()); return new PolicyContainerDto(policyDtos); } } }
PolicyServiceImpl implements PolicyService { @Override @Transactional(readOnly = true) public PolicyContainerDto getPolicies(String policyId, String wildcard) { assertPolicyId(policyId); if (wildcard == null) { final Policy policy = policyRepository.findOne(policyId); assertPolicyNotNull(policy, policyId); final PolicyDto policyDto = modelMapper .map(policy, PolicyDto.class); return new PolicyContainerDto(policyDto); } else { wildcard = "".equals(wildcard) ? DEFAULT_WILDCARD : wildcard; final String policyIdLike = policyId.replace(wildcard, LIKE); final List<Policy> policies = policyRepository .findAllByIdLike(policyIdLike); assertPoliciesNotEmpty(policies, policyId, wildcard); final List<PolicyDto> policyDtos = policies.stream() .map(p -> modelMapper.map(p, PolicyDto.class)) .collect(toList()); return new PolicyContainerDto(policyDtos); } }  }
PolicyServiceImpl implements PolicyService { @Override @Transactional(readOnly = true) public PolicyContainerDto getPolicies(String policyId, String wildcard) { assertPolicyId(policyId); if (wildcard == null) { final Policy policy = policyRepository.findOne(policyId); assertPolicyNotNull(policy, policyId); final PolicyDto policyDto = modelMapper .map(policy, PolicyDto.class); return new PolicyContainerDto(policyDto); } else { wildcard = "".equals(wildcard) ? DEFAULT_WILDCARD : wildcard; final String policyIdLike = policyId.replace(wildcard, LIKE); final List<Policy> policies = policyRepository .findAllByIdLike(policyIdLike); assertPoliciesNotEmpty(policies, policyId, wildcard); final List<PolicyDto> policyDtos = policies.stream() .map(p -> modelMapper.map(p, PolicyDto.class)) .collect(toList()); return new PolicyContainerDto(policyDtos); } }  @Override @Transactional PolicyMetadataContainerDto addPolicies(
			PolicyContentContainerDto policyContentContainerDto, boolean force); @Override @Transactional void deletePolicy(String policyId); @Override @Transactional(readOnly = true) PolicyMetadataContainerDto getAllPolicyMetadata(); @Override @Transactional(readOnly = true) PolicyContainerDto getPolicies(String policyId, String wildcard); @Override @Transactional(readOnly = true) PolicyDto getPoliciesCombinedAsPolicySet(String policyId,
			String wildcard, String policySetId, String policyCombiningAlgId); @Override Map<String, String> getPolicyCombiningAlgIds(); @Override @Transactional PolicyMetadataDto updatePolicy(
			PolicyContentDto updatePolicyRequestDto, String policyId); }
PolicyServiceImpl implements PolicyService { @Override @Transactional(readOnly = true) public PolicyContainerDto getPolicies(String policyId, String wildcard) { assertPolicyId(policyId); if (wildcard == null) { final Policy policy = policyRepository.findOne(policyId); assertPolicyNotNull(policy, policyId); final PolicyDto policyDto = modelMapper .map(policy, PolicyDto.class); return new PolicyContainerDto(policyDto); } else { wildcard = "".equals(wildcard) ? DEFAULT_WILDCARD : wildcard; final String policyIdLike = policyId.replace(wildcard, LIKE); final List<Policy> policies = policyRepository .findAllByIdLike(policyIdLike); assertPoliciesNotEmpty(policies, policyId, wildcard); final List<PolicyDto> policyDtos = policies.stream() .map(p -> modelMapper.map(p, PolicyDto.class)) .collect(toList()); return new PolicyContainerDto(policyDtos); } }  @Override @Transactional PolicyMetadataContainerDto addPolicies(
			PolicyContentContainerDto policyContentContainerDto, boolean force); @Override @Transactional void deletePolicy(String policyId); @Override @Transactional(readOnly = true) PolicyMetadataContainerDto getAllPolicyMetadata(); @Override @Transactional(readOnly = true) PolicyContainerDto getPolicies(String policyId, String wildcard); @Override @Transactional(readOnly = true) PolicyDto getPoliciesCombinedAsPolicySet(String policyId,
			String wildcard, String policySetId, String policyCombiningAlgId); @Override Map<String, String> getPolicyCombiningAlgIds(); @Override @Transactional PolicyMetadataDto updatePolicy(
			PolicyContentDto updatePolicyRequestDto, String policyId);  }