ConnectionManagerCache implements ConnectionManager { @Override public List<UrlInfo> getEndpointURLFromNhinTargetCommunities(NhinTargetCommunitiesType targets, String serviceName) throws ConnectionManagerException { ConnectionManagerCacheHelper helper = new ConnectionManagerCacheHelper(); Set<UrlInfo> endpointUrlSet = new HashSet<>(); if (targets != null && NullChecker.isNotNullish(targets.getNhinTargetCommunity())) { for (NhinTargetCommunityType target : targets.getNhinTargetCommunity()) { if (target.getHomeCommunity() != null && NullChecker.isNotNullish(target.getHomeCommunity().getHomeCommunityId())) { LOG.debug("Looking up URL by home community id"); String endpt = getDefaultEndpointURLByServiceName(target.getHomeCommunity().getHomeCommunityId(), serviceName); if (NullChecker.isNotNullish(endpt) || NullChecker.isNullish(endpt) && serviceName.equals(NhincConstants.DOC_QUERY_SERVICE_NAME)) { UrlInfo entry = new UrlInfo(); entry.setHcid(target.getHomeCommunity().getHomeCommunityId()); entry.setUrl(endpt); endpointUrlSet.add(entry); } } if (target.getRegion() != null) { LOG.debug("Looking up URL by region"); filterByRegion(endpointUrlSet, target.getRegion(), serviceName); } if (target.getList() != null) { LOG.debug("Looking up URL by list"); LOG.warn("The List target feature has not been implemented yet"); } } } else { for (BusinessEntity entity : getAllBusinessEntitySetByServiceName(serviceName)) { String hcid = helper.getCommunityId(entity); String endpt = getDefaultEndpointURLByServiceName(hcid, serviceName); if (NullChecker.isNotNullish(endpt)) { UrlInfo entry = new UrlInfo(); entry.setHcid(hcid); entry.setUrl(endpt); endpointUrlSet.add(entry); } } } List<UrlInfo> endpointUrlList = new ArrayList<>(endpointUrlSet); if (endpointUrlList != null) { printURLList(endpointUrlList); } return endpointUrlList; } ConnectionManagerCache();  ConnectionManagerCache(PropertyAccessor accessor); static ConnectionManagerCache getInstance(); void setCommunityId(BusinessEntity businessEntity, String newId); void forceRefreshUDDICache(); void forceRefreshInternalConnectCache(); @Override List<BusinessEntity> getAllBusinessEntities(); @Override BusinessEntity getBusinessEntity(String sHomeCommunityId); @Override String getBusinessEntityName(String homeCommunityId); @Override Set<BusinessEntity> getBusinessEntitySet(List<String> saHomeCommunityId); @Override BusinessEntity getBusinessEntityByServiceName(String sHomeCommunityId, String sUniformServiceName); @Override BusinessEntity getBusinessEntityByHCID(String sHomeCommunityId); @Override Set<BusinessEntity> getBusinessEntitySetByServiceName(List<String> saHomeCommunityId,
        String sUniformServiceName); @Override Set<BusinessEntity> getAllBusinessEntitySetByServiceName(String sUniformServiceName); @Override List<UDDI_SPEC_VERSION> getSpecVersions(String homeCommunityId,
        NhincConstants.NHIN_SERVICE_NAMES serviceName); @Override String getAdapterEndpointURL(String sHomeCommunityId, String sServiceName, ADAPTER_API_LEVEL level); @Override String getAdapterEndpointURL(String sServiceName, ADAPTER_API_LEVEL level); @Override String getDefaultEndpointURLByServiceName(String sHomeCommunityId, String sUniformServiceName); @Override String getEndpointURLByServiceNameSpecVersion(String sHomeCommunityId, String sUniformServiceName,
        UDDI_SPEC_VERSION version); @Override String getInternalEndpointURLByServiceName(String sUniformServiceName); @Override String getEndpointURLFromNhinTarget(NhinTargetSystemType targetSystem, String serviceName); @Override List<UrlInfo> getEndpointURLFromNhinTargetCommunities(NhinTargetCommunitiesType targets, String serviceName); boolean updateInternalServiceUrl(String serviceName, String url);  }
@Test public void testGetEndpointURLFromNhinTargetCommunitiesForNullEndPoints() { try { ConnectionManagerCache connectionManager = createConnectionManager(); List<UrlInfo> endpointUrlList = connectionManager.getEndpointURLFromNhinTargetCommunities( createNhinTargetCommunitesForNullendPoints(), QUERY_FOR_DOCUMENTS_NAME); assertTrue(endpointUrlList.get(0).getUrl().equals(QUERY_FOR_DOCUMENTS_NULL_URL)); } catch (Throwable t) { t.printStackTrace(); fail("Error running testGetEndpointURLFromNhinTargetCommunities test: " + t.getMessage()); } }
@Test public void testGetEndpointURLFromNhinTargetCommunitiesUniqueness() { try { ConnectionManagerCache connectionManager = createConnectionManager(); List<UrlInfo> endpointUrlList = connectionManager.getEndpointURLFromNhinTargetCommunities( createNhinTargetCommunitesWithDuplicateTargetCommunities(), QUERY_FOR_DOCUMENTS_NAME); assertEquals(1, endpointUrlList.size()); } catch (Throwable t) { t.printStackTrace(); fail("Error running testGetEndpointURLFromNhinTargetCommunities test: " + t.getMessage()); } }