List of usage examples for org.apache.commons.rdf.api Graph contains
boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
From source file:org.trellisldp.test.ResourceServiceTests.java
/** * Test an LDP:Container./*from w w w .j ava 2 s. c om*/ * @throws Exception if the create operation fails */ @Test @DisplayName("Test LDP-C") default void testLdpC() throws Exception { final Instant time = now(); final RDF rdf = getInstance(); final String base = TRELLIS_DATA_PREFIX + getResourceService().generateIdentifier(); final IRI identifier = rdf.createIRI(base); final Dataset dataset0 = buildDataset(identifier, "Container Test", SUBJECT0); assertEquals(MISSING_RESOURCE, getResourceService().get(identifier).toCompletableFuture().join(), "Check for no pre-existing LDP-C"); assertDoesNotThrow( () -> getResourceService().create(Metadata.builder(identifier).interactionModel(LDP.Container) .container(ROOT_CONTAINER).build(), dataset0).toCompletableFuture().join(), "Check that the LDP-C is created successfully"); final IRI child1 = rdf.createIRI(base + "/child01"); final Dataset dataset1 = buildDataset(child1, "Contained Child 1", SUBJECT1); assertEquals(MISSING_RESOURCE, getResourceService().get(child1).toCompletableFuture().join(), "Check for no child1 resource"); assertDoesNotThrow( () -> getResourceService().create( Metadata.builder(child1).interactionModel(LDP.RDFSource).container(identifier).build(), dataset1).toCompletableFuture().join(), "Check that the first child was successfully created in the LDP-C"); final IRI child2 = rdf.createIRI(base + "/child02"); final Dataset dataset2 = buildDataset(child2, "Contained Child2", SUBJECT2); assertEquals(MISSING_RESOURCE, getResourceService().get(child2).toCompletableFuture().join(), "Check for no child2 resource"); assertDoesNotThrow( () -> getResourceService().create( Metadata.builder(child2).interactionModel(LDP.RDFSource).container(identifier).build(), dataset2).toCompletableFuture().join(), "Check that the second child was successfully created in the LDP-C"); final Resource res = getResourceService().get(identifier).toCompletableFuture().join(); assertAll("Check the LDP-C resource", checkResource(res, identifier, LDP.Container, time, dataset0)); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-C"); assertTrue(graph.contains(identifier, LDP.contains, child2), "Check that child2 is contained in the LDP-C"); assertEquals(3L, res.stream(Trellis.PreferUserManaged).count(), "Check the user-managed triple count"); }
From source file:org.trellisldp.test.ResourceServiceTests.java
/** * Test an LDP:BasicContainer./*w ww . jav a 2 s . c o m*/ * @throws Exception if the create operation fails */ @Test @DisplayName("Test LDP-BC") default void testLdpBC() throws Exception { final Instant time = now(); final RDF rdf = getInstance(); final String base = TRELLIS_DATA_PREFIX + getResourceService().generateIdentifier(); final IRI identifier = rdf.createIRI(base); final Dataset dataset0 = buildDataset(identifier, "Basic Container Test", SUBJECT0); assertEquals(MISSING_RESOURCE, getResourceService().get(identifier).toCompletableFuture().join(), "Check for a pre-existing LDP-BC"); assertDoesNotThrow( () -> getResourceService().create(Metadata.builder(identifier).interactionModel(LDP.BasicContainer) .container(ROOT_CONTAINER).build(), dataset0).toCompletableFuture().join(), "Check that creating an LDP-BC succeeds"); final IRI child1 = rdf.createIRI(base + "/child11"); final Dataset dataset1 = buildDataset(child1, "Contained Child 1", SUBJECT1); assertEquals(MISSING_RESOURCE, getResourceService().get(child1).toCompletableFuture().join(), "Check for no child1 resource"); assertDoesNotThrow(() -> getResourceService() .create(Metadata.builder(child1).interactionModel(LDP.RDFSource).container(identifier).build(), dataset1) .toCompletableFuture().join(), "Check that child1 is created"); final IRI child2 = rdf.createIRI(base + "/child12"); final Dataset dataset2 = buildDataset(child2, "Contained Child2", SUBJECT2); assertEquals(MISSING_RESOURCE, getResourceService().get(child2).toCompletableFuture().join(), "Check for no child2 resource"); assertDoesNotThrow(() -> getResourceService() .create(Metadata.builder(child2).interactionModel(LDP.RDFSource).container(identifier).build(), dataset2) .toCompletableFuture().join(), "Check that child2 is created"); final Resource res = getResourceService().get(identifier).toCompletableFuture().join(); assertAll("Check the LDP-BC resource", checkResource(res, identifier, LDP.BasicContainer, time, dataset0)); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-BC"); assertTrue(graph.contains(identifier, LDP.contains, child2), "Check that child2 is contained in the LDP-BC"); assertEquals(3L, res.stream(Trellis.PreferUserManaged).count(), "Check the user-managed triple count"); }
From source file:org.trellisldp.test.ResourceServiceTests.java
/** * Test an LDP:DirectContainer.//from w w w . jav a 2 s.c o m * @throws Exception if the create operation fails */ @Test @DisplayName("Test LDP-DC") default void testLdpDC() throws Exception { // Only test DC if the backend supports it assumeTrue(getResourceService().supportedInteractionModels().contains(LDP.DirectContainer)); final Instant time = now(); final RDF rdf = getInstance(); final String base = TRELLIS_DATA_PREFIX + getResourceService().generateIdentifier(); final IRI identifier = rdf.createIRI(base); final IRI member = rdf.createIRI(base + "/member"); final Dataset dataset0 = buildDataset(identifier, "Direct Container Test", SUBJECT0); dataset0.add(Trellis.PreferUserManaged, identifier, LDP.membershipResource, member); dataset0.add(Trellis.PreferUserManaged, identifier, LDP.isMemberOfRelation, DC.isPartOf); assertEquals(MISSING_RESOURCE, getResourceService().get(identifier).toCompletableFuture().join(), "Check that the DC doesn't exist"); assertDoesNotThrow(() -> getResourceService() .create(Metadata.builder(identifier).membershipResource(member).memberOfRelation(DC.isPartOf) .interactionModel(LDP.DirectContainer).container(ROOT_CONTAINER).build(), dataset0) .toCompletableFuture().join(), "Check that creating the LDP-DC succeeds"); final IRI child1 = rdf.createIRI(base + "/child1"); final Dataset dataset1 = buildDataset(child1, "Child 1", SUBJECT1); assertEquals(MISSING_RESOURCE, getResourceService().get(child1).toCompletableFuture().join(), "Check that no child resource exists"); assertDoesNotThrow( () -> getResourceService().create( Metadata.builder(child1).interactionModel(LDP.RDFSource).container(identifier).build(), dataset1).toCompletableFuture().join(), "Check that the child resource is successfully created"); final IRI child2 = rdf.createIRI(base + "/child2"); final Dataset dataset2 = buildDataset(child2, "Child 2", SUBJECT2); assertEquals(MISSING_RESOURCE, getResourceService().get(child2).toCompletableFuture().join(), "Check that no child2 resource exists"); assertDoesNotThrow( () -> getResourceService().create( Metadata.builder(child2).interactionModel(LDP.RDFSource).container(identifier).build(), dataset2).toCompletableFuture().join(), "Check that the child2 resource is successfully created"); final Resource res = getResourceService().get(identifier).toCompletableFuture().join(); assertAll("Check the resource", checkResource(res, identifier, LDP.DirectContainer, time, dataset0)); assertEquals(of(member), res.getMembershipResource(), "Check for ldp:membershipResource"); assertEquals(of(DC.isPartOf), res.getMemberOfRelation(), "Check for ldp:isMemberOfRelation"); assertFalse(res.getMemberRelation().isPresent(), "Check for no ldp:hasMemberRelation"); assertFalse(res.getInsertedContentRelation().filter(isEqual(LDP.MemberSubject).negate()).isPresent(), "Check for no ldp:InsertedContentRelation, excepting ldp:MemberSubject"); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-DC"); assertTrue(graph.contains(identifier, LDP.contains, child2), "Check that child2 is contained in the LDP-DC"); assertEquals(5L, res.stream(Trellis.PreferUserManaged).count(), "Check the user-managed triple count"); }
From source file:org.trellisldp.test.ResourceServiceTests.java
/** * Test an LDP:IndirectContainer./*from w w w .j av a2 s. c o m*/ * @throws Exception if the create operation fails */ @Test @DisplayName("Test LDP-IC") default void testLdpIC() throws Exception { // Only execute this test if the backend supports it assumeTrue(getResourceService().supportedInteractionModels().contains(LDP.IndirectContainer)); final Instant time = now(); final RDF rdf = getInstance(); final String base = TRELLIS_DATA_PREFIX + getResourceService().generateIdentifier(); final IRI identifier = rdf.createIRI(base); final IRI member = rdf.createIRI(base + "/member"); final Dataset dataset0 = buildDataset(identifier, "Indirect Container Test", SUBJECT0); dataset0.add(Trellis.PreferUserManaged, identifier, LDP.membershipResource, member); dataset0.add(Trellis.PreferUserManaged, identifier, LDP.hasMemberRelation, DC.relation); dataset0.add(Trellis.PreferUserManaged, identifier, LDP.insertedContentRelation, FOAF.primaryTopic); assertEquals(MISSING_RESOURCE, getResourceService().get(identifier).toCompletableFuture().join(), "Check for a missing resource"); assertDoesNotThrow(() -> getResourceService().create(Metadata.builder(identifier).membershipResource(member) .memberRelation(DC.relation).insertedContentRelation(FOAF.primaryTopic) .interactionModel(LDP.IndirectContainer).container(ROOT_CONTAINER).build(), dataset0) .toCompletableFuture().join(), "Check that creating a resource succeeds"); final IRI child1 = rdf.createIRI(base + "/child1"); final Dataset dataset1 = buildDataset(child1, "Indirect Container Child 1", SUBJECT1); assertEquals(MISSING_RESOURCE, getResourceService().get(child1).toCompletableFuture().join(), "Check that the child resource doesn't exist"); assertDoesNotThrow(() -> getResourceService() .create(Metadata.builder(child1).interactionModel(LDP.RDFSource).container(identifier).build(), dataset1) .toCompletableFuture().join(), "Check that creating a child resource succeeds"); final IRI child2 = rdf.createIRI(base + "/child2"); final Dataset dataset2 = buildDataset(child2, "Indirect Container Child 2", SUBJECT2); assertEquals(MISSING_RESOURCE, getResourceService().get(child2).toCompletableFuture().join(), "Check that the child resource doesn't exist"); assertDoesNotThrow(() -> getResourceService() .create(Metadata.builder(child2).interactionModel(LDP.RDFSource).container(identifier).build(), dataset2) .toCompletableFuture().join(), "Check that creating the child resource succeeds"); final Resource res = getResourceService().get(identifier).toCompletableFuture().join(); assertAll("Check the resource", checkResource(res, identifier, LDP.IndirectContainer, time, dataset0)); assertEquals(of(member), res.getMembershipResource(), "Check for ldp:membershipResource"); assertEquals(of(DC.relation), res.getMemberRelation(), "Check for ldp:hasMemberRelation"); assertEquals(of(FOAF.primaryTopic), res.getInsertedContentRelation(), "Check for ldp:insertedContentRelation"); assertFalse(res.getMemberOfRelation().isPresent(), "Check for no ldp:isMemberOfRelation"); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-IC"); assertTrue(graph.contains(identifier, LDP.contains, child2), "Check that child2 is contained in the LDP-IC"); assertEquals(6L, res.stream(Trellis.PreferUserManaged).count(), "Check the total triple count"); }