@Test public void testGetPolicies_Throws_PolicyProviderException() throws NoPolicyFoundException, PolicyProviderException, Hl7v3TransformerException, JAXBException, IOException { thrown.expect(PolicyProviderException.class); SimplePDPFactory.getSimplePDP(); final String homeCommunityId = "homeCommunityId"; final String intermediarySubjectNPI = "intermediarySubjectNPI"; final String messageId = "messageId"; final String patientId = "patientId"; final String patientUniqueId = "patientUniqueId"; final String purposeOfUse = "purposeOfUse"; final String recipientSubjectNPI = "recipientSubjectNPI"; final String xacml = "NotXacml"; final byte[] bytes = xacml.getBytes("UTF-8"); final XacmlRequest xacmlRequest = new XacmlRequest(); xacmlRequest.setHomeCommunityId(homeCommunityId); xacmlRequest.setIntermediarySubjectNPI(intermediarySubjectNPI); xacmlRequest.setMessageId(messageId); xacmlRequest.setPatientId(patientId); xacmlRequest.setPatientUniqueId(patientUniqueId); xacmlRequest.setPurposeOfUse(purposeOfUse); xacmlRequest.setRecipientSubjectNPI(recipientSubjectNPI); final PolicyDto policyDto = mock(PolicyDto.class); when( polRepRestClient.getPoliciesCombinedAsPolicySet(anyString(), anyString(), anyString(), eq(PolicyCombiningAlgIds.DENY_OVERRIDES))).thenReturn( policyDto); when(policyDto.getPolicy()).thenReturn(bytes); final String hl7Query = "hl7Query"; when( hl7v3Transformer.getPixQueryXml(eq(patientId), anyString(), eq(Hl7v3Transformer.XML_PIX_QUERY))).thenReturn( hl7Query); final PRPAIN201309UV02 req = mock(PRPAIN201309UV02.class); when( requestXMLToJava.getPIXQueryReqObject(hl7Query, PixManagerConstants.ENCODE_STRING)).thenReturn(req); final PRPAIN201310UV02 resp = mock(PRPAIN201310UV02.class); when(pixManagerService.pixManagerPRPAIN201309UV02(req)) .thenReturn(resp); final PixManagerBean pixManagerBean = mock(PixManagerBean.class); when( pixManagerMessageHelper.getQueryMessage(eq(resp), any(PixManagerBean.class))).thenReturn(pixManagerBean); final List<Evaluatable> response = sut.getPolicies(xacmlRequest); assertNotNull(response); assertTrue(response.size() == 1); assertNotNull(response.get(0)); }
@Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { try { final String eid = xacmlRequest.getPatientId(); final String eidDomain = xacmlRequest.getHomeCommunityId(); final String mrn = getMrn(eid, eidDomain); final String policyId = toPolicyId(mrn, pidDomain, xacmlRequest.getRecipientSubjectNPI(), xacmlRequest.getIntermediarySubjectNPI()); final PolicyDto policyDto = polRepRestClient .getPoliciesCombinedAsPolicySet(policyId, WILDCARD, UUID .randomUUID().toString(), PolicyCombiningAlgIds.DENY_OVERRIDES); final Evaluatable policySet = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policyDto.getPolicy())); return Arrays.asList(policySet); } catch (final SyntaxException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); throw new PolicyProviderException(e.getMessage(), e); } catch (final HttpStatusCodeException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); if (e.getStatusCode().is4xxClientError()) { logger.info(xacmlRequest.getMessageId(), e.getMessage()); throw new NoPolicyFoundException(e.getMessage(), e); } else { throw new PolicyProviderException(e.getMessage(), e); } } }
PolRepPolicyProvider implements PolicyProvider { @Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { try { final String eid = xacmlRequest.getPatientId(); final String eidDomain = xacmlRequest.getHomeCommunityId(); final String mrn = getMrn(eid, eidDomain); final String policyId = toPolicyId(mrn, pidDomain, xacmlRequest.getRecipientSubjectNPI(), xacmlRequest.getIntermediarySubjectNPI()); final PolicyDto policyDto = polRepRestClient .getPoliciesCombinedAsPolicySet(policyId, WILDCARD, UUID .randomUUID().toString(), PolicyCombiningAlgIds.DENY_OVERRIDES); final Evaluatable policySet = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policyDto.getPolicy())); return Arrays.asList(policySet); } catch (final SyntaxException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); throw new PolicyProviderException(e.getMessage(), e); } catch (final HttpStatusCodeException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); if (e.getStatusCode().is4xxClientError()) { logger.info(xacmlRequest.getMessageId(), e.getMessage()); throw new NoPolicyFoundException(e.getMessage(), e); } else { throw new PolicyProviderException(e.getMessage(), e); } } } }
PolRepPolicyProvider implements PolicyProvider { @Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { try { final String eid = xacmlRequest.getPatientId(); final String eidDomain = xacmlRequest.getHomeCommunityId(); final String mrn = getMrn(eid, eidDomain); final String policyId = toPolicyId(mrn, pidDomain, xacmlRequest.getRecipientSubjectNPI(), xacmlRequest.getIntermediarySubjectNPI()); final PolicyDto policyDto = polRepRestClient .getPoliciesCombinedAsPolicySet(policyId, WILDCARD, UUID .randomUUID().toString(), PolicyCombiningAlgIds.DENY_OVERRIDES); final Evaluatable policySet = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policyDto.getPolicy())); return Arrays.asList(policySet); } catch (final SyntaxException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); throw new PolicyProviderException(e.getMessage(), e); } catch (final HttpStatusCodeException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); if (e.getStatusCode().is4xxClientError()) { logger.info(xacmlRequest.getMessageId(), e.getMessage()); throw new NoPolicyFoundException(e.getMessage(), e); } else { throw new PolicyProviderException(e.getMessage(), e); } } } PolRepPolicyProvider(String pidDomain, String pidDomainType,
			Hl7v3Transformer hl7v3Transformer,
			PixManagerRequestXMLToJava requestXMLToJava,
			PixManagerMessageHelper pixManagerMessageHelper,
			PixManagerService pixManagerService,
			PolRepRestClient polRepRestClient); }
