PurposeUseProxyCommunityImpl implements PurposeUseProxy { @Override public boolean isPurposeForUseEnabled(CallbackProperties callbackProperties) { String targetHomeCommunityId = callbackProperties.getTargetHomeCommunityId(); if (targetHomeCommunityId != null) { if (targetHomeCommunityId.startsWith(NhincConstants.HCID_PREFIX)) { targetHomeCommunityId = targetHomeCommunityId.replace(NhincConstants.HCID_PREFIX, ""); } return isPurposeForUseEnabled(targetHomeCommunityId); } return false; } PurposeUseProxyCommunityImpl(IPropertyAcessor propertyAccessor);  PurposeUseProxyCommunityImpl(); @Override boolean isPurposeForUseEnabled(CallbackProperties callbackProperties);  }
@Test public void testPurposeForEnabledWhenHcidTrue() throws PropertyAccessException { PurposeUseProxy testPurposeUseProxy = new PurposeUseProxyCommunityImpl(mockPropertyAccessor); String hcid = "1234"; setPropertyExpectation(Expectations.returnValue(null), NhincConstants.GATEWAY_PROPERTY_FILE, "purposeForUseEnabled"); setPropertyExpectation(Expectations.returnValue("true"), "purposeUse", hcid); setTargetHcidExpectation(Expectations.returnValue(hcid)); Assert.assertTrue(testPurposeUseProxy.isPurposeForUseEnabled(mockCallbackProperties)); }
@Test public void testPurposeForDisabledWhenHcidFalse() throws PropertyAccessException { PurposeUseProxy testPurposeUseProxy = new PurposeUseProxyCommunityImpl(mockPropertyAccessor); String hcid = "1234"; setPropertyExpectation(Expectations.returnValue("true"), NhincConstants.GATEWAY_PROPERTY_FILE, "purposeForUseEnabled"); setPropertyExpectation(Expectations.returnValue("false"), "purposeUse", hcid); setTargetHcidExpectation(Expectations.returnValue(hcid)); Assert.assertFalse(testPurposeUseProxy.isPurposeForUseEnabled(mockCallbackProperties)); }
@Test public void testPurposeForDisabledWhenHcidPointless() throws PropertyAccessException { PurposeUseProxy testPurposeUseProxy = new PurposeUseProxyCommunityImpl(mockPropertyAccessor); String hcid = "1234"; setPropertyExpectation(Expectations.returnValue("true"), NhincConstants.GATEWAY_PROPERTY_FILE, "purposeForUseEnabled"); setPropertyExpectation(Expectations.returnValue("my cat's name is mittens."), "purposeUse", hcid); setTargetHcidExpectation(Expectations.returnValue(hcid)); Assert.assertFalse(testPurposeUseProxy.isPurposeForUseEnabled(mockCallbackProperties)); }
@Test public void testPurposeForDisabledWhenHcidMissing() throws PropertyAccessException { PurposeUseProxy testPurposeUseProxy = new PurposeUseProxyCommunityImpl(mockPropertyAccessor); String hcid = "1234"; setPropertyExpectation(Expectations.returnValue("true"), NhincConstants.GATEWAY_PROPERTY_FILE, "purposeForUseEnabled"); setPropertyExpectation(Expectations.returnValue(null), "purposeUse", hcid); setTargetHcidExpectation(Expectations.returnValue(hcid)); Assert.assertFalse(testPurposeUseProxy.isPurposeForUseEnabled(mockCallbackProperties)); }
@Test public void testPurposeForUseEnabled_Exception() throws PropertyAccessException { String hcid = "1234"; IPropertyAcessor propAccessor = mock(IPropertyAcessor.class); PurposeUseProxy testPurposeUseProxy = new PurposeUseProxyCommunityImpl(propAccessor); CallbackProperties callbackProps = mock(CallbackProperties.class); when(callbackProps.getTargetHomeCommunityId()).thenReturn(hcid); when(propAccessor.getProperty("purposeUse", hcid)).thenThrow(new PropertyAccessException()); Assert.assertFalse(testPurposeUseProxy.isPurposeForUseEnabled(callbackProps)); }