marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sschaff...@apache.org
Subject marmotta git commit: more tests, fixed some bugs discovered by tests
Date Sat, 19 Dec 2015 17:49:25 GMT
Repository: marmotta
Updated Branches:
  refs/heads/develop 0064d3358 -> 185c41a85


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/develop
Commit: 185c41a85a64bf503f116b97f36d0c1ccc7231be
Parents: 0064d33
Author: Sebastian Schaffert <sschaffert@apache.org>
Authored: Sat Dec 19 18:50:53 2015 +0100
Committer: Sebastian Schaffert <sschaffert@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());
+    }
+
+}
+
+
 }
 }
 }


Mime
View raw message