JenaServiceRegistry extends WrappingRegistry implements ServiceRegistry, Updateable { @Override public ServiceInstanceRegistry instancesOf(final Service service) { init.await(); final URI registryURI = objectResourceOf(service.uri().toString(), PROP_HAS_SERVICE_INSTANCE_REGISTRY, parse( service)); if (registryURI == null) { throw new ResourceNotFoundException("No service instance registry found for service " + service.uri()); } final Model registry = getRegistry(registryURI, service); return new ServiceInstanceRegistry() { @Override public List<ServiceInstance> instances() { return objectResourcesOf(registryURI.toString(), PROP_HAS_SERVICE_INSTANCE, registry).stream() .map(uri -> new LdpServiceInstanceImpl(uri, service)) .collect(Collectors.toList()); } @Override public URI addEndpoint(final URI endpoint) { LOG.debug("PATCH: Adding endpoint <{}> to <{}>", endpoint, registryURI); final HttpPatch patch = new HttpPatch(registryURI); patch.setHeader(HttpHeaders.CONTENT_TYPE, SPARQL_UPDATE); patch.setEntity(new StringEntity(String.format( "INSERT {?instance <%s> <%s> .} WHERE {?instance a <%s> .}", PROP_HAS_ENDPOINT, endpoint, CLASS_SERVICE_INSTANCE), UTF_8)); try (CloseableHttpResponse resp = execute(patch)) { LOG.info("Adding endpoint <{}> to <{}>", endpoint, registryURI); } catch (final Exception e) { throw new RuntimeException(String.format("Failed adding endpoint <%s> to <%s>", endpoint, registryURI), e); } return registryURI; } }; }  void setHttpClient(final CloseableHttpClient client); void setRegistryContainer(final URI container); void setInitializer(final Initializer initializer); @Override void setRegistryDelegate(final Registry delegate); void init(); void shutdown(); @Override void update(); @Override void update(final URI uri); @Override void register(final URI uri); @Override ServiceInstanceRegistry createInstanceRegistry(final Service service); @Override ServiceInstanceRegistry instancesOf(final Service service); @Override Service getService(final URI uri); @Override Collection<URI> list(); @Override boolean contains(final URI uri); @Override boolean hasInDomain(final URI uri);  }
@SuppressWarnings("resource") @Test public void instancesOfTest() { final String SERVICE_INSTANCE_1 = "http: final String SERVICE_ENDPOINT_1 = "http: final String SERVICE_INSTANCE_2 = "http: final String SERVICE_ENDPOINT_2 = "http: final String SERVICE = "http: final URI SERVICE_URI = URI.create(SERVICE); final WebResource resource = rdfResource(SERVICE, triple(SERVICE, RDF_TYPE, CLASS_SERVICE) + triple(SERVICE, RDF_TYPE, CLASS_LDP_SERVICE_INSTANCE_REGISTRY) + triple(SERVICE, PROP_HAS_SERVICE_INSTANCE_REGISTRY, SERVICE) + triple(SERVICE, PROP_HAS_SERVICE_INSTANCE, SERVICE_INSTANCE_1) + triple(SERVICE, PROP_HAS_SERVICE_INSTANCE, SERVICE_INSTANCE_2) + triple(SERVICE_INSTANCE_1, PROP_HAS_ENDPOINT, SERVICE_ENDPOINT_1) + triple(SERVICE_INSTANCE_2, PROP_HAS_ENDPOINT, SERVICE_ENDPOINT_2)); when(delegate.get(SERVICE_URI)).thenReturn(resource); when(delegate.get(URI.create(SERVICE_INSTANCE_1))).thenReturn(resource); when(delegate.get(URI.create(SERVICE_INSTANCE_2))).thenReturn(resource); final ServiceInstanceRegistry instanceRegistry = toTest.instancesOf(toTest.getService(SERVICE_URI)); assertEquals(2, instanceRegistry.instances().size()); instanceRegistry.instances().stream().forEach(si -> assertEquals(1, si.endpoints().size())); final List<URI> instanceURIs = instanceRegistry.instances().stream().map(ServiceInstance::endpoints).flatMap( Collection::stream).collect( Collectors.toList()); assertTrue(instanceURIs.containsAll(Arrays.asList(URI.create(SERVICE_ENDPOINT_1), URI.create( SERVICE_ENDPOINT_2)))); }