From b8f694ec0a3e51280a523d6898a0d24c2ab5c00d Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 31 Aug 2012 13:31:16 +0200 Subject: [PATCH] issue #178: added test cases for arangoimp --- Makefile.in | 31 ++++++- UnitTests/Makefile.files | 32 ++++++- UnitTests/import-1.csv | 6 ++ UnitTests/import-1.json | 12 +++ UnitTests/import-2.csv | 2 + UnitTests/import-2.json | 8 ++ js/server/tests/import-setup.js | 40 +++++++++ js/server/tests/import.js | 148 ++++++++++++++++++++++++++++++++ 8 files changed, 277 insertions(+), 2 deletions(-) create mode 100644 UnitTests/import-1.csv create mode 100644 UnitTests/import-1.json create mode 100644 UnitTests/import-2.csv create mode 100644 UnitTests/import-2.json create mode 100644 js/server/tests/import-setup.js create mode 100644 js/server/tests/import.js diff --git a/Makefile.in b/Makefile.in index 3b59398eb3..772e39f3ef 100644 --- a/Makefile.in +++ b/Makefile.in @@ -5332,7 +5332,8 @@ unittests-brief: \ unittests-shell-server-ahuacatl \ unittests-http-server \ unittests-ssl-server \ - unittests-shell-client + unittests-shell-client \ + unittests-import unittests-verbose: @echo "################################################################################" @@ -5475,6 +5476,34 @@ unittests-shell-client: ################################################################################ ################################################################################ +.PHONY: unittests-import + +unittests-import: + $(MAKE) start-server PID=$(PID) SERVER_START="--server.endpoint unix://$(VOCDIR)/arango.sock --server.disable-authentication true" PROTO=unix + + @echo + @echo "================================================================================" + @echo "<< IMPORT TESTS >>" + @echo "================================================================================" + @echo + + $(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1" + for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.json --collection UnitTestsImportJson$$i --create-collection true --type json || test "x$(FORCE)" == "x1"; done + for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.csv --collection UnitTestsImportCsv$$i --create-collection true --type csv || test "x$(FORCE)" == "x1"; done + $(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import.js || test "x$(FORCE)" == "x1" + $(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1" + + kill `cat $(PIDFILE)` + + while test -f $(PIDFILE); do sleep 1; done + @if [ "$(VALGRIND)" != "" ]; then sleep 60; fi + + @rm -rf "$(VOCDIR)" + @echo + +################################################################################ +################################################################################ + .PHONY: unittests-http-server unittests-http-server: diff --git a/UnitTests/Makefile.files b/UnitTests/Makefile.files index 47a5e86da4..903cb3a463 100755 --- a/UnitTests/Makefile.files +++ b/UnitTests/Makefile.files @@ -33,7 +33,8 @@ unittests-brief: \ unittests-shell-server-ahuacatl \ unittests-http-server \ unittests-ssl-server \ - unittests-shell-client + unittests-shell-client \ + unittests-import unittests-verbose: @echo "################################################################################" @@ -322,6 +323,35 @@ unittests-shell-client: @rm -rf "$(VOCDIR)" @echo +################################################################################ +## IMPORT TESTS +################################################################################ + +.PHONY: unittests-import + +unittests-import: + $(MAKE) start-server PID=$(PID) SERVER_START="--server.endpoint unix://$(VOCDIR)/arango.sock --server.disable-authentication true" PROTO=unix + + @echo + @echo "================================================================================" + @echo "<< IMPORT TESTS >>" + @echo "================================================================================" + @echo + + $(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1" + for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.json --collection UnitTestsImportJson$$i --create-collection true --type json || test "x$(FORCE)" == "x1"; done + for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.csv --collection UnitTestsImportCsv$$i --create-collection true --type csv || test "x$(FORCE)" == "x1"; done + $(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import.js || test "x$(FORCE)" == "x1" + $(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1" + + kill `cat $(PIDFILE)` + + while test -f $(PIDFILE); do sleep 1; done + @if [ "$(VALGRIND)" != "" ]; then sleep 60; fi + + @rm -rf "$(VOCDIR)" + @echo + ################################################################################ ## HTTP SERVER TESTS ################################################################################ diff --git a/UnitTests/import-1.csv b/UnitTests/import-1.csv new file mode 100644 index 0000000000..aac9bb0967 --- /dev/null +++ b/UnitTests/import-1.csv @@ -0,0 +1,6 @@ +"id","a","b","c","d","e" + +1,"1",1,"1.3",null,-5 +2,null,"",3.1,-2.5,"ddd "" ' ffd" +3,"this","is" +4,let's,see,what,happens diff --git a/UnitTests/import-1.json b/UnitTests/import-1.json new file mode 100644 index 0000000000..490ea80357 --- /dev/null +++ b/UnitTests/import-1.json @@ -0,0 +1,12 @@ +{"id": 1, "one":1, "two": 2, "three": 3} +{"id": 2, "a" : 1234, "b": "the quick fox", "jumped": "over the fox", "null": null } + + +{"id": 3, "spacing" : "is", "not": "important" } +{"id": 4, "a": true, "b": false, " c " : "h\"'ihi", "d" : "" } +{"id" : 5 } + +{"id": 6, "this \" should be enough'"} +{"id": 7, "a" : 1234, "b": "the quick fox", "jumped: "over the fox", "null": null } + +{"id" : 8, "i am" : broken } diff --git a/UnitTests/import-2.csv b/UnitTests/import-2.csv new file mode 100644 index 0000000000..289264e35c --- /dev/null +++ b/UnitTests/import-2.csv @@ -0,0 +1,2 @@ + +1,2,3,4,5,6 diff --git a/UnitTests/import-2.json b/UnitTests/import-2.json new file mode 100644 index 0000000000..bd4c8aefad --- /dev/null +++ b/UnitTests/import-2.json @@ -0,0 +1,8 @@ + +{"id": 1, "value" : -445.4 } + +{"id": 2, "value" : 3.4e4 } + + +{"id": 3, "value" : null } + diff --git a/js/server/tests/import-setup.js b/js/server/tests/import-setup.js new file mode 100644 index 0000000000..60bf624445 --- /dev/null +++ b/js/server/tests/import-setup.js @@ -0,0 +1,40 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief setup stuff for import tests +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-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 Jan Steemann +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var internal = require("internal"); + +internal.db._drop("UnitTestsImportJson1"); +internal.db._drop("UnitTestsImportJson2"); +internal.db._drop("UnitTestsImportCsv1"); +internal.db._drop("UnitTestsImportCsv2"); + +return true; + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: diff --git a/js/server/tests/import.js b/js/server/tests/import.js new file mode 100644 index 0000000000..e544334fa1 --- /dev/null +++ b/js/server/tests/import.js @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief tests for query language, arithmetic operators +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-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 Jan Steemann +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var internal = require("internal"); +var jsunity = require("jsunity"); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite +//////////////////////////////////////////////////////////////////////////////// + +function importTestSuite () { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief execute a given query +//////////////////////////////////////////////////////////////////////////////// + + function executeQuery (query) { + var statement = internal.db._createStatement({"query": query}); + var cursor = statement.execute(); + return cursor; + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief execute a given query and return the results as an array +//////////////////////////////////////////////////////////////////////////////// + + function getQueryResults (query) { + var result = executeQuery(query); + var results = [ ]; + + while (result.hasNext()) { + var keys = [ ]; + var row = result.next(); + for (var k in row) { + if (row.hasOwnProperty(k) && k != '_id' && k != '_rev') { + keys.push(k); + } + } + + keys.sort(); + var resultRow = { }; + for (var k in keys) { + if (keys.hasOwnProperty(k)) { + resultRow[keys[k]] = row[keys[k]]; + } + } + + results.push(resultRow); + } + + return results; + } + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief set up +//////////////////////////////////////////////////////////////////////////////// + + setUp : function () { + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tear down +//////////////////////////////////////////////////////////////////////////////// + + tearDown : function () { + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test json import +//////////////////////////////////////////////////////////////////////////////// + + testJsonImport1 : function () { + var expected = [ { "id": 1, "one": 1, "three": 3, "two": 2 }, { "a": 1234, "b": "the quick fox", "id": 2, "jumped": "over the fox", "null": null }, { "id": 3, "not": "important", "spacing": "is" }, { " c ": "h\"'ihi", "a": true, "b": false, "d": "", "id": 4 }, { "id": 5 } ]; + var actual = getQueryResults("FOR i IN UnitTestsImportJson1 SORT i.id RETURN i"); + assertEqual(expected, actual); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test json import +//////////////////////////////////////////////////////////////////////////////// + + testJsonImport2 : function () { + var expected = [ { "id": 1, "value": -445.4 }, { "id": 2, "value": 34000 }, { "id": 3, "value": null } ]; + var actual = getQueryResults("FOR i IN UnitTestsImportJson2 SORT i.id RETURN i"); + assertEqual(expected, actual); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test csv import +//////////////////////////////////////////////////////////////////////////////// + + testCsvImport1 : function () { + var expected = [ { "a": "1", "b": 1, "c": "1.3", "d": null, "e": -5, "id": 1 }, { "a": null, "b": "", "c": 3.1, "d": -2.5, "e": "ddd \" ' ffd", "id": 2 } ]; + var actual = getQueryResults("FOR i IN UnitTestsImportCsv1 SORT i.id RETURN i"); + assertEqual(expected, actual); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test csv import +//////////////////////////////////////////////////////////////////////////////// + + testCsvImport2 : function () { + var expected = [ ]; // should be empty! + var actual = getQueryResults("FOR i IN UnitTestsImportCsv2 SORT i.id RETURN i"); + assertEqual(expected, actual); + } + + } +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suite +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(importTestSuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: