PolicyServiceImpl implements PolicyService { @Override @Transactional(readOnly = true) public PolicyMetadataContainerDto getAllPolicyMetadata() { final List<Policy> allPolicies = policyRepository.findAll(); if (allPolicies == null || allPolicies.size() == 0) { throw new PolicyNotFoundException( "There are no policies in this policy repository."); } final List<PolicyMetadataDto> policyMetadataDtos = allPolicies .stream() .map(policy -> modelMapper.map(policy, PolicyMetadataDto.class)) .collect(toList()); return new PolicyMetadataContainerDto(policyMetadataDtos); }  @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);  }
@Test public void testGetAllPolicyMetadata() throws UnsupportedEncodingException { final Policy p1 = new Policy(); p1.setId(POLICY_ID1); p1.setPolicy(POLICY_STRING1.getBytes("UTF-8")); p1.setValid(true); final Policy p2 = new Policy(); p2.setId(POLICY_ID2); p2.setPolicy(POLICY_STRING2.getBytes("UTF-8")); p2.setValid(false); final List<Policy> policyList = Arrays.asList(p1, p2); final PolicyMetadataDto m1 = new PolicyMetadataDto(); final PolicyMetadataDto m2 = new PolicyMetadataDto(); m1.setId(p1.getId()); m1.setValid(p1.isValid()); m2.setId(p2.getId()); m2.setValid(p2.isValid()); when(policyRepository.findAll()).thenReturn(policyList); when(modelMapper.map(p1, PolicyMetadataDto.class)).thenReturn(m1); when(modelMapper.map(p2, PolicyMetadataDto.class)).thenReturn(m2); final PolicyMetadataContainerDto response = sut.getAllPolicyMetadata(); assertEquals(policyList.size(), response.getPolicies().size()); assertEquals(p1.getId(), response.getPolicies().get(0).getId()); assertEquals(p1.isValid(), response.getPolicies().get(0).isValid()); assertEquals(p2.getId(), response.getPolicies().get(1).getId()); assertEquals(p2.isValid(), response.getPolicies().get(1).isValid()); }
@Test public void testGetAllPolicyMetadata_Throws_PolicyNotFoundException() throws UnsupportedEncodingException { thrown.expect(PolicyNotFoundException.class); final List<Policy> policyList = new ArrayList<Policy>(); when(policyRepository.findAll()).thenReturn(policyList); sut.getAllPolicyMetadata(); }