From 9ffa4779e2c416576702e3d408f81a018dd6dfeb Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 10 Oct 2012 09:22:18 +0200 Subject: [PATCH] test cases for issue #213 --- .../rest-create-document-spec.rb | 68 ++++++++++- .../rest-delete-document-spec.rb | 64 ++++++++++ UnitTests/HttpInterface/rest-edge-spec.rb | 107 +++++++++++++++- .../rest-update-document-spec.rb | 70 +++++++++++ js/common/tests/shell-document.js | 114 ++++++++++++++++++ 5 files changed, 421 insertions(+), 2 deletions(-) diff --git a/UnitTests/HttpInterface/rest-create-document-spec.rb b/UnitTests/HttpInterface/rest-create-document-spec.rb index 194b9fbf42..5fe1ea191c 100644 --- a/UnitTests/HttpInterface/rest-create-document-spec.rb +++ b/UnitTests/HttpInterface/rest-create-document-spec.rb @@ -130,7 +130,7 @@ describe ArangoDB do ArangoDB.size_collection(@cid).should eq(0) end - + it "creating a new document complex body" do cmd = "/_api/document?collection=#{@cid}" body = "{ \"Hallo\" : \"Wo\\\"rld\" }" @@ -325,6 +325,72 @@ describe ArangoDB do ArangoDB.size_collection(@cid).should eq(0) end + + it "creating a new document, waitForSync URL param = false" do + cmd = "/_api/document?collection=#{@cid}&waitForSync=false" + body = "{ \"Hallo\" : \"World\" }" + doc = ArangoDB.log_post("#{prefix}-accept-sync-false", cmd, :body => body) + + doc.code.should eq(202) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + doc.parsed_response['error'].should eq(false) + + etag = doc.headers['etag'] + etag.should be_kind_of(String) + + location = doc.headers['location'] + location.should be_kind_of(String) + + rev = doc.parsed_response['_rev'] + rev.should be_kind_of(Integer) + + did = doc.parsed_response['_id'] + did.should be_kind_of(String) + + match = /([0-9]*)\/([0-9]*)/.match(did) + + match[1].should eq("#{@cid}") + + etag.should eq("\"#{rev}\"") + location.should eq("/_api/document/#{did}") + + ArangoDB.delete(location) + + ArangoDB.size_collection(@cid).should eq(0) + end + + it "creating a new document, waitForSync URL param = true" do + cmd = "/_api/document?collection=#{@cid}&waitForSync=true" + body = "{ \"Hallo\" : \"World\" }" + doc = ArangoDB.log_post("#{prefix}-accept-sync-true", cmd, :body => body) + + doc.code.should eq(201) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + doc.parsed_response['error'].should eq(false) + + etag = doc.headers['etag'] + etag.should be_kind_of(String) + + location = doc.headers['location'] + location.should be_kind_of(String) + + rev = doc.parsed_response['_rev'] + rev.should be_kind_of(Integer) + + did = doc.parsed_response['_id'] + did.should be_kind_of(String) + + match = /([0-9]*)\/([0-9]*)/.match(did) + + match[1].should eq("#{@cid}") + + etag.should eq("\"#{rev}\"") + location.should eq("/_api/document/#{did}") + + ArangoDB.delete(location) + + ArangoDB.size_collection(@cid).should eq(0) + end end ################################################################################ diff --git a/UnitTests/HttpInterface/rest-delete-document-spec.rb b/UnitTests/HttpInterface/rest-delete-document-spec.rb index 88912fa9cc..6f6c8610ee 100644 --- a/UnitTests/HttpInterface/rest-delete-document-spec.rb +++ b/UnitTests/HttpInterface/rest-delete-document-spec.rb @@ -315,6 +315,70 @@ describe ArangoDB do ArangoDB.size_collection(@cid).should eq(0) end + + it "create a document and delete it, waitForSync URL param = false" do + cmd = "/_api/document?collection=#{@cid}&waitForSync=false" + body = "{ \"Hallo\" : \"World\" }" + doc = ArangoDB.post(cmd, :body => body) + + doc.code.should eq(201) + + location = doc.headers['location'] + location.should be_kind_of(String) + + did = doc.parsed_response['_id'] + rev = doc.parsed_response['_rev'] + + # delete document + cmd = "/_api/document/#{did}" + doc = ArangoDB.log_delete("#{prefix}-sync-false", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + did2 = doc.parsed_response['_id'] + did2.should be_kind_of(String) + did2.should eq(did) + + rev2 = doc.parsed_response['_rev'] + rev2.should be_kind_of(Integer) + rev2.should eq(rev) + + ArangoDB.size_collection(@cid).should eq(0) + end + + it "create a document and delete it, waitForSync URL param = true" do + cmd = "/_api/document?collection=#{@cid}&waitForSync=true" + body = "{ \"Hallo\" : \"World\" }" + doc = ArangoDB.post(cmd, :body => body) + + doc.code.should eq(201) + + location = doc.headers['location'] + location.should be_kind_of(String) + + did = doc.parsed_response['_id'] + rev = doc.parsed_response['_rev'] + + # delete document + cmd = "/_api/document/#{did}" + doc = ArangoDB.log_delete("#{prefix}-sync-true", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + did2 = doc.parsed_response['_id'] + did2.should be_kind_of(String) + did2.should eq(did) + + rev2 = doc.parsed_response['_rev'] + rev2.should be_kind_of(Integer) + rev2.should eq(rev) + + ArangoDB.size_collection(@cid).should eq(0) + end end end diff --git a/UnitTests/HttpInterface/rest-edge-spec.rb b/UnitTests/HttpInterface/rest-edge-spec.rb index a6d4c42992..5d2324660c 100644 --- a/UnitTests/HttpInterface/rest-edge-spec.rb +++ b/UnitTests/HttpInterface/rest-edge-spec.rb @@ -189,7 +189,112 @@ describe ArangoDB do end end +################################################################################ +## known collection name, waitForSync URL param +################################################################################ + + context "known collection name:" do + before do + @ce = "UnitTestsCollectionEdge" + @eid = ArangoDB.create_collection(@ce, false, 3) # type 3 = edge collection + @cv = "UnitTestsCollectionVertex" + @vid = ArangoDB.create_collection(@cv, true, 2) # type 2 = document collection + end + + after do + ArangoDB.drop_collection(@ce) + ArangoDB.drop_collection(@cv) + end + + it "creating an edge, waitForSync URL param=false" do + # create first vertex + cmd = "/_api/document?collection=#{@vid}" + body = "{ \"a\" : 1 }" + doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(201) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id1 = doc.parsed_response['_id'] + + # create second vertex + body = "{ \"a\" : 2 }" + doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(201) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id2 = doc.parsed_response['_id'] + + # create edge + cmd = "/_api/edge?collection=#{@eid}&from=#{id1}&to=#{id2}&waitForSync=false" + body = "{}" + doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(202) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id3 = doc.parsed_response['_id'] + + # check edge + cmd = "/_api/edge/#{id3}" + doc = ArangoDB.log_get("#{prefix}-read-edge", cmd) + + doc.code.should eq(200) + doc.parsed_response['_id'].should eq(id3) + doc.parsed_response['_from'].should eq(id1) + doc.parsed_response['_to'].should eq(id2) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + end + + it "creating an edge, waitForSync URL param=true" do + # create first vertex + cmd = "/_api/document?collection=#{@vid}" + body = "{ \"a\" : 1 }" + doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(201) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id1 = doc.parsed_response['_id'] + + # create second vertex + body = "{ \"a\" : 2 }" + doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(201) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id2 = doc.parsed_response['_id'] + + # create edge + cmd = "/_api/edge?collection=#{@eid}&from=#{id1}&to=#{id2}&waitForSync=true" + body = "{}" + doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(201) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id3 = doc.parsed_response['_id'] + + # check edge + cmd = "/_api/edge/#{id3}" + doc = ArangoDB.log_get("#{prefix}-read-edge", cmd) + + doc.code.should eq(200) + doc.parsed_response['_id'].should eq(id3) + doc.parsed_response['_from'].should eq(id1) + doc.parsed_response['_to'].should eq(id2) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + end + end + end end - diff --git a/UnitTests/HttpInterface/rest-update-document-spec.rb b/UnitTests/HttpInterface/rest-update-document-spec.rb index b7cb85e8b4..e20b635243 100644 --- a/UnitTests/HttpInterface/rest-update-document-spec.rb +++ b/UnitTests/HttpInterface/rest-update-document-spec.rb @@ -345,6 +345,76 @@ describe ArangoDB do ArangoDB.size_collection(@cid).should eq(0) end + + it "create a document and update it, waitForSync URL param=false" do + cmd = "/_api/document?collection=#{@cid}&waitForSync=false" + body = "{ \"Hallo\" : \"World\" }" + doc = ArangoDB.post(cmd, :body => body) + + doc.code.should eq(201) + + location = doc.headers['location'] + location.should be_kind_of(String) + + did = doc.parsed_response['_id'] + rev = doc.parsed_response['_rev'] + + # update document + cmd = "/_api/document/#{did}" + body = "{ \"World\" : \"Hallo\" }" + doc = ArangoDB.log_put("#{prefix}-sync-false", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + did2 = doc.parsed_response['_id'] + did2.should be_kind_of(String) + did2.should eq(did) + + rev2 = doc.parsed_response['_rev'] + rev2.should be_kind_of(Integer) + rev2.should_not eq(rev) + + ArangoDB.delete(location) + + ArangoDB.size_collection(@cid).should eq(0) + end + + it "create a document and update it, waitForSync URL param=true" do + cmd = "/_api/document?collection=#{@cid}&waitForSync=true" + body = "{ \"Hallo\" : \"World\" }" + doc = ArangoDB.post(cmd, :body => body) + + doc.code.should eq(201) + + location = doc.headers['location'] + location.should be_kind_of(String) + + did = doc.parsed_response['_id'] + rev = doc.parsed_response['_rev'] + + # update document + cmd = "/_api/document/#{did}" + body = "{ \"World\" : \"Hallo\" }" + doc = ArangoDB.log_put("#{prefix}-sync-true", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + did2 = doc.parsed_response['_id'] + did2.should be_kind_of(String) + did2.should eq(did) + + rev2 = doc.parsed_response['_rev'] + rev2.should be_kind_of(Integer) + rev2.should_not eq(rev) + + ArangoDB.delete(location) + + ArangoDB.size_collection(@cid).should eq(0) + end end end diff --git a/js/common/tests/shell-document.js b/js/common/tests/shell-document.js index 1274c97d6f..4d7648997a 100644 --- a/js/common/tests/shell-document.js +++ b/js/common/tests/shell-document.js @@ -209,6 +209,28 @@ function CollectionDocumentSuite () { assertTypeOf("number", doc._rev); }, +//////////////////////////////////////////////////////////////////////////////// +/// @brief create a document, waitForSync=false +//////////////////////////////////////////////////////////////////////////////// + + testSaveDocumentSyncFalse : function () { + var doc = collection.save({ "Hallo" : "World" }, false); + + assertTypeOf("string", doc._id); + assertTypeOf("number", doc._rev); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief create a document, waitForSync=true +//////////////////////////////////////////////////////////////////////////////// + + testSaveDocumentSyncTrue : function () { + var doc = collection.save({ "Hallo" : "World" }, true); + + assertTypeOf("string", doc._id); + assertTypeOf("number", doc._rev); + }, + //////////////////////////////////////////////////////////////////////////////// /// @brief read a document //////////////////////////////////////////////////////////////////////////////// @@ -297,6 +319,38 @@ function CollectionDocumentSuite () { assertEqual(4, doc4.a); }, +//////////////////////////////////////////////////////////////////////////////// +/// @brief replace a document, waitForSync=false +//////////////////////////////////////////////////////////////////////////////// + + testReplaceDocumentSyncFalse : function () { + var a1 = collection.save({ a : 1}); + + assertTypeOf("string", a1._id); + assertTypeOf("number", a1._rev); + + var a2 = collection.replace(a1, { a : 2 }, true, false); + + assertEqual(a1._id, a2._id); + assertNotEqual(a1._rev, a2._rev); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief replace a document, waitForSync=true +//////////////////////////////////////////////////////////////////////////////// + + testReplaceDocumentSyncTrue : function () { + var a1 = collection.save({ a : 1}); + + assertTypeOf("string", a1._id); + assertTypeOf("number", a1._rev); + + var a2 = collection.replace(a1, { a : 2 }, true, true); + + assertEqual(a1._id, a2._id); + assertNotEqual(a1._rev, a2._rev); + }, + //////////////////////////////////////////////////////////////////////////////// /// @brief update a document //////////////////////////////////////////////////////////////////////////////// @@ -447,6 +501,66 @@ function CollectionDocumentSuite () { assertEqual(a4, false); }, +//////////////////////////////////////////////////////////////////////////////// +/// @brief update a document, waitForSync=false +//////////////////////////////////////////////////////////////////////////////// + + testUpdateDocumentSyncFalse : function () { + var a1 = collection.save({ a : 1}); + + assertTypeOf("string", a1._id); + assertTypeOf("number", a1._rev); + + var a2 = collection.update(a1, { a : 2 }, true, false); + + assertEqual(a1._id, a2._id); + assertNotEqual(a1._rev, a2._rev); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief update a document, waitForSync=true +//////////////////////////////////////////////////////////////////////////////// + + testUpdateDocumentSyncTrue : function () { + var a1 = collection.save({ a : 1}); + + assertTypeOf("string", a1._id); + assertTypeOf("number", a1._rev); + + var a2 = collection.update(a1, { a : 2 }, true, true); + + assertEqual(a1._id, a2._id); + assertNotEqual(a1._rev, a2._rev); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief delete a document, waitForSync=false +//////////////////////////////////////////////////////////////////////////////// + + testDeleteDocumentSyncFalse : function () { + var a1 = collection.save({ a : 1}); + + assertTypeOf("string", a1._id); + assertTypeOf("number", a1._rev); + + var a2 = collection.remove(a1, true, false); + assertEqual(a2, true); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief delete a document, waitForSync=true +//////////////////////////////////////////////////////////////////////////////// + + testDeleteDocumentSyncTrue : function () { + var a1 = collection.save({ a : 1}); + + assertTypeOf("string", a1._id); + assertTypeOf("number", a1._rev); + + var a2 = collection.remove(a1, true, true); + assertEqual(a2, true); + }, + //////////////////////////////////////////////////////////////////////////////// /// @brief delete a deleted document ////////////////////////////////////////////////////////////////////////////////