//////////////////////////////////////////////////////////////////////////////// /// @brief test the collection interface /// /// @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 Dr. Frank Celler /// @author Copyright 2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// var jsunity = require("jsunity"); // ----------------------------------------------------------------------------- // --SECTION-- collection methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief test suite: error handling //////////////////////////////////////////////////////////////////////////////// function collectionSuiteErrorHandling () { var ERRORS = require("internal").errors; return { //////////////////////////////////////////////////////////////////////////////// /// @brief bad name (underscore) //////////////////////////////////////////////////////////////////////////////// testErrorHandlingBadNameUnderscore : function () { try { db._create("_illegal"); } catch (err) { assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); } }, //////////////////////////////////////////////////////////////////////////////// /// @brief bad name (empty) //////////////////////////////////////////////////////////////////////////////// testErrorHandlingBadNameEmpty : function () { try { db._create(""); } catch (err) { assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); } }, //////////////////////////////////////////////////////////////////////////////// /// @brief bad name (number) //////////////////////////////////////////////////////////////////////////////// testErrorHandlingBadNameNumber : function () { try { db._create("12345"); } catch (err) { assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); } }, //////////////////////////////////////////////////////////////////////////////// /// @brief bad name (underscore) (short-cut) //////////////////////////////////////////////////////////////////////////////// testErrorHandlingBadNameUnderscoreShortCut : function () { try { db["_illegal"]; } catch (err) { assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); } }, //////////////////////////////////////////////////////////////////////////////// /// @brief bad name (empty) (short-cut) //////////////////////////////////////////////////////////////////////////////// testErrorHandlingBadNameEmptyShortCut : function () { try { db[""]; } catch (err) { assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); } }, //////////////////////////////////////////////////////////////////////////////// /// @brief bad name (number) (short-cut) //////////////////////////////////////////////////////////////////////////////// testErrorHandlingBadNameNumberShortCut : function () { try { db["12345"]; } catch (err) { assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); } } }; } //////////////////////////////////////////////////////////////////////////////// /// @brief test suite: collection //////////////////////////////////////////////////////////////////////////////// function collectionSuite () { var ERRORS = require("internal").errors; return { //////////////////////////////////////////////////////////////////////////////// /// @brief read by name //////////////////////////////////////////////////////////////////////////////// testReadingByName : function () { var cn = "example"; db._drop(cn); var c1 = db._create(cn); assertTypeOf("number", c1._id); assertEqual(cn, c1.name()); assertTypeOf("number", c1.status()); var c2 = db._collection(cn); assertEqual(c1._id, c2._id); assertEqual(c1.name(), c2.name()); assertEqual(c1.status(), c2.status()); db._drop(cn); }, //////////////////////////////////////////////////////////////////////////////// /// @brief read by identifier //////////////////////////////////////////////////////////////////////////////// testReadingByIdentifier : function () { var cn = "example"; db._drop(cn); var c1 = db._create(cn); assertTypeOf("number", c1._id); assertEqual(cn, c1.name()); assertTypeOf("number", c1.status()); var c2 = db._collection(c1._id); assertEqual(c1._id, c2._id); assertEqual(c1.name(), c2.name()); assertEqual(c1.status(), c2.status()); db._drop(cn); }, //////////////////////////////////////////////////////////////////////////////// /// @brief read by name (short-cut) //////////////////////////////////////////////////////////////////////////////// testReadingByNameShortCut : function () { var cn = "example"; db._drop(cn); var c1 = db._create(cn); assertTypeOf("number", c1._id); assertEqual(cn, c1.name()); assertTypeOf("number", c1.status()); var c2 = db[cn]; assertEqual(c1._id, c2._id); assertEqual(c1.name(), c2.name()); assertEqual(c1.status(), c2.status()); db._drop(cn); }, //////////////////////////////////////////////////////////////////////////////// /// @brief read all //////////////////////////////////////////////////////////////////////////////// testReadingAll : function () { var cn = "example"; db._drop(cn); var c1 = db._create(cn); assertTypeOf("number", c1._id); assertEqual(cn, c1.name()); assertTypeOf("number", c1.status()); var l = db._collections(); assertNotEqual(0, l.length); db._drop(cn); }, //////////////////////////////////////////////////////////////////////////////// /// @brief creating with defaults //////////////////////////////////////////////////////////////////////////////// testCreatingDefaults : function () { var cn = "example"; db._drop(cn); var c1 = db._create(cn); assertTypeOf("number", c1._id); assertEqual(cn, c1.name()); assertTypeOf("number", c1.status()); var p = c1.properties(); assertEqual(false, p.waitForSync); db._drop(cn); }, //////////////////////////////////////////////////////////////////////////////// /// @brief creating with properties //////////////////////////////////////////////////////////////////////////////// testCreatingProperties : function () { var cn = "example"; db._drop(cn); var c1 = db._create(cn, { waitForSync : true, journalSize : 1024 * 1024 }); assertTypeOf("number", c1._id); assertEqual(cn, c1.name()); assertTypeOf("number", c1.status()); var p = c1.properties(); assertEqual(true, p.waitForSync); if (p.journalSize < 1024 * 1024) { fail(); } if (1024 * 1025 < p.journalSize) { fail(); } db._drop(cn); }, }; } // ----------------------------------------------------------------------------- // --SECTION-- main // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief executes the test suites //////////////////////////////////////////////////////////////////////////////// jsunity.run(collectionSuiteErrorHandling); jsunity.run(collectionSuite); return jsunity.done(); // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" // End: