You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/02/04 06:01:26 UTC
usergrid git commit: Add additional node.js integration tests for
groups/users/devices.
Repository: usergrid
Updated Branches:
refs/heads/master 8bead20f9 -> b6698927a
Add additional node.js integration tests for groups/users/devices.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/b6698927
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/b6698927
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/b6698927
Branch: refs/heads/master
Commit: b6698927ac609a14e2fccdb4a0d973023d9228d7
Parents: 8bead20
Author: Michael Russo <mi...@gmail.com>
Authored: Wed Feb 3 21:00:46 2016 -0800
Committer: Michael Russo <mi...@gmail.com>
Committed: Wed Feb 3 21:00:46 2016 -0800
----------------------------------------------------------------------
tests/integration/lib/connections.js | 63 +++++++
tests/integration/lib/devices.js | 43 +++++
tests/integration/lib/entities.js | 19 +-
tests/integration/lib/groups.js | 43 +++++
tests/integration/lib/notifications.js | 34 ++++
tests/integration/lib/users.js | 2 +-
tests/integration/test/authentication/user.js | 2 +-
tests/integration/test/entities/create.js | 12 +-
tests/integration/test/groups/groups.js | 192 +++++++++++++++++++++
tests/integration/test/main.js | 5 +-
tests/integration/test/setup.js | 23 ++-
tests/integration/test/teardown.js | 24 +++
12 files changed, 439 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/lib/connections.js
----------------------------------------------------------------------
diff --git a/tests/integration/lib/connections.js b/tests/integration/lib/connections.js
new file mode 100644
index 0000000..59df1fa
--- /dev/null
+++ b/tests/integration/lib/connections.js
@@ -0,0 +1,63 @@
+/*
+ * 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 urls = require("./urls");
+var responseLib = require("./response");
+
+module.exports = {};
+
+function buildUrl(collection1, entity1, collection2, entity2, relationship){
+
+ var url = urls.getAppUrl();
+ if ( relationship !== null && relationship !== undefined && relationship !== ""){
+ url += collection1 + "/" + entity1 + "/" + relationship + "/" + collection2 + "/" + entity2;
+ }else{
+ url += collection1 + "/" + entity1 + "/" + collection2 + "/" + entity2;
+ }
+
+ return urls.appendOrgCredentials(url);
+}
+
+module.exports.connect = function(collection1, entity1, collection2, entity2, relationship, cb) {
+
+ var url = buildUrl(collection1, entity1, collection2, entity2, relationship);
+
+ request.post({
+ url : url,
+ json: {}
+ }, function(err, response, body) {
+ var error = responseLib.getError(err, response, body);
+ cb(error, error ? null : body.entities.pop());
+ });
+};
+
+
+module.exports.disconnect = function(collection1, entity1, collection2, entity2, relationship, cb) {
+
+ var url = buildUrl(collection1, entity1, collection2, entity2, relationship);
+
+ request.del(url, 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());
+ })
+};
+
+
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/lib/devices.js
----------------------------------------------------------------------
diff --git a/tests/integration/lib/devices.js b/tests/integration/lib/devices.js
new file mode 100644
index 0000000..a96b553
--- /dev/null
+++ b/tests/integration/lib/devices.js
@@ -0,0 +1,43 @@
+/*
+ * 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 urls = require("./urls");
+var responseLib = require("./response");
+module.exports = {};
+
+
+module.exports.add = function(device, cb) {
+ request.put({
+ url: urls.appendOrgCredentials(urls.getAppUrl() + "devices/" + device.name),
+ json: device
+ }, function(err, response, body) {
+ var error = responseLib.getError(err, response);
+ cb(error, error ? null : body.entities.pop());
+ });
+};
+
+
+module.exports.get = function(deviceUUID, cb) {
+ request.get(urls.appendOrgCredentials(urls.getAppUrl() + "devices/" + deviceUUID), 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/b6698927/tests/integration/lib/entities.js
----------------------------------------------------------------------
diff --git a/tests/integration/lib/entities.js b/tests/integration/lib/entities.js
index 7ac8479..b17fc74 100644
--- a/tests/integration/lib/entities.js
+++ b/tests/integration/lib/entities.js
@@ -19,29 +19,20 @@
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) {
+ create: function(collection, entity, numberOfEntities, cb) {
var url = urls.appendOrgCredentials(urls.getAppUrl() + collection);
- var requestArray = []
+ 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
- }
- }
- });
- }
+ json: entity
+ })
+ }
async.each(requestArray, function(options, cb) {
request.post(options, function(e, r, body) {
cb(e);
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/lib/groups.js
----------------------------------------------------------------------
diff --git a/tests/integration/lib/groups.js b/tests/integration/lib/groups.js
new file mode 100644
index 0000000..21a51d2
--- /dev/null
+++ b/tests/integration/lib/groups.js
@@ -0,0 +1,43 @@
+/*
+ * 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 urls = require("./urls");
+var responseLib = require("./response");
+module.exports = {};
+
+
+module.exports.add = function(group, cb) {
+ request.put({
+ url: urls.appendOrgCredentials(urls.getAppUrl() + "groups/" + group.path),
+ json: group
+ }, function(err, response, body) {
+ var error = responseLib.getError(err, response);
+ cb(error, error ? null : body.entities.pop());
+ });
+};
+
+
+module.exports.get = function(groupUUID, cb) {
+ request.get(urls.appendOrgCredentials(urls.getAppUrl() + "groups/" + groupUUID), 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/b6698927/tests/integration/lib/notifications.js
----------------------------------------------------------------------
diff --git a/tests/integration/lib/notifications.js b/tests/integration/lib/notifications.js
new file mode 100644
index 0000000..dd04864
--- /dev/null
+++ b/tests/integration/lib/notifications.js
@@ -0,0 +1,34 @@
+/*
+ * 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 urls = require("./urls");
+var responseLib = require("./response");
+module.exports = {};
+
+
+module.exports.send = function(path, payload, cb) {
+ request.post({
+ url: urls.appendOrgCredentials(urls.getAppUrl() + path + "/notifications"),
+ json: payload
+ }, function(err, response, body) {
+ var error = responseLib.getError(err, response);
+ cb(error, error ? null : body.entities.pop());
+ });
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/lib/users.js
----------------------------------------------------------------------
diff --git a/tests/integration/lib/users.js b/tests/integration/lib/users.js
index 60234a8..ca7e9c5 100644
--- a/tests/integration/lib/users.js
+++ b/tests/integration/lib/users.js
@@ -45,4 +45,4 @@ module.exports.get = function(username, cb) {
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
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/test/authentication/user.js
----------------------------------------------------------------------
diff --git a/tests/integration/test/authentication/user.js b/tests/integration/test/authentication/user.js
index 28914d2..16b2e3d 100644
--- a/tests/integration/test/authentication/user.js
+++ b/tests/integration/test/authentication/user.js
@@ -37,4 +37,4 @@ module.exports.test = function() {
});
});
});
-}
\ No newline at end of file
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/test/entities/create.js
----------------------------------------------------------------------
diff --git a/tests/integration/test/entities/create.js b/tests/integration/test/entities/create.js
index c553292..6333b8f 100644
--- a/tests/integration/test/entities/create.js
+++ b/tests/integration/test/entities/create.js
@@ -18,6 +18,7 @@
*/
var entities = require("../../lib/entities");
+var random = require("../../lib/random");
var should = require("should");
module.exports = {
@@ -26,7 +27,16 @@ module.exports = {
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) {
+ var entity = {
+ firstProperty: "somethingConsistent",
+ secondProperty: "somethingRandom: " + random.randomString(10),
+ thirdPropertyTypeInt: random.randomNumber(5),
+ location: { // Apigee San Jose
+ latitude: 37.3338716,
+ longitude: -121.894249
+ }
+ };
+ entities.create('cats', entity, numberOfRecords, function(err, body) {
should(err).be.null;
body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(numberOfRecords);
done();
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/test/groups/groups.js
----------------------------------------------------------------------
diff --git a/tests/integration/test/groups/groups.js b/tests/integration/test/groups/groups.js
new file mode 100644
index 0000000..b822661
--- /dev/null
+++ b/tests/integration/test/groups/groups.js
@@ -0,0 +1,192 @@
+/*
+ * 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 devices = require("../../lib/devices");
+var groups = require("../../lib/groups");
+var connections = require("../../lib/connections");
+var async = require('async');
+
+
+var DEVICE_TOKEN = "APA91bGxRGnMK8tKgVPzSlxtCFvwSVqx0xEPjA06sBmiK0kQsiwUt6ipSYF0iPRHyUgpXle0P8OlRWJADkQrcN7yxG4pLMg1CVmrqDu8tfSe63mZ-MRU2IW0cOhmosqzC9trl33moS3OvT7qjDjkP4Qq8LYdwwYC5A";
+
+module.exports = {
+ test: function () {
+
+ var username = "groupuser";
+ var password = "password";
+ var usersArray = [];
+ for (var i = 1; i <= 5; i++) {
+ usersArray.push({
+ "username": username + "-" + i,
+ "password": password,
+ "name": username + "-" + i,
+ "email": username + "-" + i + "@uge2e.com"
+ });
+ }
+
+ // build devices
+ var name = "device";
+ var devicesArray = [];
+ for (var j = 1; j <= 5; j++) {
+ devicesArray.push({
+ "name": name + "-" + j,
+ "gcm.notifier.id": DEVICE_TOKEN
+ });
+ }
+
+
+ describe("users", function () {
+ it("should create some devices", function (done) {
+ this.slow(2000);
+ async.each(usersArray, function (user, cb) {
+ users.add(user, function (err, user) {
+ should(err).be.null;
+ user.should.not.be.null;
+ cb(err, user);
+ });
+ }, function (err) {
+
+ done();
+
+ });
+
+ })
+
+ });
+
+
+ describe("devices", function () {
+ it("should create some devices", function (done) {
+ this.slow(2000);
+ async.each(devicesArray, function (device, cb) {
+ devices.add(device, function (err, device) {
+ should(err).be.null;
+ device.should.not.be.null;
+ cb(err, device);
+ });
+
+ }, function (err) {
+
+ done()
+
+ });
+
+ })
+
+ });
+
+
+ describe("user<->devices", function () {
+ it("should connect devices to users", function (done) {
+ this.slow(2000);
+ async.eachSeries(usersArray, function (user, cb) {
+ async.each(devicesArray, function (device, cb) {
+ connections.connect("users", user.username, "devices", device.name, null, function (err) {
+ cb(err, device);
+ });
+ });
+ cb(null);
+
+ }, function (err) {
+
+ if (err) {
+ console.log("error adding users " + err);
+ }
+ done();
+ });
+
+ })
+
+ });
+
+
+ describe("groups", function () {
+ it("should create some groups", function (done) {
+ this.slow(2000);
+ var group1 = {
+ path: "group1"
+ };
+
+ var group2 = {
+ path: "group2"
+ };
+
+ console.log(" creating some groups");
+ groups.add(group1, function (err) {
+ if (err) {
+ console.log("failed to create " + "group1:" + err);
+ }
+
+ });
+
+ groups.add(group2, function (err) {
+ if (err) {
+ console.log("failed to create " + "group2:" + err);
+ }
+ });
+
+ done();
+
+ })
+
+ });
+
+
+ describe("groups<->users", function () {
+ it("should connect users to groups", function (done) {
+ this.slow(2000);
+ async.each(usersArray, function (user, cb) {
+
+ async.series([
+ function (cb) {
+ connections.connect("groups", "group1", "users", user.username, null, function (err) {
+ cb(err, user);
+ });
+
+ },
+ function (cb) {
+ connections.connect("groups", "group2", "users", user.username, null, function (err) {
+ cb(err, user);
+
+ });
+ }
+
+ ], function (err, results) {
+
+ cb(err);
+
+ });
+
+ }, function (err) {
+ done();
+ });
+
+ })
+
+ });
+
+
+ // SEND NOTIFICATIONS HERE AND VALIDATE THE NUMBER OF NOTIFICATIONS SENT ARE ACCURATE FOR QUERY
+
+
+ }
+};
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/test/main.js
----------------------------------------------------------------------
diff --git a/tests/integration/test/main.js b/tests/integration/test/main.js
index 2b37769..5833607 100644
--- a/tests/integration/test/main.js
+++ b/tests/integration/test/main.js
@@ -25,7 +25,7 @@ var async = require('async');
var request = require('request');
var colors = require('colors');
-describe("baas 2.0 tests", function() {
+describe("** Usergrid REST Integration Tests **", function() {
before(function(done) {
console.log(" setup");
setup.do(function(err) {
@@ -54,6 +54,9 @@ describe("baas 2.0 tests", function() {
describe("queries", function() {
require('./queries/integerComparison.js').test();
});
+ describe("groups", function() {
+ require("./groups/groups.js").test();
+ });
after(function(done) {
this.timeout(40000);
console.log(" teardown");
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/test/setup.js
----------------------------------------------------------------------
diff --git a/tests/integration/test/setup.js b/tests/integration/test/setup.js
index f0a89b6..d254d8d 100644
--- a/tests/integration/test/setup.js
+++ b/tests/integration/test/setup.js
@@ -23,6 +23,7 @@ var entities = require("../lib/entities");
var config = require("../config");
var async = require("async");
var uuid = require("uuid");
+var random = require("../lib/random");
module.exports = {
users: [],
@@ -37,8 +38,9 @@ module.exports = {
password: "pwd" + id,
name: id + " name",
email: id + "@uge2e.com"
- }
+ };
users.add(admin, function(err, user) {
+ //console.log(user);
users.addToRole(user.username, "admin", function(err) {
module.exports.admins.push(admin);
cb(err, err ? null : admin);
@@ -55,7 +57,7 @@ module.exports = {
userArr.push({
username: id + "user",
password: "pwd" + id,
- name: id + " name",
+ name: id + "name",
email: id + "@uge2e.com"
});
}
@@ -63,6 +65,7 @@ module.exports = {
userArr,
function(user, cb) {
users.add(user, function(err, user) {
+ module.exports.users.push(user);
cb(err, user);
});
},
@@ -74,14 +77,24 @@ module.exports = {
function(cb) {
// create entities
var numberOfRecords = 20;
+ var entity = {
+ firstProperty: "somethingConsistent",
+ secondProperty: "somethingRandom: " + random.randomString(10),
+ thirdPropertyTypeInt: random.randomNumber(5),
+ location: { // Apigee San Jose
+ latitude: 37.3338716,
+ longitude: -121.894249
+ }
+ };
async.parallel([
function(cb) {
- entities.create('dogs', numberOfRecords, function(err, body) {
+
+ entities.create('dogs', entity, numberOfRecords, function(err, body) {
cb(err);
});
},
function(cb) {
- entities.create('horses', numberOfRecords, function(err, body) {
+ entities.create('horses', entity, numberOfRecords, function(err, body) {
cb(err);
});
}
@@ -95,4 +108,4 @@ module.exports = {
cb(err);
});
}
-}
\ No newline at end of file
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b6698927/tests/integration/test/teardown.js
----------------------------------------------------------------------
diff --git a/tests/integration/test/teardown.js b/tests/integration/test/teardown.js
index 6175d69..d1031ff 100644
--- a/tests/integration/test/teardown.js
+++ b/tests/integration/test/teardown.js
@@ -47,6 +47,30 @@ module.exports = {
body.count.should.equal(0);
cb(err);
})
+ },
+ function(cb) {
+ entities.deleteAll('devices', 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('groups', 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('notifications', 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) {