@Test public void testGetPolicies_No_Wildcard_Throws_PolicyNotFoundException() { final String policyId = "policyId"; final String wildcard = null; thrown.expect(PolicyNotFoundException.class); when(policyRepository.findOne(policyId)).thenReturn(null); sut.getPolicies(policyId, wildcard); }
@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);  }