PolicyTryingImpl implements PolicyTrying { @Override public String tryPolicy(String c32Xml, String xacmlPolicy, String purposeOfUse) throws TryPolicyException { final String messageId = UUID.randomUUID().toString(); DSSResponse segmentDocumentResponse; try { final PdpRequestResponse pdpRequestResponse = contextHandler .makeDecisionForTryingPolicy(xacmlPolicy, purposeOfUse); final XacmlResponse xacmlResponse = pdpRequestResponse .getXacmlResponse(); final XacmlRequest xacmlRequest = pdpRequestResponse .getXacmlRequest(); final XacmlResult xacmlResult = createXacmlResult(xacmlRequest, xacmlResponse); final String enforcementPolicies = marshaller.marshal(xacmlResult); final DSSRequest request = new DSSRequest(); request.setDocumentXml(c32Xml); request.setEnforcementPoliciesXml(enforcementPolicies); request.setAudited(AUDITED); request.setAuditFailureByPass(AUDIT_FAILURE_BY_PASS); request.setEnableTryPolicyResponse(Boolean.TRUE); segmentDocumentResponse = documentSegmentation .segmentDocument(request); } catch (final Throwable t) { logger.error(messageId, "Error in tryPolicy", t); throw new TryPolicyException(t); } return segmentDocumentResponse.getTryPolicyDocumentXml(); } PolicyTryingImpl(ContextHandler contextHandler,
			SimpleMarshaller marshaller,
			DSSWebServiceClient documentSegmentation); @Override String tryPolicy(String c32Xml, String xacmlPolicy,
			String purposeOfUse); static final boolean AUDITED; static final boolean AUDIT_FAILURE_BY_PASS; }
@Test public void testTryPolicy() throws SimpleMarshallerException, InvalidSegmentedClinicalDocumentException, XmlDocumentReadFailureException, AuditException, TryPolicyException { final String c32Xml = "c32Xml"; final String xacmlPolicy = "xacmlPolicy"; final String purposeOfUse = "TREATMENT"; final PdpRequestResponse pdpRequestResponse = mock(PdpRequestResponse.class); final XacmlRequest xacmlRequest = mock(XacmlRequest.class); final XacmlResponse xacmlResponse = mock(XacmlResponse.class); when(xacmlRequest.getPurposeOfUse()).thenReturn( SubjectPurposeOfUse.HEALTHCARE_TREATMENT.getPurpose()); when(xacmlResponse.getPdpObligation()).thenReturn( new ArrayList<String>()); when( contextHandler.makeDecisionForTryingPolicy(xacmlPolicy, purposeOfUse)).thenReturn(pdpRequestResponse); when(pdpRequestResponse.getXacmlRequest()).thenReturn(xacmlRequest); when(pdpRequestResponse.getXacmlResponse()).thenReturn(xacmlResponse); final String enforcementPolicies = "String enforcementPolicies"; when( marshaller .marshal(argThat(new IsXacmlResultWithCorrectProperties( xacmlRequest, xacmlResponse)))).thenReturn( enforcementPolicies); final SegmentDocumentResponse segmentDocumentResponse = mock(SegmentDocumentResponse.class); final String segmentedC32 = "segmentedC32"; when(segmentDocumentResponse.getTryPolicyDocumentXml()).thenReturn( segmentedC32); final DSSResponse response = mock(DSSResponse.class); when(response.getTryPolicyDocumentXml()).thenReturn(segmentedC32); when(documentSegmentation.segmentDocument(isA(DSSRequest.class))) .thenReturn(response); final String result = sut.tryPolicy(c32Xml, xacmlPolicy, purposeOfUse); assertEquals("Not return expected result", segmentedC32, result); verify(documentSegmentation, times(1)).segmentDocument( argThat(matching((DSSRequest r) -> r.getDocumentXml().equals( c32Xml) && r.getEnforcementPoliciesXml().equals( enforcementPolicies) && r.isAudited() == false && r.isAuditFailureByPass() == true))); }