PolRepPolicyProvider implements PolicyProvider { @Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { try { final String eid = xacmlRequest.getPatientId(); final String eidDomain = xacmlRequest.getHomeCommunityId(); final String mrn = getMrn(eid, eidDomain); final String policyId = toPolicyId(mrn, pidDomain, xacmlRequest.getRecipientSubjectNPI(), xacmlRequest.getIntermediarySubjectNPI()); final PolicyDto policyDto = polRepRestClient .getPoliciesCombinedAsPolicySet(policyId, WILDCARD, UUID .randomUUID().toString(), PolicyCombiningAlgIds.DENY_OVERRIDES); final Evaluatable policySet = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policyDto.getPolicy())); return Arrays.asList(policySet); } catch (final SyntaxException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); throw new PolicyProviderException(e.getMessage(), e); } catch (final HttpStatusCodeException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); if (e.getStatusCode().is4xxClientError()) { logger.info(xacmlRequest.getMessageId(), e.getMessage()); throw new NoPolicyFoundException(e.getMessage(), e); } else { throw new PolicyProviderException(e.getMessage(), e); } } } PolRepPolicyProvider(String pidDomain, String pidDomainType,
			Hl7v3Transformer hl7v3Transformer,
			PixManagerRequestXMLToJava requestXMLToJava,
			PixManagerMessageHelper pixManagerMessageHelper,
			PixManagerService pixManagerService,
			PolRepRestClient polRepRestClient); @Override List<Evaluatable> getPolicies(XacmlRequest xacmlRequest); }
PolRepPolicyProvider implements PolicyProvider { @Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { try { final String eid = xacmlRequest.getPatientId(); final String eidDomain = xacmlRequest.getHomeCommunityId(); final String mrn = getMrn(eid, eidDomain); final String policyId = toPolicyId(mrn, pidDomain, xacmlRequest.getRecipientSubjectNPI(), xacmlRequest.getIntermediarySubjectNPI()); final PolicyDto policyDto = polRepRestClient .getPoliciesCombinedAsPolicySet(policyId, WILDCARD, UUID .randomUUID().toString(), PolicyCombiningAlgIds.DENY_OVERRIDES); final Evaluatable policySet = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policyDto.getPolicy())); return Arrays.asList(policySet); } catch (final SyntaxException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); throw new PolicyProviderException(e.getMessage(), e); } catch (final HttpStatusCodeException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); if (e.getStatusCode().is4xxClientError()) { logger.info(xacmlRequest.getMessageId(), e.getMessage()); throw new NoPolicyFoundException(e.getMessage(), e); } else { throw new PolicyProviderException(e.getMessage(), e); } } } PolRepPolicyProvider(String pidDomain, String pidDomainType,
			Hl7v3Transformer hl7v3Transformer,
			PixManagerRequestXMLToJava requestXMLToJava,
			PixManagerMessageHelper pixManagerMessageHelper,
			PixManagerService pixManagerService,
			PolRepRestClient polRepRestClient); @Override List<Evaluatable> getPolicies(XacmlRequest xacmlRequest);  }