1
0
Fork 0

test cases for issue #213

This commit is contained in:
Jan Steemann 2012-10-10 09:22:18 +02:00
parent 957d4d7402
commit 9ffa4779e2
5 changed files with 421 additions and 2 deletions

View File

@ -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
################################################################################

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
////////////////////////////////////////////////////////////////////////////////