1
0
Fork 0

update test

This commit is contained in:
Jan Christoph Uhde 2016-08-04 15:02:04 +02:00
parent 01c1c09d5a
commit 3c4db6783c
5 changed files with 78 additions and 31 deletions

View File

@ -47,7 +47,7 @@ function RequestSuite () {
append = append || ''; append = append || '';
return arango.getEndpoint().replace(/^tcp:/, 'http:').replace(/^ssl:/, 'https:') + base + append; return arango.getEndpoint().replace(/^tcp:/, 'http:').replace(/^ssl:/, 'https:') + base + append;
}; };
var buildUrlBroken = function (append) { var buildUrlBroken = function (append) {
return arango.getEndpoint().replace(/^tcp:/, 'http:').replace(/^ssl:/, 'https:') + '/_not-there' + append; return arango.getEndpoint().replace(/^tcp:/, 'http:').replace(/^ssl:/, 'https:') + '/_not-there' + append;
}; };
@ -57,51 +57,88 @@ function RequestSuite () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief test http DELETE /// @brief test http DELETE
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
versionHttp: function () { testVersionJsonJson: function () {
var path = '/_api/version'; var path = '/_api/version';
var headers = { var headers = {
'content-type': 'application/x-velocypack', 'content-type': 'application/json',
'content-type': 'application/x-velocypack' 'accept' : 'application/json'
}; };
var res = request.post(buildUrl(path), {headers : headers, timeout: 300}); //var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
var res = request.post(path, {headers : headers, timeout: 300});
expect(res).to.be.a(request.Response); expect(res).to.be.a(request.Response);
expect(res.body).to.be.a('string'); expect(res.body).to.be.a('string');
expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length); expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
var obj = JSON.parse(res.body); var obj = JSON.parse(res.body);
expect(obj.path).to.equal(path); var expected = { "server" : "arango" , "version" : "3.0.x-devel" };
//expect(JSON.stringify(obj)).to.equal(JSON.stringify(expected));
expect(obj).to.eql(expected);
}, },
versionHttpVpack: function () { // testVersionVpackJson: function () {
// var path = '/_api/version';
// var headers = {
// 'content-type': 'application/x-velocypack',
// 'accept' : 'application/json'
// };
// var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
//
// expect(res).to.be.a(request.Response);
// expect(res.body).to.be.a('string');
// expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
// var obj = JSON.parse(res.body);
// expect(obj.path).to.equal(path);
// },
//
testVersionJsonVpack: function () {
var path = '/_api/version'; var path = '/_api/version';
var headers = { var headers = {
'content-type': 'application/x-velocypack', 'content-type': 'application/json',
'content-type': 'application/x-velocypack' 'accept' : 'application/x-velocypack'
}; };
var res = request.post(buildUrl(path), {headers : headers, timeout: 300}); //var res = request.post(buildUrl(path,false), {headers : headers, timeout: 300});
var res = request.post(path, {headers : headers, timeout: 300});
expect(res).to.be.a(request.Response);
expect(res.body).to.be.a('string');
expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
var obj = JSON.parse(res.body);
expect(obj.path).to.equal(path);
},
vpackEcho: function () {
var path = '/_admin/echo';
var body = "foooo"
var res = request.post(buildUrl(path),{ headers : headers, body : body, timeout: 300});
expect(res).to.be.a(request.Response); expect(res).to.be.a(request.Response);
expect(res.body).to.be.a('string'); expect(res.body).to.be.a('string');
expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length); expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
var expected = "velocypack blablba echt scheisse" ;
require("internal").print(JSON.stringify(res.body));
require("internal").print(JSON.stringify(expected));
//var obj = JSON.parse(res.body); //var obj = JSON.parse(res.body);
expect(res.body).to.equal(body); expect(res.body).to.eql(expected);
} },
//
// testVersionVpackVpack: function () {
// var path = '/_api/version';
// var headers = {
// 'content-type': 'application/x-velocypack',
// 'accept' : 'application/x-velocypack'
// };
// var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
//
// expect(res).to.be.a(request.Response);
// expect(res.body).to.be.a('string');
// expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
// var obj = JSON.parse(res.body);
// expect(obj.path).to.equal(path);
// },
//
// ///////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////
//
// testVpackEcho: function () {
// var path = '/_admin/echo';
// var body = "foooo"
// var res = request.post(buildUrl(path),{ headers : headers, body : body, timeout: 300});
//
// expect(res).to.be.a(request.Response);
// expect(res.body).to.be.a('string');
// expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
// //var obj = JSON.parse(res.body);
// expect(res.body).to.equal(body);
// }

View File

@ -75,7 +75,15 @@ class GeneralRequest {
}; };
enum class ProtocolVersion { HTTP_1_0, HTTP_1_1, VPP_1_0, UNKNOWN }; enum class ProtocolVersion { HTTP_1_0, HTTP_1_1, VPP_1_0, UNKNOWN };
enum class ContentType { UNSET, VPACK, JSON }; enum class ContentType {
CUSTOM, // use Content-Type from _headers
JSON, // application/json
VPACK, // application/x-velocypack
TEXT, // text/plain
HTML, // text/html
DUMP, // application/x-arango-dump
UNSET
};
public: public:
// translate the HTTP protocol version // translate the HTTP protocol version

View File

@ -106,7 +106,8 @@ class GeneralResponse {
VPACK, // application/x-velocypack VPACK, // application/x-velocypack
TEXT, // text/plain TEXT, // text/plain
HTML, // text/html HTML, // text/html
DUMP // application/x-arango-dump DUMP, // application/x-arango-dump
UNSET
}; };
enum ConnectionType { enum ConnectionType {

View File

@ -69,7 +69,7 @@ HttpRequest::HttpRequest(
_vpackBuilder(nullptr), _vpackBuilder(nullptr),
_headers(headers) { _headers(headers) {
_contentType = contentType; _contentType = contentType;
_contentTypeResponse = ContentType::JSON; _contentTypeResponse = contentType;
} }
void HttpRequest::parseHeader(size_t length) { void HttpRequest::parseHeader(size_t length) {

View File

@ -232,6 +232,7 @@ void HttpResponse::writeHeader(StringBuffer* output) {
// add "Content-Type" header // add "Content-Type" header
switch (_contentType) { switch (_contentType) {
case ContentType::UNSET:
case ContentType::JSON: case ContentType::JSON:
output->appendText(TRI_CHAR_LENGTH_PAIR( output->appendText(TRI_CHAR_LENGTH_PAIR(
"Content-Type: application/json; charset=utf-8\r\n")); "Content-Type: application/json; charset=utf-8\r\n"));
@ -300,7 +301,7 @@ void HttpResponse::writeHeader(StringBuffer* output) {
void HttpResponse::setPayload(GeneralRequest const* request, void HttpResponse::setPayload(GeneralRequest const* request,
arangodb::velocypack::Slice const& slice, arangodb::velocypack::Slice const& slice,
bool generateBody, VPackOptions const& options){ bool generateBody, VPackOptions const& options) {
// VELOCYPACK // VELOCYPACK
if (request != nullptr && request->velocyPackResponse()) { if (request != nullptr && request->velocyPackResponse()) {
setContentType(HttpResponse::ContentType::VPACK); setContentType(HttpResponse::ContentType::VPACK);