usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [33/36] usergrid git commit: add consistency check for create
Date Thu, 01 Oct 2015 16:28:08 GMT
add consistency check for create


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/9ceae774
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/9ceae774
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/9ceae774

Branch: refs/heads/master
Commit: 9ceae7748ce522778fbd0d9a9bbbd6b240cf9b9b
Parents: 2e51d06
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Thu Oct 1 09:40:14 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Thu Oct 1 09:40:14 2015 -0600

----------------------------------------------------------------------
 stack/rest_integration_tests/lib/entities.js    | 41 ++++++++++++++++++++
 .../test/entities/create.js                     | 24 +++++++++++-
 2 files changed, 64 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/9ceae774/stack/rest_integration_tests/lib/entities.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/lib/entities.js b/stack/rest_integration_tests/lib/entities.js
index c62ca0d..3693dcb 100644
--- a/stack/rest_integration_tests/lib/entities.js
+++ b/stack/rest_integration_tests/lib/entities.js
@@ -46,6 +46,37 @@ module.exports = {
             cb(error, error ? error : body);
         });
     },
+    createEach: function(collection, numberOfEntities, cb) {
+        var url = urls.appendOrgCredentials(urls.appUrl() + collection);
+        var requestArray = []
+        geos = random.geo(config.location, 2000, numberOfEntities);
+        // console.log(geos);
+        for (var i = 0; i < numberOfEntities; i++) {
+            requestArray.push({
+                consistentProperty: "somethingConsistent",
+                randomProperty: "somethingRandom - " + random.randomString(10),
+                intProperty: random.randomNumber(5),
+                optionsProperty: random.abc(),
+                location: geos[i],
+                title: "A Tale of Two Cities"
+            });
+        }
+        var returnBody = [];
+        async.each(requestArray, function(options, cb) {
+            request.post({
+                url: url,
+                json: true,
+                body: options
+            }, function(e, r, body) {
+                var error = responseLib.getError(e, r);
+                returnBody.push(body.entities[0]);
+                cb(error, error ? error : body.entities[0]);
+            });
+        }, function(err,bodies) {
+           cb(err,returnBody);
+        });
+
+    },
     deleteAll: function(collection, cb) {
         var url = urls.appendOrgCredentials(urls.appUrl() + collection);
         deleteAllEntities(collection, function(e) {
@@ -79,6 +110,16 @@ module.exports = {
             cb(error, error ? error : body);
         })
     },
+    getByUuid: function(collection, uuid, cb) {
+        var url = urls.appendOrgCredentials(urls.appUrl() + collection + "/"+uuid);
+        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.appUrl() + collection + "?ql=" + encodeURIComponent(query)
+ "&limit=" + numberOfEntities.toString());
         request.get({

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9ceae774/stack/rest_integration_tests/test/entities/create.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/test/entities/create.js b/stack/rest_integration_tests/test/entities/create.js
index 97e820c..c7e6f42 100644
--- a/stack/rest_integration_tests/test/entities/create.js
+++ b/stack/rest_integration_tests/test/entities/create.js
@@ -21,6 +21,9 @@ var config = require('../../config');
 module.exports = {
     test: function() {
         var numberOfRecords = 30;
+        var uuid = require("uuid");
+        var id = "resttest_"+ uuid.v1().toString().replace("-", "");
+
         describe("create entities", function() {
             it("should create " + numberOfRecords.toString() + " entities in the " + config.entitiesTestCollection
+ " collection", function(done) {
                 this.slow(numberOfRecords * 500);
@@ -29,10 +32,29 @@ module.exports = {
                     body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(numberOfRecords);
                     body.entities.forEach(function(entity) {
                         entity.should.have.property("uuid").and.match(/(\w{8}(-\w{4}){3}-\w{12}?)/);
-                    })
+                    });
                     done();
                 })
             });
+            it("should create " + numberOfRecords.toString() + " entities in the " + id +
" collection and check for consistency", function(done) {
+                this.slow(numberOfRecords * 500);
+                entities.createEach(id, numberOfRecords, function(err, bodies) {
+                    should(err).be.null;
+                    bodies.should.be.an.instanceOf(Array).and.have.lengthOf(numberOfRecords);
+                    bodyMap = {};
+                    bodies.forEach(function(body){
+                        bodyMap[body.uuid] = body;
+                    });
+                    entities.get(id, numberOfRecords, function (err,entityArray) {
+                        should(err).be.null;
+                        entityArray.entities.forEach(function(entity){
+                            delete(bodyMap[entity.uuid]);
+                        });
+                        should(Object.keys(bodyMap)).have.lengthOf(0);
+                        done();
+                    });
+                });
+            });
         });
     }
 };


Mime
View raw message