http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/LICENSE ---------------------------------------------------------------------- diff --git a/tests/integration/LICENSE b/tests/integration/LICENSE new file mode 100644 index 0000000..a4b9abe --- /dev/null +++ b/tests/integration/LICENSE @@ -0,0 +1,327 @@ + +Apache Usergrid itself is licensed under the terms of the Apache License: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + +------------------------------------------------------------------------------ + +USERGRID SUBCOMPONENTS + +The Usergrid software includes a number of subcomponents with separate +copyrights and license terms. Your use of the source code for these +subcomponents is subject to the terms and conditions of the following +licenses. + +IOS SDK +------- +For the SBJson component: + + Copyright (c) Stig Brautaset. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors may be used + to endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +For the SSKeychain component: +----------------------------- + + Copyright (c) Sam Soffes, http://soff.es + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Other components: +----------------- + +This product bundles angular.js +Copyright(c) Google, Inc. Released under the MIT license. + +This product bundles angular-scenario.js, part of jQuery JavaScript Library +which Includes Sizzle.js Copyright (c) jQuery Foundation, Inc. and others. +Released under the MIT license. + +This product bundles Bootstrap Copyright (c) Twitter, Inc +Licensed under the MIT license. + +The product bundles Intro.js (MIT licensed) +Copyright (c) usabli.ca - A weekend project by Afshin Mehrabani (@afshinmeh) + +This product bundles jQuery +Licensed under MIT license. + +This product bundles jQuery-UI +Licensed under MIT license. + +This product bundles jQuery Sparklines (New BSD License) +Copyright (c) Splunk Inc. + +This product bundles Mocha. +All rights reserved. Licensed under MIT. +Copyright (c) TJ Holowaychuk <t...@vision-media.ca> + +This product bundles NewtonSoft.Json under MIT license + +This product bundles NPM MD5 (BSD-3 licensed) +Copyright (c) Paul Vorbach and Copyright (C), Jeff Mott. + +This product bundles NSubsttute under BSD license + +This product bundles SBJson, which is available under a "3-clause BSD" license. +For details, see sdks/ios/UGAPI/SBJson/ . + +This product bundles Sphinx under BSD license + +This product bundles SSKeychain, which is available under a "MIT/X11" license. +For details, see sdks/ios/UGAPI/SSKeychain/. + +This product bundles SSToolkit. +Copyright (c) Sam Soffes. All rights reserved. +These files can be located within the /sdks/ios package. + +This product bundles Entypo, CC by SA license + +This product bundles date.min.js, MIT license + +This product bundles jquery.ui.timepicker.min.js, MIT license + +This product bundles blanket_mocha.min.js, MIT license + +This product bundles FontAwesome, SIL Open Font License +
http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/README.md ---------------------------------------------------------------------- diff --git a/tests/integration/README.md b/tests/integration/README.md new file mode 100644 index 0000000..54a37fa --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,8 @@ +#REST Test framework + +Tests will run via nodejs and mocha framework. The tests will make network calls to the specified environment. + +1. install node above 0.12.1 +2. run "npm install" +3. to override settings in config/default.js add a file config/override.js with the same structure, two documents will be merged. +4. run "mocha" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/config/default.js ---------------------------------------------------------------------- diff --git a/tests/integration/config/default.js b/tests/integration/config/default.js new file mode 100644 index 0000000..856e801 --- /dev/null +++ b/tests/integration/config/default.js @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +module.exports = { + "serverUrl": "http://localhost:8080/", + "orgName": "test-organization", //must + "appName": "test-app", //must pre create app + numberOfUsers:5, + org:{ + clientId:"",clientSecret:"" + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/config/index.js ---------------------------------------------------------------------- diff --git a/tests/integration/config/index.js b/tests/integration/config/index.js new file mode 100644 index 0000000..45c5fcd --- /dev/null +++ b/tests/integration/config/index.js @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var _ = require("underscore"); +var config = require("./default.js") +var override = require("./override.js") + + +if(Object.keys(override).length>0){ + config = _.extend(config, override); +} +module.exports = config; http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/index.js ---------------------------------------------------------------------- diff --git a/tests/integration/index.js b/tests/integration/index.js new file mode 100644 index 0000000..60513b1 --- /dev/null +++ b/tests/integration/index.js @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var config = require('./config/config.js'); + +console.log('config is '+ JSON.stringify(config)); + http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/lib/entities.js ---------------------------------------------------------------------- diff --git a/tests/integration/lib/entities.js b/tests/integration/lib/entities.js new file mode 100644 index 0000000..7ac8479 --- /dev/null +++ b/tests/integration/lib/entities.js @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var config = require("../config"); +var urls = require("./urls"); +var random = require("./random"); +var responseLib = require("./response"); +var async = require('async'); +var request = require("request"); + +module.exports = { + create: function(collection, numberOfEntities, cb) { + var url = urls.appendOrgCredentials(urls.getAppUrl() + collection); + var requestArray = [] + for (var i = 0; i < numberOfEntities; i++) { + requestArray.push({ + url: url, + json: { + firstProperty: "somethingConsistent", + secondProperty: "somethingRandom: " + random.randomString(10), + thirdPropertyTypeInt: random.randomNumber(5), + location: { // Apigee San Jose + latitude: 37.3338716, + longitude: -121.894249 + } + } + }); + } + async.each(requestArray, function(options, cb) { + request.post(options, function(e, r, body) { + cb(e); + }); + }, function(err) { + request.get({ + url: url + "&limit=" + numberOfEntities, + json: true + }, function(e, r, body) { + var error = responseLib.getError(e, r); + cb(error, error ? error : body); + }) + }); + }, + deleteAll: function(collection, cb) { + var url = urls.appendOrgCredentials(urls.getAppUrl() + collection); + deleteAllEntities(collection, function(e) { + request.get({ + url: url, + json: true + }, function(e, r, body) { + var error = responseLib.getError(e, r); + cb(error, error ? error : body); + }) + }) + }, + update: function(collection, uuid, body, cb) { + var url = urls.appendOrgCredentials(urls.getAppUrl() + collection + "/" + uuid); + request.put({ + url: url, + body: body, + json: true + }, function(e, r, body) { + var error = responseLib.getError(e, r); + cb(error, error ? error : body); + }) + }, + get: function(collection, numberOfEntities, cb) { + var url = urls.appendOrgCredentials(urls.getAppUrl() + collection + "?limit=" + numberOfEntities.toString()); + request.get({ + url: url, + json: true + }, function(e, r, body) { + var error = responseLib.getError(e, r); + cb(error, error ? error : body); + }) + }, + getWithQuery: function(collection, query, numberOfEntities, cb) { + var url = urls.appendOrgCredentials(urls.getAppUrl() + collection + "?ql=" + encodeURIComponent(query) + "&limit=" + numberOfEntities.toString()); + request.get({ + url: url, + json: true + }, function(e, r, body) { + var error = responseLib.getError(e, r); + cb(error, error ? error : body); + }) + } +}; + +function deleteAllEntities(collection, cb) { + var url = urls.appendOrgCredentials(urls.getAppUrl() + collection); + request.get({ + url: url, + json: true + }, function(e, r, body) { + if (body.count === undefined) { + cb("The 'count' property is not defined at " + url); + } else if (body.count > 0) { + var deletes = []; + for (var i = 0; i < body.count; i++) { + deletes.push({ + url: urls.appendOrgCredentials(urls.getAppUrl() + collection + "/" + body.entities[i].uuid), + json: true + }); + } + async.each(deletes, function(options, cb) { + request.del(options, function(e) { + cb(e); + }); + }, function(err) { + setTimeout(function() { + deleteAllEntities(collection, function(e) { + cb(e); + }); + }, 600); // Mandatory, since it seems to not retrieve entities if you make a request in < 600ms + }); + } else { + cb(); + } + }); +} http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/lib/random.js ---------------------------------------------------------------------- diff --git a/tests/integration/lib/random.js b/tests/integration/lib/random.js new file mode 100644 index 0000000..a8d0fc3 --- /dev/null +++ b/tests/integration/lib/random.js @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +module.exports = {}; +module.exports.randomString = function randomString(length) { + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for (var i = 0; i < length; i++) { + text += possible.charAt(Math.floor(Math.random() * possible.length)); + } + return text; +} + +module.exports.randomNumber = function randomNumber(length) { + var text = ""; + var possible = "0123456789"; + + for (var i = 0; i < length; i++) { + text += possible.charAt(Math.floor(Math.random() * possible.length)); + } + return parseInt(text); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/lib/response.js ---------------------------------------------------------------------- diff --git a/tests/integration/lib/response.js b/tests/integration/lib/response.js new file mode 100644 index 0000000..f9b34cb --- /dev/null +++ b/tests/integration/lib/response.js @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +module.exports = {}; +module.exports.getError = function(err,response) { + return err || (response.statusCode>=400 ? response.body : null) +}; http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/lib/token.js ---------------------------------------------------------------------- diff --git a/tests/integration/lib/token.js b/tests/integration/lib/token.js new file mode 100644 index 0000000..87b52c8 --- /dev/null +++ b/tests/integration/lib/token.js @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var config = require("../config"); +var urls = require("./urls"); +var responseLib = require("./response"); +var request = require("request"); + +module.exports= { + getAppToken: function (username, password, cb) { + var appUrl = urls.getAppUrl(); + var options = { + uri: appUrl + "token", + method: 'POST', + json: {username: username, password: password, grant_type: "password"} + }; + request(options, function (err, response, body) { + var error = responseLib.getError(err,response); + cb(error, body); + }); + }, + getOrgToken: function (cb) { + var managementUrl = urls.getManagementUrl(); + + var options = { + uri: managementUrl + "token", + method: 'POST', + json: {client_id: config.org.clientId, client_secret: config.org.clientSecret, grant_type: "client_credentials"} + }; + request(options, function (err, response, body) { + var error = responseLib.getError(err,response); + cb(error, body); + }); + }, + getManagementToken: function (username, password, cb) { + var managementUrl = urls.getManagementUrl(); + var options = { + uri: managementUrl + "token", + method: 'POST', + json: {username: username, password: password, grant_type: "password"} + }; + request.post(options, function (err, response, body) { + var error = responseLib.getError(err,response); + cb(error,body); + }); + } + +}; http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/lib/urls.js ---------------------------------------------------------------------- diff --git a/tests/integration/lib/urls.js b/tests/integration/lib/urls.js new file mode 100644 index 0000000..c117bc5 --- /dev/null +++ b/tests/integration/lib/urls.js @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var config = require("../config"); +module.exports = { + getAppUrl: function () { + return config.serverUrl + config.orgName + "/" + config.appName + "/"; + }, + getManagementUrl: function () { + return config.serverUrl + "management/"; + }, + appendAccessToken: function(url,tokenData){ + if(tokenData == null){ + return url; + } + var token = tokenData.access_token || tokenData; + return url + (url.indexOf("?") >= 0 ? "&" : "?" ) + "access_token="+token; + }, + appendOrgCredentials: function(url, clientId, clientSecret){ + clientId = clientId || config.org.clientId; + clientSecret = clientSecret || config.org.clientSecret; + return url + (url.indexOf("?") >= 0 ? "&" : "?" ) + "client_id="+clientId+"&client_secret="+clientSecret; + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/lib/users.js ---------------------------------------------------------------------- diff --git a/tests/integration/lib/users.js b/tests/integration/lib/users.js new file mode 100644 index 0000000..60234a8 --- /dev/null +++ b/tests/integration/lib/users.js @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var request = require("request"); +var token = require("./token"); +var urls = require("./urls"); +var responseLib = require("./response"); +module.exports = {}; + +module.exports.add = function(user, cb) { + request.post(urls.appendOrgCredentials(urls.getAppUrl() + "users"), { + json: user + }, function(err, response, body) { + var error = responseLib.getError(err, response); + cb(error, error ? null : body.entities.pop()); + }); +}; + +module.exports.addToRole = function(username, role, cb) { + request.post(urls.appendOrgCredentials(urls.getAppUrl() + "roles/" + role + "/users/" + username), null, function(err, response, body) { + var error = responseLib.getError(err, response); + cb(error); + }); +}; + +module.exports.get = function(username, cb) { + request.get(urls.appendOrgCredentials(urls.getAppUrl() + "users/" + username), function(err, response, body) { + var json = JSON.parse(body); + var error = response.statusCode === 404 ? null : responseLib.getError(err, response); + cb(error, error ? null : response.statusCode === 404 ? null : json.entities.pop()); + }) +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/package.json ---------------------------------------------------------------------- diff --git a/tests/integration/package.json b/tests/integration/package.json new file mode 100644 index 0000000..d8b24e5 --- /dev/null +++ b/tests/integration/package.json @@ -0,0 +1,16 @@ +{ + "name": "Usergrid_Tests", + "version": "0.0.1", + "devDependencies": { + "async": "^1.2.1", + "mocha": "~2.2.5", + "request": "~2.58.0", + "should": "~6.0.3", + "underscore": "^1.8.3", + "uuid": "^2.0.1", + "colors": "~1.1.2" + }, + "engines": { + "node": ">0.12.1" + } +} http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/authentication/management.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/authentication/management.js b/tests/integration/test/authentication/management.js new file mode 100644 index 0000000..a624146 --- /dev/null +++ b/tests/integration/test/authentication/management.js @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +'use strict'; +var token = require("../../lib/token") +var config = require("../../config") +var should = require("should") +var setup = require("../setup") +module.exports = {}; + +module.exports.test = function() { + describe('get a management token', function() { + it('should return valid token', function() { + var admin = setup.admins[0]; + token.getAppToken(admin.username, admin.password, function(err, tokenData) { + should(err).be.null; + tokenData.should.have.property('access_token').and.have.lengthOf(63);; + tokenData.should.have.property('expires_in'); + tokenData.should.have.property('expires_in').which.is.a.Number; + tokenData.user.username.should.equal(admin.username) + }); + }); + }); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/authentication/org.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/authentication/org.js b/tests/integration/test/authentication/org.js new file mode 100644 index 0000000..6a0de9f --- /dev/null +++ b/tests/integration/test/authentication/org.js @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +'use strict'; +var token = require("../../lib/token") +var config = require("../../config") +var should = require("should") +var setup = require("../setup") +module.exports = {}; + +module.exports.test = function() { + describe('get an org token', function() { + it('should return valid token', function() { + token.getOrgToken(function(err, tokenData) { + should(err).be.null; + tokenData.should.have.property('access_token').and.have.lengthOf(63);; + tokenData.should.have.property('expires_in'); + tokenData.should.have.property('expires_in').which.is.a.Number; + tokenData.organization.name.should.equal(config.orgName) + }); + }); + }); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/authentication/shawn ---------------------------------------------------------------------- diff --git a/tests/integration/test/authentication/shawn b/tests/integration/test/authentication/shawn new file mode 100644 index 0000000..709e62c --- /dev/null +++ b/tests/integration/test/authentication/shawn @@ -0,0 +1 @@ +shawn \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/authentication/user.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/authentication/user.js b/tests/integration/test/authentication/user.js new file mode 100644 index 0000000..28914d2 --- /dev/null +++ b/tests/integration/test/authentication/user.js @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +'use strict'; +var token = require("../../lib/token") +var config = require("../../config") +var should = require("should") +var setup = require("../setup") +module.exports = {}; + +module.exports.test = function() { + describe('get a user token', function() { + it('should return valid token', function() { + var user = setup.users[0]; + token.getAppToken(user.username, user.password, function(err, tokenData) { + should(err).be.null; + tokenData.should.have.property('access_token').and.have.lengthOf(63);; + tokenData.should.have.property('expires_in'); + tokenData.should.have.property('expires_in').which.is.a.Number; + tokenData.user.username.should.equal(user.username) + }); + }); + }); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/authorization/shawn ---------------------------------------------------------------------- diff --git a/tests/integration/test/authorization/shawn b/tests/integration/test/authorization/shawn new file mode 100644 index 0000000..709e62c --- /dev/null +++ b/tests/integration/test/authorization/shawn @@ -0,0 +1 @@ +shawn \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/collections/brandon ---------------------------------------------------------------------- diff --git a/tests/integration/test/collections/brandon b/tests/integration/test/collections/brandon new file mode 100644 index 0000000..bb0382d --- /dev/null +++ b/tests/integration/test/collections/brandon @@ -0,0 +1 @@ +brandon \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/connections/brandon ---------------------------------------------------------------------- diff --git a/tests/integration/test/connections/brandon b/tests/integration/test/connections/brandon new file mode 100644 index 0000000..bb0382d --- /dev/null +++ b/tests/integration/test/connections/brandon @@ -0,0 +1 @@ +brandon \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/entities/brandon ---------------------------------------------------------------------- diff --git a/tests/integration/test/entities/brandon b/tests/integration/test/entities/brandon new file mode 100644 index 0000000..bb0382d --- /dev/null +++ b/tests/integration/test/entities/brandon @@ -0,0 +1 @@ +brandon \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/entities/create.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/entities/create.js b/tests/integration/test/entities/create.js new file mode 100644 index 0000000..c553292 --- /dev/null +++ b/tests/integration/test/entities/create.js @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var entities = require("../../lib/entities"); +var should = require("should"); + +module.exports = { + test: function() { + var numberOfRecords = 30; + describe("create entities", function() { + it("should create " + numberOfRecords.toString() + " entities in the cats collection", function(done) { + this.slow(numberOfRecords * 500); + entities.create('cats', numberOfRecords, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(numberOfRecords); + done(); + }) + }); + }); + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/entities/deleteAll.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/entities/deleteAll.js b/tests/integration/test/entities/deleteAll.js new file mode 100644 index 0000000..81a6199 --- /dev/null +++ b/tests/integration/test/entities/deleteAll.js @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var entities = require("../../lib/entities"); +var should = require("should"); + +module.exports = { + test: function(collectionName) { + collectionName = collectionName ? collectionName : "cats"; + describe("delete entities", function() { + it("should delete all entities from the " + collectionName + " collection", function(done) { + this.timeout(60000); + this.slow(30000); + entities.deleteAll(collectionName, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0); + body.count.should.equal(0); + done(); + }) + }); + }); + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/entities/get.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/entities/get.js b/tests/integration/test/entities/get.js new file mode 100644 index 0000000..1eb05e3 --- /dev/null +++ b/tests/integration/test/entities/get.js @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var entities = require("../../lib/entities"); +var should = require("should"); +var async = require("async"); + +module.exports = { + test: function() { + describe("get entities", function(done) { + async.parallel([ + function(cb) { + it("should get 1 entity", function() { + entities.get('cats', 1, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(1); + body.count.should.equal(1); + }) + }); + }, + function(cb) { + it("should get 4 entities", function() { + entities.get('cats', 4, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(4); + body.count.should.equal(4); + }) + }); + }, + function(cb) { + it("should get 18 entities", function() { + entities.get('cats', 18, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(18); + body.count.should.equal(18); + }) + }); + } + ], function(err) { + done(); + }); + }); + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/entities/update.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/entities/update.js b/tests/integration/test/entities/update.js new file mode 100644 index 0000000..fe7e33a --- /dev/null +++ b/tests/integration/test/entities/update.js @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var entities = require("../../lib/entities"); +var random = require("../../lib/random"); +var should = require("should"); + +module.exports = { + test: function() { + describe("update entity", function() { + it("should get a random entity and set 'firstProperty' to 'BANJO'", function(done) { + this.slow(4000); + entities.get('cats', random.randomNumber(10), function(err, body) { + var payload = { + firstProperty: "BANJO" + } + body.entities[0].firstProperty.should.equal("somethingConsistent"); + entities.update('cats', body.entities[body.entities.length - 1].uuid, payload, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(1); + body.entities[0].firstProperty.should.equal("BANJO"); + done(); + }); + }); + }); + }); + } +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/main.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/main.js b/tests/integration/test/main.js new file mode 100644 index 0000000..2b37769 --- /dev/null +++ b/tests/integration/test/main.js @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var should = require("should"); +var config = require("../config/"); +var setup = require("./setup"); +var teardown = require("./teardown"); +var async = require('async'); +var request = require('request'); +var colors = require('colors'); + +describe("baas 2.0 tests", function() { + before(function(done) { + console.log(" setup"); + setup.do(function(err) { + should(err).be.null; + console.log(" â".green + " done".grey); + done(); + }) + }); + describe("authentication", function() { + require("./authentication/user.js").test(); + require("./authentication/management.js").test(); + require("./authentication/org.js").test(); + }); + describe("users", function() { + require("./users/create.js").test(); + }); + describe("entities", function() { + require("./entities/create.js").test(); + require("./entities/get.js").test(); + require("./entities/update.js").test(); + require("./entities/deleteAll.js").test(); + }); + describe("connections", function() { + + }); + describe("queries", function() { + require('./queries/integerComparison.js').test(); + }); + after(function(done) { + this.timeout(40000); + console.log(" teardown"); + teardown.do(function(err) { + should(err).be.null; + console.log(" â".green + " done".grey); + done(); + }) + }); +}); http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/management/shawn ---------------------------------------------------------------------- diff --git a/tests/integration/test/management/shawn b/tests/integration/test/management/shawn new file mode 100644 index 0000000..709e62c --- /dev/null +++ b/tests/integration/test/management/shawn @@ -0,0 +1 @@ +shawn \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/mocha.opts ---------------------------------------------------------------------- diff --git a/tests/integration/test/mocha.opts b/tests/integration/test/mocha.opts new file mode 100644 index 0000000..9e2480f --- /dev/null +++ b/tests/integration/test/mocha.opts @@ -0,0 +1,3 @@ +--ui bdd +--recursive +--timeout 5000 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/queries/integerComparison.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/queries/integerComparison.js b/tests/integration/test/queries/integerComparison.js new file mode 100644 index 0000000..f3036f1 --- /dev/null +++ b/tests/integration/test/queries/integerComparison.js @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var entities = require("../../lib/entities"); +var should = require("should"); + +module.exports = { + test: function() { + var query1 = "where thirdPropertyTypeInt > 30000"; + describe("get horses " + query1, function() { + it('should return a subset of results ' + query1, function() { + entities.getWithQuery('horses', query1, 10, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array); + if (body.entities.length > 0) { + body.entities.length.should.be.greaterThan(0).and.lessThan(11); + body.entities.forEach(function(entity) { + entity.thirdPropertyTypeInt.should.be.greaterThan(30000); + }); + } + }); + }); + }); + var query2 = "where thirdPropertyTypeInt > 30000 && thirdPropertyTypeInt < 40000"; + describe("get horses " + query2, function() { + it('should return a subset of results ' + query2, function() { + entities.getWithQuery('horses', query2, 10, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array); + if (body.entities.length > 0) { + body.entities.length.should.be.greaterThan(0).and.lessThan(11); + body.entities.forEach(function(entity) { + entity.thirdPropertyTypeInt.should.be.greaterThan(30000).and.lessThan(40000); + + }); + } + }); + }); + }); + + var query3 = "select * where location within 10000 of 37.3236882,-121.9373442"; //San Jose Airport + describe("get horses " + query3, function() { + it('should return a subset of results ' + query3, function() { + entities.getWithQuery('horses', query3, 10, function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array); + body.entities.length.should.be.greaterThan(0); + if (body.entities.length > 0) { + body.entities.length.should.be.greaterThan(0).and.lessThan(11); + body.entities.forEach(function(entity) { + // Apigee San Jose + entity.location.latitude.should.be.equal(37.3338716); + entity.location.longitude.should.be.equal(-121.894249); + }); + } + }); + }); + }); + + } +}; http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/setup.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/setup.js b/tests/integration/test/setup.js new file mode 100644 index 0000000..f0a89b6 --- /dev/null +++ b/tests/integration/test/setup.js @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +// here we're going to do teardown of BaaS environment - deletion of users, entities, etc. +var users = require("../lib/users"); +var entities = require("../lib/entities"); +var config = require("../config"); +var async = require("async"); +var uuid = require("uuid"); + +module.exports = { + users: [], + admins: [], + do: function(cb) { + async.parallel([ + function(cb) { + // create admin user + var id = uuid.v1().toString().replace("-", ""); + var admin = { + username: id + "user", + password: "pwd" + id, + name: id + " name", + email: id + "@uge2e.com" + } + users.add(admin, function(err, user) { + users.addToRole(user.username, "admin", function(err) { + module.exports.admins.push(admin); + cb(err, err ? null : admin); + }); + }); + }, + function(cb) { + // create app users + var size = config.numberOfUsers; + var userArr = []; + module.exports.users = userArr; + for (var i = 0; i < size; i++) { + var id = uuid.v1().toString().replace("-", ""); + userArr.push({ + username: id + "user", + password: "pwd" + id, + name: id + " name", + email: id + "@uge2e.com" + }); + } + async.each( + userArr, + function(user, cb) { + users.add(user, function(err, user) { + cb(err, user); + }); + }, + function(err, localUsers) { + cb(err); + } + ) + }, + function(cb) { + // create entities + var numberOfRecords = 20; + async.parallel([ + function(cb) { + entities.create('dogs', numberOfRecords, function(err, body) { + cb(err); + }); + }, + function(cb) { + entities.create('horses', numberOfRecords, function(err, body) { + cb(err); + }); + } + ], + function(err, data) { + cb(err); + }); + } + ], + function(err, data) { + cb(err); + }); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/teardown.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/teardown.js b/tests/integration/test/teardown.js new file mode 100644 index 0000000..6175d69 --- /dev/null +++ b/tests/integration/test/teardown.js @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var entities = require("../lib/entities"); +var should = require("should"); +var async = require("async"); + +module.exports = { + do: function(cb) { + async.parallel([ + function(cb) { + entities.deleteAll('users', function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0); + body.count.should.equal(0); + cb(err); + }) + }, + function(cb) { + entities.deleteAll('horses', function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0); + body.count.should.equal(0); + cb(err); + }) + }, + function(cb) { + entities.deleteAll('dogs', function(err, body) { + should(err).be.null; + body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0); + body.count.should.equal(0); + cb(err); + }) + } + ], + function(err, data) { + cb(err); + }); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/integration/test/users/create.js ---------------------------------------------------------------------- diff --git a/tests/integration/test/users/create.js b/tests/integration/test/users/create.js new file mode 100644 index 0000000..0d714c6 --- /dev/null +++ b/tests/integration/test/users/create.js @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +var should = require("should"); +var uuid = require("uuid"); +var users = require("../../lib/users"); +var token = require("../../lib/token"); +module.exports = { + test: function() { + describe("create a user", function() { + var username = "testuser" + uuid.v1(); + var password = "password"; + it("successfully return result", function() { + users.add({ + username: username, + password: password, + name: username + " name", + email: username + "@uge2e.com" + }, function(err, userBody) { + should(err).be.null; + userBody.should.not.be.null; + token.getAppToken(username, password, function(err, appToken) { + should(err).be.null; + appToken.should.not.be.null; + appToken.should.have.property("access_token"); + }) + }); + }); + }); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/29bf682e/tests/performance/.gitignore ---------------------------------------------------------------------- diff --git a/tests/performance/.gitignore b/tests/performance/.gitignore new file mode 100644 index 0000000..b012b3e --- /dev/null +++ b/tests/performance/.gitignore @@ -0,0 +1 @@ +.java-version