mirror of https://gitee.com/bigwinds/arangodb
fix wrong tests
This commit is contained in:
parent
23968dd94e
commit
7ef0fe6119
|
@ -71,4 +71,4 @@ UnitTests/Philadelphia/Runner.cpp
|
|||
UnitTests/test_suite
|
||||
.v8-build
|
||||
VC++
|
||||
UnitTests/RestDocuments/*.log
|
||||
UnitTests/RestDocuments/logs
|
||||
|
|
|
@ -252,6 +252,7 @@ bool RestDocumentHandler::createDocument () {
|
|||
int res = useCollection(collection, create);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
releaseCollection();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -377,6 +378,7 @@ bool RestDocumentHandler::readSingleDocument (bool generateBody) {
|
|||
int res = useCollection(collection);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
releaseCollection();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -400,7 +402,7 @@ bool RestDocumentHandler::readSingleDocument (bool generateBody) {
|
|||
|
||||
// generate result
|
||||
if (document._did == 0) {
|
||||
generateDocumentNotFound(cid + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + did);
|
||||
generateDocumentNotFound(cid, did);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -468,6 +470,7 @@ bool RestDocumentHandler::readAllDocuments () {
|
|||
int res = useCollection(collection);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
releaseCollection();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -669,6 +672,7 @@ bool RestDocumentHandler::updateDocument () {
|
|||
int res = useCollection(collection);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
releaseCollection();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -706,7 +710,7 @@ bool RestDocumentHandler::updateDocument () {
|
|||
return false;
|
||||
|
||||
case TRI_ERROR_AVOCADO_DOCUMENT_NOT_FOUND:
|
||||
generateDocumentNotFound(cid + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + didStr);
|
||||
generateDocumentNotFound(cid, didStr);
|
||||
return false;
|
||||
|
||||
case TRI_ERROR_AVOCADO_CONFLICT:
|
||||
|
@ -803,6 +807,7 @@ bool RestDocumentHandler::deleteDocument () {
|
|||
int res = useCollection(collection);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
releaseCollection();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -839,7 +844,7 @@ bool RestDocumentHandler::deleteDocument () {
|
|||
return false;
|
||||
|
||||
case TRI_ERROR_AVOCADO_DOCUMENT_NOT_FOUND:
|
||||
generateDocumentNotFound(cid + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + didStr);
|
||||
generateDocumentNotFound(cid, didStr);
|
||||
return false;
|
||||
|
||||
case TRI_ERROR_AVOCADO_CONFLICT:
|
||||
|
|
|
@ -248,10 +248,12 @@ void RestVocbaseBaseHandler::generateCollectionNotFound (string const& cid) {
|
|||
/// @brief generates document not found error message
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestVocbaseBaseHandler::generateDocumentNotFound (string const& handle) {
|
||||
void RestVocbaseBaseHandler::generateDocumentNotFound (TRI_voc_cid_t cid, string const& did) {
|
||||
string location = DOCUMENT_PATH + "/" + StringUtils::itoa(cid) + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + did;
|
||||
|
||||
generateError(HttpResponse::NOT_FOUND,
|
||||
TRI_ERROR_AVOCADO_DOCUMENT_NOT_FOUND,
|
||||
"document " + DOCUMENT_PATH + "/" + handle + " not found");
|
||||
"document " + location + " not found");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -179,7 +179,7 @@ namespace triagens {
|
|||
/// @brief generates document not found error message
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void generateDocumentNotFound (string const& handle);
|
||||
void generateDocumentNotFound (TRI_voc_cid_t, string const& did);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates conflict message
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief over the wire protocol
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2012 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @page HttpCollectionTOC
|
||||
///
|
||||
/// <ol>
|
||||
/// <li>@ref RestDocumentIntro</li>
|
||||
/// <li>@ref RestDocumentResource</li>
|
||||
/// <li>@ref RestDocumentHttp
|
||||
/// <ol>
|
||||
/// <li>@ref RestDocumentRead "GET /document/@FA{document-handle}"</li>
|
||||
/// <li>@ref RestDocumentCreate "POST /document?collection=@FA{collection-identifier}"</li>
|
||||
/// <li>@ref RestDocumentUpdate "PUT /document/@FA{document-handle}"</li>
|
||||
/// <li>@ref RestDocumentDelete "DELETE /document/@FA{document-handle}"</li>
|
||||
/// <li>@ref RestDocumentHead "HEAD /document/@FA{document-handle}"</li>
|
||||
/// <li>@ref RestDocumentReadAll "GET /document?collection=@FA{collection-identifier}"</li>
|
||||
/// </ol>
|
||||
/// </li>
|
||||
/// </ol>
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @page HttpCollection Http Interface for Collections
|
||||
///
|
||||
/// This is an introduction to AvocadoDB's Http interface to documents.
|
||||
///
|
||||
/// <hr>
|
||||
/// @copydoc HttpCollectionTOC
|
||||
/// <hr>
|
||||
///
|
||||
/// @section HttpCollectionIntro Dealing with Collections
|
||||
/////////////////////////////////////////////////////////
|
||||
///
|
||||
/// @copydoc GlossaryCollection
|
||||
///
|
||||
/// @copydoc GlossaryCollectionIdentifier
|
||||
///
|
||||
/// The basic operations (create, read, update, delete) for documents are mapped
|
||||
/// to the standard HTTP methods (POST, GET, PUT, DELETE).
|
||||
///
|
||||
/// @section HttpCollectionResource Address of an Collection
|
||||
////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// All collections in AvocadoDB have a document indentifier. This
|
||||
/// collection identifier uniquely defines a collection and is managed
|
||||
/// by AvocadoDB. All collections are found under the URI
|
||||
///
|
||||
/// @LIT{http://@FA{server}:@FA{port}/_api/collection/@FA{collection-identifier}}
|
||||
///
|
||||
/// For exmaple: Assume that the collection identifier is @LIT{7254820},
|
||||
/// then the URL of that collection is:
|
||||
///
|
||||
/// @LIT{http://localhost:8529/_api/collection/7254820}
|
||||
///
|
||||
/// @section HttpCollectionHttp Working with Collections using HTTP
|
||||
///////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// @anchor RestDocumentRead
|
||||
/// @copydetails triagens::avocado::RestDocumentHandler::readSingleDocument
|
||||
/// <hr>
|
||||
///
|
||||
/// @anchor RestDocumentCreate
|
||||
/// @copydetails triagens::avocado::RestDocumentHandler::createDocument
|
||||
/// <hr>
|
||||
///
|
||||
/// @anchor RestDocumentUpdate
|
||||
/// @copydetails triagens::avocado::RestDocumentHandler::updateDocument
|
||||
/// <hr>
|
||||
///
|
||||
/// @anchor RestDocumentDelete
|
||||
/// @copydetails triagens::avocado::RestDocumentHandler::deleteDocument
|
||||
/// <hr>
|
||||
///
|
||||
/// @anchor RestDocumentHead
|
||||
/// @copydetails triagens::avocado::RestDocumentHandler::checkDocument
|
||||
/// <hr>
|
||||
///
|
||||
/// @anchor RestDocumentReadAll
|
||||
/// @copydetails triagens::avocado::RestDocumentHandler::readAllDocuments
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Local Variables:
|
||||
// mode: c++
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -28,6 +28,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @page Glossary
|
||||
///
|
||||
/// @copydoc GlossaryCollection
|
||||
///
|
||||
/// @copydoc GlossaryCollectionIdentifier
|
||||
///
|
||||
/// @copydoc GlossaryDocument
|
||||
|
@ -38,6 +40,11 @@
|
|||
///
|
||||
/// @copydoc GlossaryDocumentRevision
|
||||
///
|
||||
/// @page GlossaryCollection
|
||||
///
|
||||
/// @GE{Collection}: A collection consists of documents. It is uniquely identified
|
||||
/// by it's collection identifier. It also has a unique name.
|
||||
///
|
||||
/// @page GlossaryCollectionIdentifier
|
||||
///
|
||||
/// @GE{Collection Identifier}: A collection identifier identifies a collection
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @page RestDocument REST Interface for Documents
|
||||
///
|
||||
/// This is an introduction to AvocadoDB's REST interface to documents.
|
||||
/// This is an introduction to AvocadoDB's REST interface for documents.
|
||||
///
|
||||
/// <hr>
|
||||
/// @copydoc RestDocumentTOC
|
||||
|
|
|
@ -30,7 +30,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-missing-handle")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-missing-handle")
|
||||
end
|
||||
|
||||
it "returns an error if document handle is corrupted" do
|
||||
|
@ -43,7 +43,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle")
|
||||
end
|
||||
|
||||
it "returns an error if document handle is corrupted" do
|
||||
|
@ -56,7 +56,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle2")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle2")
|
||||
end
|
||||
|
||||
it "returns an error if collection identifier is unknown" do
|
||||
|
@ -69,7 +69,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
end
|
||||
|
||||
it "returns an error if document handle is unknown" do
|
||||
|
@ -82,7 +82,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-unknown-handle")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-unknown-handle")
|
||||
end
|
||||
|
||||
it "returns an error if the policy parameter is bad" do
|
||||
|
@ -107,7 +107,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['error'].should eq(true)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-policy-bad")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-policy-bad")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
|
@ -158,7 +158,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -193,7 +193,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other")
|
||||
|
||||
# delete document, same revision
|
||||
cmd = "/document/#{did}"
|
||||
|
@ -208,12 +208,11 @@ describe AvocadoDB do
|
|||
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)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-if-match")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-if-match")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -248,7 +247,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other-last-write")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other-last-write")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -282,7 +281,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-rev-other")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-rev-other")
|
||||
|
||||
# delete document, same revision
|
||||
cmd = "/document/#{did}?rev=#{rev}"
|
||||
|
@ -301,7 +300,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-rev")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :result => doc, :output => "#{prefix}-rev")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -336,7 +335,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-rev-other-last-write")
|
||||
AvocadoDB.log(:method => :delete, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-rev-other-last-write")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-missing-handle")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-missing-handle")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -63,7 +63,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle2")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle2")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -79,7 +79,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -95,7 +95,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-handle")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-handle")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -113,7 +113,7 @@ describe AvocadoDB do
|
|||
did = doc.parsed_response['_id']
|
||||
rev = doc.parsed_response['_rev']
|
||||
|
||||
# delete document, different revision
|
||||
# update document, different revision
|
||||
cmd = "/document/#{did}?policy=last-write"
|
||||
hdr = { "if-match" => "\"#{rev-1}\"" }
|
||||
doc = AvocadoDB.put(cmd, :headers => hdr)
|
||||
|
@ -122,7 +122,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['error'].should eq(true)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-policy-bad")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :headers => hdr, :result => doc, :output => "#{prefix}-policy-bad")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
|
@ -174,7 +174,7 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should_not eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
|
@ -212,13 +212,13 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other")
|
||||
|
||||
# update document, same revision
|
||||
cmd = "/document/#{did}"
|
||||
hdr = { "if-match" => "\"#{rev}\"" }
|
||||
body = "{ \"World\" : \"Hallo\" }"
|
||||
doc = AvocadoDB.delete(cmd, :headers => hdr, :body => body)
|
||||
doc = AvocadoDB.put(cmd, :headers => hdr, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
@ -227,13 +227,14 @@ describe AvocadoDB do
|
|||
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)
|
||||
rev2.should_not eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :headers => hdr, :result => doc, :output => "#{prefix}-if-match")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :headers => hdr, :result => doc, :output => "#{prefix}-if-match")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -251,11 +252,11 @@ describe AvocadoDB do
|
|||
did = doc.parsed_response['_id']
|
||||
rev = doc.parsed_response['_rev']
|
||||
|
||||
# delete document, different revision
|
||||
# update document, different revision
|
||||
cmd = "/document/#{did}?policy=last"
|
||||
hdr = { "if-match" => "\"#{rev-1}\"" }
|
||||
body = "{ \"World\" : \"Hallo\" }"
|
||||
doc = AvocadoDB.delete(cmd, :headers => hdr, :body => body)
|
||||
doc = AvocadoDB.put(cmd, :headers => hdr, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
@ -267,9 +268,11 @@ describe AvocadoDB do
|
|||
|
||||
rev2 = doc.parsed_response['_rev']
|
||||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
rev2.should_not eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other-last-write")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :headers => hdr, :result => doc, :output => "#{prefix}-if-match-other-last-write")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -304,12 +307,12 @@ describe AvocadoDB do
|
|||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-rev-other")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-rev-other")
|
||||
|
||||
# update document, same revision
|
||||
cmd = "/document/#{did}?rev=#{rev}"
|
||||
body = "{ \"World\" : \"Hallo\" }"
|
||||
doc = AvocadoDB.delete(cmd, :body => body)
|
||||
doc = AvocadoDB.put(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
@ -318,13 +321,14 @@ describe AvocadoDB do
|
|||
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)
|
||||
rev2.should_not eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-rev")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-rev")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -342,10 +346,10 @@ describe AvocadoDB do
|
|||
did = doc.parsed_response['_id']
|
||||
rev = doc.parsed_response['_rev']
|
||||
|
||||
# delete document, different revision
|
||||
# update document, different revision
|
||||
cmd = "/document/#{did}?policy=last&rev=#{rev-1}"
|
||||
body = "{ \"World\" : \"Hallo\" }"
|
||||
doc = AvocadoDB.delete(cmd, :body => body)
|
||||
doc = AvocadoDB.put(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
@ -357,9 +361,11 @@ describe AvocadoDB do
|
|||
|
||||
rev2 = doc.parsed_response['_rev']
|
||||
rev2.should be_kind_of(Integer)
|
||||
rev2.should eq(rev)
|
||||
rev2.should_not eq(rev)
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-rev-other-last-write")
|
||||
AvocadoDB.log(:method => :put, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-rev-other-last-write")
|
||||
|
||||
AvocadoDB.delete(location)
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief querying and managing collections
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2012 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Achim Brandt
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var actions = require("actions");
|
||||
var API = "_api/";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup AvocadoAPI
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a collection
|
||||
///
|
||||
/// @REST{GET /_api/collection/@FA{collection-identifier}}
|
||||
///
|
||||
/// The result is an objects describing the collection with the following
|
||||
/// attributes:
|
||||
///
|
||||
/// @FA{id}
|
||||
///
|
||||
/// The identifier of the collection.
|
||||
///
|
||||
/// @FA{name}
|
||||
///
|
||||
/// The name of the collection.
|
||||
///
|
||||
/// If the @FA{collection-identifier} is missing, then a @LIT{HTTP 400} is
|
||||
/// returned. If the @FA{collection-identifier} is unknown, then a @LIT{HTTP
|
||||
/// 404} is returned. It is possible to specify a name instead of an identifier.
|
||||
/// In this case the response will contain a field "Location" which contains the
|
||||
/// correct location.
|
||||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// Using an identifier:
|
||||
///
|
||||
/// @verbinclude api_database3
|
||||
///
|
||||
/// Using a name:
|
||||
///
|
||||
/// @verbinclude api_database2
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function GET_api_collection (req, res) {
|
||||
if (req.suffix.length != 1) {
|
||||
actions.resultBad(req, res, actions.ERROR_HTTP_BAD_PARAMETER,
|
||||
"expect GET /" + API + "collection/<collection-identifer>")
|
||||
}
|
||||
else {
|
||||
var name = req.suffix[0];
|
||||
var id = parseInt(name) || name;
|
||||
var collection = db._collection(name);
|
||||
|
||||
if (collection == null) {
|
||||
actions.collectionUnknown(req, res, name);
|
||||
}
|
||||
else {
|
||||
var result = {};
|
||||
|
||||
result.id = collection._id;
|
||||
result.name = collection._name;
|
||||
|
||||
actions.resultOk(req, res, actions.HTTP_OK, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief reads or creates a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
actions.defineHttp({
|
||||
url : API + "collection",
|
||||
context : "api",
|
||||
|
||||
callback : function (req, res) {
|
||||
if (req.requestType == actions.GET) {
|
||||
GET_api_collection(req, res);
|
||||
}
|
||||
/*
|
||||
else if (req.requestType == actions.POST) {
|
||||
POST_api_database_collection(req, res);
|
||||
}
|
||||
*/
|
||||
else {
|
||||
actions.resultUnsupported(req, res);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||
// End:
|
|
@ -26,7 +26,7 @@ function getCollection(req, res) {
|
|||
}
|
||||
|
||||
actions.defineHttp({
|
||||
url : "_api/collection",
|
||||
url : "_api/collection_OLD",
|
||||
context : "api",
|
||||
|
||||
callback : function (req, res) {
|
||||
|
|
|
@ -28,37 +28,6 @@
|
|||
var internal = require("internal");
|
||||
var console = require("console");
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public constants
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup AvocadoActions
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief error codes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.errorQuerySpecificationInvalid = 1512;
|
||||
exports.errorCursorNotFound = 1600;
|
||||
|
||||
exports.errorInvalidRequest = 1700;
|
||||
exports.errorJavascriptException = 1701;
|
||||
|
||||
exports.collectionNotFound = 20404;
|
||||
exports.documentNotFound = 30404;
|
||||
exports.documentNotModified = 30304;
|
||||
|
||||
exports.keyValueNotFound = 41404;
|
||||
exports.keyValueNotModified = 41304;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -249,13 +218,16 @@ function actionError (req, res, err) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a result
|
||||
///
|
||||
/// @FUN{actionResultOK(@FA{req}, @FA{res}, @FA{code}, @FA{result}, @FA{headers}})}
|
||||
/// @FUN{actions.resultOk(@FA{req}, @FA{res}, @FA{code}, @FA{result}, @FA{headers}})}
|
||||
///
|
||||
/// Works like @FN{actionResult} but adds the attribute @LIT{error} with
|
||||
/// value @LIT{false} and @LIT{code} with value @FA{code} to the @FA{result}.
|
||||
/// The functions defines a response. @FA{code} is the status code to
|
||||
/// return. @FA{result} is the result object, which will be returned as JSON
|
||||
/// object in the body. @LIT{headers} is an array of headers to returned.
|
||||
/// The function adds the attribute @LIT{error} with value @LIT{false}
|
||||
/// and @LIT{code} with value @FA{code} to the @FA{result}.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function actionResultOK (req, res, httpReturnCode, result, headers) {
|
||||
function ResultOk (req, res, httpReturnCode, result, headers) {
|
||||
res.responseCode = httpReturnCode;
|
||||
res.contentType = "application/json";
|
||||
|
||||
|
@ -320,6 +292,18 @@ function actionResultError (req, res, httpReturnCode, errorNum, errorMessage, he
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates an error for a bad request
|
||||
///
|
||||
/// @FUN{badParameter(@FA{req}, @FA{res}, @FA{error-code}, @{msg}, @FA{headers})}
|
||||
///
|
||||
/// The functions generates an error response.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function ResultBad (req, res, code, msg, headers) {
|
||||
actionResultError(req, res, exports.BAD, code, msg, headers);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates an error for unsupported methods
|
||||
///
|
||||
|
@ -379,15 +363,19 @@ function collectionUnknown (req, res, collection, headers) {
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.resultBad = ResultBad;
|
||||
exports.resultOk = ResultOk;
|
||||
|
||||
|
||||
exports.defineHttp = defineHttp;
|
||||
exports.actionResult = actionResult;
|
||||
exports.actionResultOK = actionResultOK;
|
||||
exports.actionResultOK = ResultOk;
|
||||
exports.actionResultError = actionResultError;
|
||||
exports.actionResultUnsupported = actionResultUnsupported;
|
||||
exports.actionError = actionError;
|
||||
exports.resultOK = ResultOk;
|
||||
|
||||
exports.result = actionResult;
|
||||
exports.resultOK = actionResultOK;
|
||||
exports.unsupported = actionResultUnsupported;
|
||||
exports.error = actionResultError;
|
||||
|
||||
|
@ -413,9 +401,6 @@ exports.HTTP_NOT_FOUND = 404;
|
|||
exports.HTTP_METHOD_NOT_ALLOWED = 405;
|
||||
exports.HTTP_CONFLICT = 409;
|
||||
|
||||
// VOC ERRORS
|
||||
exports.VERR_COLLECTION_EXISTS = 1205;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue