You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/06/17 22:55:27 UTC

[13/15] jena git commit: more tests.

more tests.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/01c7fd54
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/01c7fd54
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/01c7fd54

Branch: refs/heads/master
Commit: 01c7fd548a46e9796077a42eda617ab470fcfada
Parents: 90bfa41
Author: Alexis Miara <al...@hotmail.com>
Authored: Mon Jun 8 14:08:47 2015 -0400
Committer: Alexis Miara <al...@hotmail.com>
Committed: Mon Jun 8 14:08:47 2015 -0400

----------------------------------------------------------------------
 ...tasetWithLuceneTextIndexDeletionSupport.java |  53 ++++++++
 .../org/apache/jena/query/text/TS_Text.java     |   4 +-
 ...tasetWithLuceneTextIndexDeletionSupport.java | 109 ++++++++++++++++
 ...tDatasetWithLuceneTextIndexWithUidField.java | 129 -------------------
 4 files changed, 164 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/01c7fd54/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithLuceneTextIndexDeletionSupport.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithLuceneTextIndexDeletionSupport.java b/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithLuceneTextIndexDeletionSupport.java
new file mode 100644
index 0000000..9b39007
--- /dev/null
+++ b/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithLuceneTextIndexDeletionSupport.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.query.text;
+
+import org.apache.jena.query.Dataset;
+import org.apache.jena.tdb.TDBFactory;
+import org.apache.jena.vocabulary.RDFS;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.After;
+import org.junit.Before;
+
+
+/**
+ * This abstract class defines a setup configuration for a dataset with a deletion-support-enabled Lucene index.
+ */
+public class AbstractTestDatasetWithLuceneTextIndexDeletionSupport extends AbstractTestDatasetWithTextIndex {
+
+    @Before
+    public void init() {
+        Dataset ds1 = TDBFactory.createDataset() ;
+        Directory dir = new RAMDirectory() ;
+        EntityDefinition eDef = new EntityDefinition("iri", "text");
+        eDef.setPrimaryPredicate(RDFS.label);
+        eDef.set("comment", RDFS.comment.asNode()) ; // some tests require indexing rdfs:comment
+        //uid field to allow deletion
+        eDef.setUidField("uid");
+        TextIndex tidx = new TextIndexLucene(dir, new TextIndexConfig(eDef)) ;
+        dataset = TextDatasetFactory.create(ds1, tidx) ;
+    }
+
+    @After
+    public void teardown() {
+        dataset.close();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/01c7fd54/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java b/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
index 471b129..07f141a 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
@@ -32,9 +32,9 @@ import org.junit.runners.Suite.SuiteClasses ;
     , TestDatasetWithLuceneTextIndex.class
     , TestDatasetWithLuceneMultilingualTextIndex.class
     , TestDatasetWithLuceneTextIndexWithLangField.class
-    , TestDatasetWithLuceneTextIndexWithUidField.class
     , TestDatasetWithLuceneGraphTextIndex.class
-    
+    , TestDatasetWithLuceneTextIndexDeletionSupport.class
+
     // Embedded solr not supported 
     //, TestDatasetWithEmbeddedSolrTextIndex.class
     

http://git-wip-us.apache.org/repos/asf/jena/blob/01c7fd54/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexDeletionSupport.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexDeletionSupport.java b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexDeletionSupport.java
new file mode 100644
index 0000000..fc0b98a
--- /dev/null
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexDeletionSupport.java
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.query.text;
+
+import org.apache.jena.atlas.lib.StrUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class TestDatasetWithLuceneTextIndexDeletionSupport extends AbstractTestDatasetWithLuceneTextIndexDeletionSupport {
+
+    @Before
+    public void before() {
+        init();
+    }
+
+    @Test
+    public void testInsertDeleteOneTriple(){
+        final String turtle = StrUtils.strjoinNL(
+                TURTLE_PROLOG,
+                "<" + RESOURCE_BASE + "myResource>",
+                "  rdfs:label 'My first resource'",
+                "."
+        );
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s text:query ( rdfs:label 'first' ) .",
+                "}"
+        );
+        Set<String> expectedURIs = new HashSet<>() ;
+        expectedURIs.addAll( Arrays.asList("http://example.org/data/resource/myResource")) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+
+        String updateString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "DELETE DATA { ",
+                "    <" + RESOURCE_BASE + "myResource> rdfs:label 'My first resource'",
+                "}"
+        );
+        doUpdate(updateString);
+
+        queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s text:query ( rdfs:label 'first' ) .",
+                "}"
+        );
+        doTestNoResult(dataset, "", queryString);
+    }
+
+    @Test
+    public void testInsert2WithSameLabelAndDelete1(){
+        final String turtle = StrUtils.strjoinNL(
+                TURTLE_PROLOG,
+                "<" + RESOURCE_BASE + "object1>",
+                "  rdfs:label 'The same label'",
+                ".",
+                TURTLE_PROLOG,
+                "<" + RESOURCE_BASE + "object2>",
+                "  rdfs:label 'The same label'",
+                "."
+        );
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s text:query ( rdfs:label 'same' ) .",
+                "}"
+        );
+        Set<String> expectedURIs = new HashSet<String>() ;
+        expectedURIs.addAll( Arrays.asList("http://example.org/data/resource/object1",
+                                           "http://example.org/data/resource/object2")) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+
+        String updateString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "DELETE DATA { ",
+                "    <" + RESOURCE_BASE + "object1> rdfs:label 'The same label'",
+                "}"
+        );
+        doUpdate(updateString);
+
+        expectedURIs = new HashSet<String>() ;
+        expectedURIs.addAll( Arrays.asList("http://example.org/data/resource/object2")) ;
+        doTestQuery(dataset, "", queryString, expectedURIs, 1);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/01c7fd54/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexWithUidField.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexWithUidField.java b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexWithUidField.java
deleted file mode 100644
index 9431449..0000000
--- a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneTextIndexWithUidField.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.query.text;
-
-import org.apache.jena.assembler.Assembler;
-import org.apache.jena.atlas.lib.StrUtils;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.text.assembler.TextAssembler;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.ModelFactory;
-import org.apache.jena.rdf.model.Resource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-public class TestDatasetWithLuceneTextIndexWithUidField extends AbstractTestDatasetWithTextIndexBase {
-    
-    private static final String SPEC_BASE = "http://example.org/spec#";
-    private static final String SPEC_ROOT_LOCAL = "lucene_text_dataset";
-    private static final String SPEC_ROOT_URI = SPEC_BASE + SPEC_ROOT_LOCAL;
-    private static final String SPEC;
-    static {
-        SPEC = StrUtils.strjoinNL(
-                    "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ",
-                    "prefix ja:   <http://jena.hpl.hp.com/2005/11/Assembler#> ",
-                    "prefix tdb:  <http://jena.hpl.hp.com/2008/tdb#>",
-                    "prefix text: <http://jena.apache.org/text#>",
-                    "prefix :     <" + SPEC_BASE + ">",
-                    "",
-                    "[] ja:loadClass    \"org.apache.jena.query.text.TextQuery\" .",
-                    "text:TextDataset      rdfs:subClassOf   ja:RDFDataset .",
-                    "text:TextIndexLucene  rdfs:subClassOf   text:TextIndex .",
-                    
-                    ":" + SPEC_ROOT_LOCAL,
-                    "    a              text:TextDataset ;",
-                    "    text:dataset   :dataset ;",
-                    "    text:index     :indexLucene ;",
-                    "    .",
-                    "",
-                    ":dataset",
-                    "    a               ja:RDFDataset ;",
-                    "    ja:defaultGraph :graph ;",
-                    ".",
-                    ":graph",
-                    "    a               ja:MemoryModel ;",
-                    ".",
-                    "",
-                    ":indexLucene",
-                    "    a text:TextIndexLucene ;",
-                    "    text:directory \"mem\" ;",
-                    "    text:entityMap :entMap ;",
-                    "    .",
-                    "",
-                    ":entMap",
-                    "    a text:EntityMap ;",
-                    "    text:entityField      \"uri\" ;",
-                    "    text:defaultField     \"label\" ;",
-                    "    text:uidField         \"uuid\" ;",
-                    "    text:map (",
-                    "         [ text:field \"label\" ; text:predicate rdfs:label ]",
-                    "         [ text:field \"comment\" ; text:predicate rdfs:comment ]",
-                    "         ) ."
-                    );
-    }
-    
-    @Before
-    public void before() {
-        Reader reader = new StringReader(SPEC);
-        Model specModel = ModelFactory.createDefaultModel();
-        specModel.read(reader, "", "TURTLE");
-        TextAssembler.init();           
-        Resource root = specModel.getResource(SPEC_ROOT_URI);
-        dataset = (Dataset) Assembler.general.open(root);
-    }
-    
-    @After
-    public void after() {
-        dataset.close();
-    }
-    
-    @Test
-    public void testDeleteTriple(){
-        final String turtle = StrUtils.strjoinNL(
-                TURTLE_PROLOG,
-                "<" + RESOURCE_BASE + "myResource>",
-                "  rdfs:label 'My first resource'",
-                "."
-        );
-        loadData(turtle);
-        String updateString = StrUtils.strjoinNL(
-                QUERY_PROLOG,
-                "DELETE DATA { ",
-                "    <" + RESOURCE_BASE + "myResource> rdfs:label 'My first resource'",
-                "}"
-        );
-        doUpdate(updateString);
-
-        String queryString = StrUtils.strjoinNL(
-                QUERY_PROLOG,
-                "SELECT ?s",
-                "WHERE {",
-                "    ?s text:query ( rdfs:label 'first' ) .",
-                "}"
-        );
-        doTestNoResult(dataset, "", queryString);
-    }
-}