YUKI Hiroshi
null+****@clear*****
Mon Dec 10 17:50:01 JST 2012
YUKI Hiroshi 2012-12-10 17:50:01 +0900 (Mon, 10 Dec 2012) New Revision: 510d02a6f4abe86992fa16bc21b47ce76d8ea1aa https://github.com/groonga/gcs/commit/510d02a6f4abe86992fa16bc21b47ce76d8ea1aa Log: Accept XML SDF batches for documents/batch API Modified files: lib/api/2011-02-01/batch.js test/api-batch.test.js Modified: lib/api/2011-02-01/batch.js (+5 -0) =================================================================== --- lib/api/2011-02-01/batch.js 2012-12-10 17:46:19 +0900 (161de20) +++ lib/api/2011-02-01/batch.js 2012-12-10 17:50:01 +0900 (e65cc46) @@ -1,4 +1,5 @@ var BatchProcessor = require('../../batch/processor').Processor; +var xml = require('../../batch/xml'); var Domain = require('../../database').Domain; var logger = require('../../logger'); @@ -21,6 +22,7 @@ function handleInvalidContentType(request, response) { var contentType = request.headers['content-type']; switch (contentType) { case 'application/json': + case 'application/xml': return false; default: var message = contentType ? @@ -45,6 +47,9 @@ exports.createHandler = function(context, config) { if (handleInvalidContentLength(request, response)) return; var batches = request.body; + if (request.headers['content-type'] == 'application/xml') + request.headers['content-type'] = xml.toJSON(batches); + var domain = new Domain({ source: request, context: context, documentsPath: config.documentsPath }); Modified: test/api-batch.test.js (+31 -0) =================================================================== --- test/api-batch.test.js 2012-12-10 17:46:19 +0900 (64d334f) +++ test/api-batch.test.js 2012-12-10 17:50:01 +0900 (3ad2aeb) @@ -60,6 +60,37 @@ suite('documents/batch API', function() { }); }); + test('add (xml)', function(done) { + var addBatch = fs.readFileSync(__dirname + '/fixture/companies/add.sdf.xml', 'UTF-8'); + utils + .post('/2011-02-01/documents/batch', addBatch, { + 'Content-Type': 'application/xml', + 'Content-Length': addBatch.length, + 'Host': 'doc-companies-00000000000000000000000000.localhost' + }) + .next(function(response) { + var expected = { + statusCode: 200, + body: JSON.stringify({ + status: 'success', + adds: 10, + deletes: 0 + }) + }; + assert.deepEqual(response, expected); + + var dump = context.commandSync('dump', { + tables: 'companies_00000000000000000000000000' + }); + assert.equal(dump, schemeDump + '\n' + loadDump); + + done(); + }) + .error(function(error) { + done(error); + }); + }); + test('delete', function(done) { var path = '/2011-02-01/documents/batch'; utils -------------- next part -------------- HTML����������������������������... ダウンロード