PolicyServiceImpl implements PolicyService { @Override @Transactional public PolicyMetadataDto updatePolicy( PolicyContentDto updatePolicyRequestDto, String policyId) { assertPolicyId(policyId); final PolicyDto policyDto = MappingUtils .toPolicyDto(updatePolicyRequestDto.getPolicy()); assertPolicyIdConsistency(policyId, policyDto.getId()); final Policy policy = policyRepository.findOne(policyId); assertPolicyNotNull(policy, policyId); policy.setPolicy(updatePolicyRequestDto.getPolicy()); policy.setValid(PolicyValidationUtils.validate(updatePolicyRequestDto .getPolicy())); policyRepository.save(policy); final PolicyMetadataDto updatePolicyResponseDto = modelMapper.map( policy, PolicyMetadataDto.class); return updatePolicyResponseDto; }  @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 testUpdatePolicy() throws UnsupportedEncodingException { final byte[] policyBytes = POLICY_STRING1.getBytes("UTF-8"); final PolicyContentDto updatePolicyRequestDto = mock(PolicyContentDto.class); final Policy policy = mock(Policy.class); when(updatePolicyRequestDto.getPolicy()).thenReturn(policyBytes); when(policyRepository.findOne(POLICY_ID1)).thenReturn(policy); final PolicyMetadataDto updatePolicyResponseDto = mock(PolicyMetadataDto.class); when(modelMapper.map(policy, PolicyMetadataDto.class)).thenReturn( updatePolicyResponseDto); final PolicyMetadataDto response = sut.updatePolicy( updatePolicyRequestDto, POLICY_ID1); verify(policy, times(1)).setPolicy(policyBytes); verify(policy, times(1)).setValid(true); verify(policyRepository, times(1)).save(policy); assertEquals(updatePolicyResponseDto, response); }
@Test public void testUpdatePolicy_Throws_PolicyIdNotFoundException() throws UnsupportedEncodingException { thrown.expect(PolicyIdNotFoundException.class); final String policyId = ""; final PolicyContentDto updatePolicyRequestDto = mock(PolicyContentDto.class); sut.updatePolicy(updatePolicyRequestDto, policyId); }