Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 69C66200BB1 for ; Thu, 3 Nov 2016 15:16:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 686FD160B0B; Thu, 3 Nov 2016 14:16:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8C34C160AFF for ; Thu, 3 Nov 2016 15:16:16 +0100 (CET) Received: (qmail 59748 invoked by uid 500); 3 Nov 2016 14:16:15 -0000 Mailing-List: contact commits-help@commonsrdf.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commonsrdf.incubator.apache.org Delivered-To: mailing list commits@commonsrdf.incubator.apache.org Received: (qmail 59739 invoked by uid 99); 3 Nov 2016 14:16:15 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2016 14:16:15 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id EC221C0750 for ; Thu, 3 Nov 2016 14:16:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Vv5BGy0we5pn for ; Thu, 3 Nov 2016 14:16:13 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 988F45F3F4 for ; Thu, 3 Nov 2016 14:16:12 +0000 (UTC) Received: (qmail 54978 invoked by uid 99); 3 Nov 2016 14:14:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2016 14:14:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A5F0FE0BB1; Thu, 3 Nov 2016 14:14:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stain@apache.org To: commits@commonsrdf.incubator.apache.org Date: Thu, 03 Nov 2016 14:14:57 -0000 Message-Id: <91d1c3c80d514fb0872b5eb58e0d0d98@git.apache.org> In-Reply-To: <36ffbb9871d743589a5f7e3b965fbbe8@git.apache.org> References: <36ffbb9871d743589a5f7e3b965fbbe8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] incubator-commonsrdf git commit: test getGraph(), getGraphNames() archived-at: Thu, 03 Nov 2016 14:16:17 -0000 test getGraph(), getGraphNames() Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/9f20482f Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/9f20482f Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/9f20482f Branch: refs/heads/master Commit: 9f20482fb42da24fb80e911fd2a86bd3bd0b50e8 Parents: c483e62 Author: Stian Soiland-Reyes Authored: Thu Nov 3 14:13:27 2016 +0000 Committer: Stian Soiland-Reyes Committed: Thu Nov 3 14:13:27 2016 +0000 ---------------------------------------------------------------------- .../commons/rdf/api/AbstractDatasetTest.java | 75 ++++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9f20482f/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java index 6940dae..a8e321c 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java @@ -17,11 +17,7 @@ */ package org.apache.commons.rdf.api; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.HashSet; @@ -29,7 +25,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Assume; @@ -464,7 +462,74 @@ public abstract class AbstractDatasetTest { g2.add(b2, b2, hasChild, b1); return g2; } + + /** + * Ensure {@link Dataset#getGraphNames()} contains our two graphs. + * + * @throws Exception + * If test fails + */ + @Test + public void getGraphNames() throws Exception { + Set names = dataset.getGraphNames().collect(Collectors.toSet()); + assertTrue("Can't find graph name " + graph1, names.contains(graph1)); + assertTrue("Can't find graph name " + graph2, names.contains(graph2)); + + // Some implementations like Virtuoso might have additional internal graphs, + // so we can't assume this: + //assertEquals(2, names.size()); + } + + @Test + public void getGraph() throws Exception { + Graph defaultGraph = dataset.getGraph(); + // TODO: Can we assume the default graph was empty before our new triples? + assertEquals(2, defaultGraph.size()); + assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); + // NOTE: graph2 is a BlankNode + assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, graph2)); + } + + + @Test + public void getGraphNull() throws Exception { + // Default graph should be present + Graph defaultGraph = dataset.getGraph(null).get(); + // TODO: Can we assume the default graph was empty before our new triples? + assertEquals(2, defaultGraph.size()); + assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); + // NOTE: graph2 is a BlankNode + assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, graph2)); + } + + + @Test + public void getGraph1() throws Exception { + // graph1 should be present + Graph g1 = dataset.getGraph(graph1).get(); + assertEquals(4, g1.size()); + + assertTrue(g1.contains(alice, name, aliceName)); + assertTrue(g1.contains(alice, knows, bob)); + assertTrue(g1.contains(alice, member, bnode1)); + assertTrue(g1.contains(bnode1, name, secretClubName)); + } + + @Test + public void getGraph2() throws Exception { + // graph2 should be present, even if is named by a BlankNode + Graph g2 = dataset.getGraph(graph2).get(); + assertEquals(4, g2.size()); + Triple bobNameTriple = bobNameQuad.asTriple(); + assertTrue(g2.contains(bobNameTriple)); + assertTrue(g2.contains(bob, member, bnode1)); + assertTrue(g2.contains(bob, member, bnode2)); + assertFalse(g2.contains(bnode1, name, secretClubName)); + assertTrue(g2.contains(bnode2, name, companyName)); + } + + /** * An attempt to use the Java 8 streams to look up a more complicated query. *