You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2016/05/02 11:49:51 UTC

[14/50] [abbrv] marmotta git commit: more tests, fixed some bugs discovered by tests

more tests, fixed some bugs discovered by tests


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/185c41a8
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/185c41a8
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/185c41a8

Branch: refs/heads/MARMOTTA-584
Commit: 185c41a85a64bf503f116b97f36d0c1ccc7231be
Parents: 0064d33
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Sat Dec 19 18:50:53 2015 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Sat Dec 19 18:50:53 2015 +0100

----------------------------------------------------------------------
 libraries/ostrich/backend/model/rdf_model.h     |   8 +-
 .../ostrich/backend/test/PersistenceTest.cc     | 100 +++++++++++++++++++
 2 files changed, 104 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/185c41a8/libraries/ostrich/backend/model/rdf_model.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/model/rdf_model.h b/libraries/ostrich/backend/model/rdf_model.h
index ee5c5bb..6793f85 100644
--- a/libraries/ostrich/backend/model/rdf_model.h
+++ b/libraries/ostrich/backend/model/rdf_model.h
@@ -89,7 +89,7 @@ class Namespace {
     /**
      * Set the prefix used to identify this namespace.
      */
-    void setPrefix(std::string &prefix) {
+    void setPrefix(const std::string &prefix) {
         internal_.set_prefix(prefix);
     }
 
@@ -103,7 +103,7 @@ class Namespace {
     /**
      * Set the URI identified by this namespace.
      */
-    void setUri(std::string &uri) {
+    void setUri(const std::string &uri) {
         internal_.set_uri(uri);
     }
 
@@ -183,7 +183,7 @@ class URI {
     /**
      * Set the string representation of the URI.
      */
-    void setUri(std::string &uri) {
+    void setUri(const std::string &uri) {
         internal_.set_uri(uri);
     }
 
@@ -279,7 +279,7 @@ class BNode {
     /**
      * Set the id of this blank node.
      */
-    void setId(std::string &id) {
+    void setId(const std::string &id) {
         internal_.set_id(id);
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/185c41a8/libraries/ostrich/backend/test/PersistenceTest.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/test/PersistenceTest.cc b/libraries/ostrich/backend/test/PersistenceTest.cc
index 301692e..8fb60c9 100644
--- a/libraries/ostrich/backend/test/PersistenceTest.cc
+++ b/libraries/ostrich/backend/test/PersistenceTest.cc
@@ -53,6 +53,42 @@ class PersistenceTest : public ::testing::Test {
     path testdir;
 };
 
+TEST_F(PersistenceTest, TestAddNamespaces) {
+    std::vector<rdf::proto::Namespace> ns = {
+            rdf::Namespace("ex", "http://www.example.com/").getMessage(),
+            rdf::Namespace("foo", "http://www.foo.com/").getMessage(),
+    };
+
+    util::CollectionIterator<rdf::proto::Namespace> it(ns);
+    db->AddNamespaces(it);
+
+    {
+        rdf::Namespace pattern;
+        pattern.setPrefix("foo");
+        auto it = db->GetNamespaces(pattern.getMessage());
+        EXPECT_TRUE(it->hasNext());
+        EXPECT_EQ(ns[1], it->next());
+        EXPECT_FALSE(it->hasNext());
+    }
+
+    {
+        rdf::Namespace pattern;
+        pattern.setPrefix("bar");
+        auto it = db->GetNamespaces(pattern.getMessage());
+        EXPECT_FALSE(it->hasNext());
+    }
+
+    {
+        rdf::Namespace pattern;
+        pattern.setUri("http://www.example.com/");
+        auto it = db->GetNamespaces(pattern.getMessage());
+        EXPECT_TRUE(it->hasNext());
+        EXPECT_EQ(ns[0], it->next());
+        EXPECT_FALSE(it->hasNext());
+    }
+}
+
+
 TEST_F(PersistenceTest, TestAddStatements) {
     std::vector<rdf::proto::Statement> stmts = {
             rdf::Statement(rdf::URI("http://example.com/s1"), rdf::URI("http://example.com/p1"),
@@ -163,6 +199,70 @@ TEST_F(PersistenceTest, TestGetStatementsFiltered) {
 }
 
 
+TEST_F(PersistenceTest, TestRemoveStatements) {
+    std::vector<rdf::proto::Statement> stmts = {
+            rdf::Statement(rdf::URI("http://example.com/s1"), rdf::URI("http://example.com/p1"),
+                           rdf::URI("http://example.com/o1")).getMessage(),
+            rdf::Statement(rdf::URI("http://example.com/s2"), rdf::URI("http://example.com/p2"),
+                           rdf::URI("http://example.com/o2")).getMessage()
+    };
+
+    util::CollectionIterator<rdf::proto::Statement> it(stmts);
+    db->AddStatements(it);
+    ASSERT_EQ(2, db->Size());
+
+    {
+        auto it1 = db->GetStatements(stmts[0]);
+        EXPECT_TRUE(it1->hasNext());
+    }
+
+    db->RemoveStatements(stmts[0]);
+    EXPECT_EQ(1, db->Size());
+
+    {
+        auto it2 = db->GetStatements(stmts[0]);
+        EXPECT_FALSE(it2->hasNext());
+    }
+
+}
+
+TEST_F(PersistenceTest, TestUpdates) {
+    std::vector<rdf::proto::Statement> stmts = {
+            rdf::Statement(rdf::URI("http://example.com/s1"), rdf::URI("http://example.com/p1"),
+                           rdf::URI("http://example.com/o1")).getMessage(),
+            rdf::Statement(rdf::URI("http://example.com/s2"), rdf::URI("http://example.com/p2"),
+                           rdf::URI("http://example.com/o2")).getMessage()
+    };
+
+    util::CollectionIterator<rdf::proto::Statement> it(stmts);
+    db->AddStatements(it);
+    ASSERT_EQ(2, db->Size());
+
+    service::proto::UpdateRequest removeReq;
+    *removeReq.mutable_stmt_removed() = stmts[0];
+    service::proto::UpdateRequest addReq;
+    *addReq.mutable_stmt_added() =
+            rdf::Statement(rdf::URI("http://example.com/s1"), rdf::URI("http://example.com/p1"),
+                           rdf::URI("http://example.com/o3")).getMessage();
+
+
+    util::CollectionIterator<service::proto::UpdateRequest> updates({ removeReq, addReq });
+    db->Update(updates);
+    ASSERT_EQ(2, db->Size());
+
+    {
+        auto it = db->GetStatements(stmts[0]);
+        EXPECT_FALSE(it->hasNext());
+    }
+
+    {
+        auto it = db->GetStatements(addReq.stmt_added());
+        EXPECT_TRUE(it->hasNext());
+    }
+
+}
+
+
 }
 }
 }