From c4ba130d85fbbdf26b9072450a2f23454dc47226 Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Fri, 27 Oct 2017 14:32:46 -0500 Subject: [PATCH 1/8] initial watson conversation tcs and readme --- .../templates/node/README.md | 31 ++++++++++ test/app/watson-conversation/node/server.js | 31 ++++++++++ test/integration-node-express-test.js | 56 +++++++++++++------ 3 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 test/app/watson-conversation/node/server.js diff --git a/generators/service-watson-conversation/templates/node/README.md b/generators/service-watson-conversation/templates/node/README.md index e69de29b..fd87e940 100644 --- a/generators/service-watson-conversation/templates/node/README.md +++ b/generators/service-watson-conversation/templates/node/README.md @@ -0,0 +1,31 @@ +# Watson Conversation + +The IBM Watson™ Conversation service combines machine learning, natural language understanding, and integrated dialog tools to create conversation flows between your apps and your users. + +## Credentials + +### LocalDevConfig + +This is where your local configuration is stored for Watson Conversation. +``` +{ + "watson_conversation_url": "{{{url}}}", + "watson_conversation_username": "{{username}}", + "watson_conversation_password": "{{password}}" +} +``` + +## Usage + +The `service_manager` returns an instance of a `ConversationV1` client which is preconfigured to use the credentials supplied. You will need to specify the `workspace_id` for the conversation workspace you have created, as each service integration can include multiple workspaces. The full documentation for `python ConversationV1` can [be found here](https://www.ibm.com/watson/developercloud/conversation/api/v1/?python), +but a small getting started example can be found below: + +```javascript + +``` + +## Extended Example + +An extended example of basic usages can be found in the [Watson Developer Cloud GitHub Repo](https://github.com/watson-developer-cloud/node-sdk/blob/master/examples/conversation.v1.js). + +Reference the full [ConversationV1 API to leverage its full power](https://www.ibm.com/watson/developercloud/conversation/api/v1/?node). diff --git a/test/app/watson-conversation/node/server.js b/test/app/watson-conversation/node/server.js new file mode 100644 index 00000000..33c45443 --- /dev/null +++ b/test/app/watson-conversation/node/server.js @@ -0,0 +1,31 @@ +/* eslint-disable */ +app.get('/watson-conversation-test', function (req, res) { + let messages = []; + + /* workspace_id is not a supplied credential from service_manager, + * as each conversation service can have several workspaces. + * thus exposing the credential, while not ideal, in this case is okay + */ + + var workspace_id = 'bdce14dd-65ce-4e50-91b9-dea4d7445393' + var conversation = serviceManager.get('watson-conversation'); + + if (!conversation) { + res.status(500).send('watson-conversation is not defined in serviceManager'); + return; + } + + conversation.message({ + workspace_id: workspace_id, + input: { 'text': 'Hello' } + }, function (err, response) { + if (err) { + console.log('error:', err); + res.status(400).json(err); + } + else { + console.log(JSON.stringify(response, null, 2)); + res.status(200).send('received response for conversation'); + } + }); +}); diff --git a/test/integration-node-express-test.js b/test/integration-node-express-test.js index 60b61875..e66ec8c9 100644 --- a/test/integration-node-express-test.js +++ b/test/integration-node-express-test.js @@ -51,8 +51,8 @@ describe('integration test for services', function () { }); }); - describe('ObjectStorage', function() { - it('should create a container `test` and write content', function() { + describe('ObjectStorage', function () { + it('should create a container `test` and write content', function () { this.timeout(30000); let expectedMessages = [ 'test container was created', @@ -110,7 +110,7 @@ describe('integration test for services', function () { it('should login anon to web strategy', function (done) { this.timeout(12000); let expectedMessage = { - points : "1337" + points: "1337" }; let options = { @@ -120,8 +120,8 @@ describe('integration test for services', function () { }; let j = request.jar(); let cookie; - request(options, function(error, response){ - if(error){ + request(options, function (error, response) { + if (error) { assert.isNotOk(error, 'This should not happen - login web'); done(); @@ -148,7 +148,7 @@ describe('integration test for services', function () { } else { //redirect to protected resource options.method = 'GET'; - options.uri = response.headers.location.indexOf('http') > -1 ? response.headers.location : 'http://localhost:3000' + response.headers.location ; + options.uri = response.headers.location.indexOf('http') > -1 ? response.headers.location : 'http://localhost:3000' + response.headers.location; options.headers = response.request.headers; request(options, function (error, response) { if (error) { @@ -170,8 +170,8 @@ describe('integration test for services', function () { }); }); - describe('Push', function() { - it('should create a push notification', function() { + describe('Push', function () { + it('should create a push notification', function () { this.timeout(30000); let options = { 'method': 'get', @@ -179,11 +179,11 @@ describe('integration test for services', function () { }; return axios(options) - .then(function(response) { + .then(function (response) { assert.deepEqual(response.data.message, { alert: 'Testing BluemixPushNotifications' }); }) - .catch(function(err){ - if(err.response){ + .catch(function (err) { + if (err.response) { assert.isNotOk(err.response.data, 'This should not happen'); } else { assert.isNotOk(JSON.stringify(err), 'This should not happen'); @@ -193,8 +193,8 @@ describe('integration test for services', function () { }); }); - describe('Alert-Notification', function() { - it('should send a sample alert', function() { + describe('Alert-Notification', function () { + it('should send a sample alert', function () { this.timeout(30000); let expectedMessages = [ 'alert sent' @@ -219,6 +219,30 @@ describe('integration test for services', function () { }); }); }); + + describe('Watson-Conversation', function () { + it('should be able to send input and receive a response', function () { + this.timeout(30000); + + let expectedMessage = ['received response for conversation']; + let options = { + 'method': 'get', + 'url': 'http://localhost:3000/watson-conversation-test' + }; + return axios(options) + .then(function (response) { + assert.deepEqual(response.data, expectedMessage); + }) + .catch(function (err) { + if (err.response) { + assert.isNotOk(err.response.data, 'This should not happen'); + } else { + console.log('ERR ' + err.toString()); + assert.isNotOk(err, 'This should not happen'); + } + }); + }); + }); }); let _setUpApplication = function (cb) { @@ -234,12 +258,12 @@ let _setUpApplication = function (cb) { bluemix: JSON.stringify(optionsBluemix) }) .then((tmpDir) => { - execRun('npm install', {cwd: tmpDir}, function (error, stdout) { + execRun('npm install', { cwd: tmpDir }, function (error, stdout) { if (error) { assert.isOk('Could not install dependencies ' + error); } else { console.log(stdout); - execRun('npm install --save express express-session axios body-parser', {cmd: tmpDir}, function (error, stdout) { + execRun('npm install --save express express-session axios body-parser', { cmd: tmpDir }, function (error, stdout) { if (error) { assert.isOk('Could not install express, body-parser, axios and express-session', error); cb(); @@ -270,7 +294,7 @@ let _destroyApplication = function (cb) { }; let _generateApplication = function (cb) { - const serviceNames = ['cloudant', 'object-storage', 'appId', 'push', 'mongodb', 'alertnotification']; + const serviceNames = ['cloudant', 'object-storage', 'appId', 'push', 'mongodb', 'alertnotification', 'watson-conversation']; const REPLACE_CODE_HERE = '// GENERATE HERE'; let snippetJS; From 1ca58b0230bafa7af14352896e8f3e659368040a Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Fri, 27 Oct 2017 16:05:00 -0500 Subject: [PATCH 2/8] redis initial commit --- .../service-redis/templates/node/README.md | 23 +++++++++++++++ test/app/redis/node/server.js | 21 ++++++++++++++ test/integration-node-express-test.js | 28 ++++++++++++++++++- test/lib/service-helpers.js | 15 ++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 test/app/redis/node/server.js diff --git a/generators/service-redis/templates/node/README.md b/generators/service-redis/templates/node/README.md index e69de29b..82871113 100644 --- a/generators/service-redis/templates/node/README.md +++ b/generators/service-redis/templates/node/README.md @@ -0,0 +1,23 @@ +# Redis + +Redis is a powerful, in-memory key/value store which can act as a cache, queue or transient store in your database stack. The Redis platform is designed to solve practical problems in the modern application stack and offers a chance to use counters, queues, lists and hyperloglogs to handle complex data issues simply. Redis is the modern developers’ multi-bladed tool with something to offer in every use case. + +## Credentials + +### LocalDevConfig + +This is where your local configuration is stored for Redis. +``` +{ + "redis_uri": "{{{uri}}}" +} +``` + +## Usage + +The `service_manager` returns an instance of a `redis` instance configured to connect to the supplied database. Database management is done using the `redis` client, whose full documentation can [be found here](https://pypi.python.org/pypi/redis), +but a small getting started example can be found below: + +```javascript + +``` diff --git a/test/app/redis/node/server.js b/test/app/redis/node/server.js new file mode 100644 index 00000000..dec867ea --- /dev/null +++ b/test/app/redis/node/server.js @@ -0,0 +1,21 @@ +/* eslint-disable */ +app.get('/redis-test', function (req, res) { + let messages = []; + + var redis = serviceManager.get('redis'); + console.log("** got redis") + if (!redis) { + res.status(500).send('redis is not defined in serviceManager'); + return; + } + + redis.set("test-key", "test-val"); + messages.push("set data"); + + console.log("** gonna try to get....") + redis.get("test-key", function (err, response) { + + console.log("***** response"); + + }) +}); diff --git a/test/integration-node-express-test.js b/test/integration-node-express-test.js index e66ec8c9..ed8b3645 100644 --- a/test/integration-node-express-test.js +++ b/test/integration-node-express-test.js @@ -242,6 +242,32 @@ describe('integration test for services', function () { } }); }); + + describe('Redis', function() { + it('should be able to set and get data', function() { + this.timeout(30000); + let expectedMessage = ['set data', 'got data']; + let options = { + 'method': 'get', + 'url': 'http://localhost:3000/redis-test' + }; + + return axios(options) + .then(function(response) { + console.log("** " + response.data) + assert.deepEqual(response.data, expectedMessage); + }) + .catch(function(err){ + console.error("** err: " + err) + if(err.response){ + assert.isNotOk(err.response.data, 'This should not happen'); + } else { + console.log('ERR ' + err.toString()); + assert.isNotOk(err, 'This should not happen'); + } + }); + }); + }); }); }); @@ -294,7 +320,7 @@ let _destroyApplication = function (cb) { }; let _generateApplication = function (cb) { - const serviceNames = ['cloudant', 'object-storage', 'appId', 'push', 'mongodb', 'alertnotification', 'watson-conversation']; + const serviceNames = ['cloudant', 'object-storage', 'appId', 'push', 'mongodb', 'alertnotification', 'watson-conversation', 'redis']; const REPLACE_CODE_HERE = '// GENERATE HERE'; let snippetJS; diff --git a/test/lib/service-helpers.js b/test/lib/service-helpers.js index 9caf2996..29d9790c 100644 --- a/test/lib/service-helpers.js +++ b/test/lib/service-helpers.js @@ -121,6 +121,21 @@ function serviceAlertNotification(optionsBluemix) { }; } +function serviceRedis(optionsBluemix) { + console.log("***** OPTIONSBLUEMIX redis: " + optionsBluemix.redis + " " + optionsBluemix.redis.uri) + return { + location: 'service-redis', + bluemixName: 'redis', + localDevConfig: { + redis_uri: optionsBluemix.redis.uri + }, + instrumentation: { + java_liberty: [], + java_spring: [] + } + }; +} + function serviceTest(optionsBluemix) { return { location: 'service-test', From 62a2a06f96ecdfa671daf63b42255fc0befb5333 Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Mon, 30 Oct 2017 12:41:26 -0500 Subject: [PATCH 3/8] update watson and redis tests --- test/app/redis/node/server.js | 13 ++++-- test/app/watson-conversation/node/server.js | 7 ++-- test/integration-node-express-test.js | 46 ++++++++++----------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/test/app/redis/node/server.js b/test/app/redis/node/server.js index dec867ea..1cd2a8ea 100644 --- a/test/app/redis/node/server.js +++ b/test/app/redis/node/server.js @@ -3,19 +3,24 @@ app.get('/redis-test', function (req, res) { let messages = []; var redis = serviceManager.get('redis'); - console.log("** got redis") if (!redis) { res.status(500).send('redis is not defined in serviceManager'); return; } redis.set("test-key", "test-val"); + messages.push("set data"); - console.log("** gonna try to get....") redis.get("test-key", function (err, response) { - - console.log("***** response"); + if (err) { + res.status(400).json(err); + } + else { + // console.log(JSON.stringify(response, null, 2)); + messages.push("got data"); + res.status(202).json(messages); + } }) }); diff --git a/test/app/watson-conversation/node/server.js b/test/app/watson-conversation/node/server.js index 33c45443..469d13ef 100644 --- a/test/app/watson-conversation/node/server.js +++ b/test/app/watson-conversation/node/server.js @@ -7,13 +7,14 @@ app.get('/watson-conversation-test', function (req, res) { * thus exposing the credential, while not ideal, in this case is okay */ - var workspace_id = 'bdce14dd-65ce-4e50-91b9-dea4d7445393' + var workspace_id = 'df5a2ec4-943d-410e-835f-e85bd63e3a7c'; var conversation = serviceManager.get('watson-conversation'); if (!conversation) { res.status(500).send('watson-conversation is not defined in serviceManager'); return; } + messages.push("received response for conversation"); conversation.message({ workspace_id: workspace_id, @@ -24,8 +25,8 @@ app.get('/watson-conversation-test', function (req, res) { res.status(400).json(err); } else { - console.log(JSON.stringify(response, null, 2)); - res.status(200).send('received response for conversation'); + //console.log(JSON.stringify(response, null, 2)); + res.status(202).json(messages); } }); }); diff --git a/test/integration-node-express-test.js b/test/integration-node-express-test.js index ed8b3645..cc082ce3 100644 --- a/test/integration-node-express-test.js +++ b/test/integration-node-express-test.js @@ -242,31 +242,29 @@ describe('integration test for services', function () { } }); }); + }); - describe('Redis', function() { - it('should be able to set and get data', function() { - this.timeout(30000); - let expectedMessage = ['set data', 'got data']; - let options = { - 'method': 'get', - 'url': 'http://localhost:3000/redis-test' - }; - - return axios(options) - .then(function(response) { - console.log("** " + response.data) - assert.deepEqual(response.data, expectedMessage); - }) - .catch(function(err){ - console.error("** err: " + err) - if(err.response){ - assert.isNotOk(err.response.data, 'This should not happen'); - } else { - console.log('ERR ' + err.toString()); - assert.isNotOk(err, 'This should not happen'); - } - }); - }); + describe('Redis', function () { + it('should be able to set and get data', function () { + this.timeout(30000); + let expectedMessage = ['set data', 'got data']; + let options = { + 'method': 'get', + 'url': 'http://localhost:3000/redis-test' + }; + + return axios(options) + .then(function (response) { + assert.deepEqual(response.data, expectedMessage); + }) + .catch(function (err) { + if (err.response) { + assert.isNotOk(err.response.data, 'This should not happen'); + } else { + console.log('ERR ' + err.toString()); + assert.isNotOk(err, 'This should not happen'); + } + }); }); }); }); From 6c801e087b9dd29e0c28a6fe9fe656b33348b46a Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Tue, 31 Oct 2017 12:10:21 -0500 Subject: [PATCH 4/8] python tests --- test/app/postgre/node/server.js | 36 +++++++++++++++++++++++++++ test/integration-node-express-test.js | 26 ++++++++++++++++++- test/lib/service-helpers.js | 17 ++++++++++++- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 test/app/postgre/node/server.js diff --git a/test/app/postgre/node/server.js b/test/app/postgre/node/server.js new file mode 100644 index 00000000..24e31171 --- /dev/null +++ b/test/app/postgre/node/server.js @@ -0,0 +1,36 @@ +/* eslint-disable */ +app.get('/postgre-test', function (req, res) { + let messages = []; + pair = (100, "abc'def") + var client = serviceManager.get('postgre-client'); + if (!client) { + res.status(500).send('postgre is not defined in serviceManager'); + return; + } + + client.query('CREATE TABLE IF NOT EXISTS "sch.test" (var1 varchar(256) NOT NULL, var2 varchar(256) NOT NULL);', function (err, result) { + if (err) { + res.status(500).send(err); + } + else { + client.query('INSERT INTO "sch.test" (var1, var2) VALUES ($1, $2)', [pair[0], pair[1]], function (err2, result2) { + if (err2) { + console.log("err after insert: " + err2) + // return; + } + }); + // client.query('INSERT INTO test (num, data) VALUES ($1, $2)', [pair[0], pair[1]]); + client.query('SELECT * FROM "sch.test";', function (err3, result3) { + if (err3) { + res.status(500).send(err3); + } else { + messages.push('created and fetched data') + res.status(202).json(messages); + } + + }); + } + }); +}); + + diff --git a/test/integration-node-express-test.js b/test/integration-node-express-test.js index cc082ce3..aca6dfe2 100644 --- a/test/integration-node-express-test.js +++ b/test/integration-node-express-test.js @@ -267,6 +267,30 @@ describe('integration test for services', function () { }); }); }); + + describe('Postgre', function () { + it('should be able to set and get data', function () { + this.timeout(30000); + let expectedMessage = ['created and fetched data']; + let options = { + 'method': 'get', + 'url': 'http://localhost:3000/postgre-test' + }; + + return axios(options) + .then(function (response) { + assert.deepEqual(response.data, expectedMessage); + }) + .catch(function (err) { + if (err.response) { + assert.isNotOk(err.response.data, 'This should not happen'); + } else { + assert.isNotOk(err, 'This should not happen'); + } + }); + }); + }); + }); let _setUpApplication = function (cb) { @@ -318,7 +342,7 @@ let _destroyApplication = function (cb) { }; let _generateApplication = function (cb) { - const serviceNames = ['cloudant', 'object-storage', 'appId', 'push', 'mongodb', 'alertnotification', 'watson-conversation', 'redis']; + const serviceNames = ['cloudant', 'object-storage', 'appId', 'push', 'mongodb', 'alertnotification', 'watson-conversation', 'redis', 'postgre']; const REPLACE_CODE_HERE = '// GENERATE HERE'; let snippetJS; diff --git a/test/lib/service-helpers.js b/test/lib/service-helpers.js index 29d9790c..8f44edc0 100644 --- a/test/lib/service-helpers.js +++ b/test/lib/service-helpers.js @@ -122,7 +122,6 @@ function serviceAlertNotification(optionsBluemix) { } function serviceRedis(optionsBluemix) { - console.log("***** OPTIONSBLUEMIX redis: " + optionsBluemix.redis + " " + optionsBluemix.redis.uri) return { location: 'service-redis', bluemixName: 'redis', @@ -136,6 +135,22 @@ function serviceRedis(optionsBluemix) { }; } +function servicePostgre(optionsBluemix) { + return { + location: 'service-postgre', + bluemixName: 'postgre', + localDevConfig: { + postgre_uri: optionsBluemix.postgre.uri, + postgre_ca_certificate_base64: optionsBluemix.postgre.ca_certificate_base64, + postgre_deployment_id: optionsBluemix.postgre.deployment_id + }, + instrumentation: { + java_liberty: [], + java_spring: [] + } + }; +} + function serviceTest(optionsBluemix) { return { location: 'service-test', From cd2de44f4d379d30e5d0413b89777fe70674e3c2 Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Wed, 1 Nov 2017 13:42:56 -0500 Subject: [PATCH 5/8] cleanup test cases --- test/app/postgre/node/server.js | 43 +++++++++++---------- test/app/redis/node/server.js | 4 +- test/app/watson-conversation/node/server.js | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/test/app/postgre/node/server.js b/test/app/postgre/node/server.js index 24e31171..5205a16c 100644 --- a/test/app/postgre/node/server.js +++ b/test/app/postgre/node/server.js @@ -1,35 +1,38 @@ /* eslint-disable */ app.get('/postgre-test', function (req, res) { + let messages = []; pair = (100, "abc'def") + var client = serviceManager.get('postgre-client'); + if (!client) { - res.status(500).send('postgre is not defined in serviceManager'); + res.status(500).send('postgre-client is not defined in serviceManager'); return; } - client.query('CREATE TABLE IF NOT EXISTS "sch.test" (var1 varchar(256) NOT NULL, var2 varchar(256) NOT NULL);', function (err, result) { + client.query('CREATE TABLE IF NOT EXISTS "sch.test" (var1 integer NOT NULL, var2 varchar(256) NOT NULL);', function (err, result) { if (err) { res.status(500).send(err); + return; } - else { - client.query('INSERT INTO "sch.test" (var1, var2) VALUES ($1, $2)', [pair[0], pair[1]], function (err2, result2) { - if (err2) { - console.log("err after insert: " + err2) - // return; - } - }); - // client.query('INSERT INTO test (num, data) VALUES ($1, $2)', [pair[0], pair[1]]); - client.query('SELECT * FROM "sch.test";', function (err3, result3) { - if (err3) { - res.status(500).send(err3); - } else { - messages.push('created and fetched data') - res.status(202).json(messages); - } - - }); - } + + client.query('INSERT INTO "sch.test" (var1, var2) VALUES ($1, $2)', [pair[0], pair[1]], function (err, result) { + if (err) { + res.status(500).send(err); + return; + } + }); + client.query('SELECT * FROM "sch.test";', function (err, result) { + if (err) { + res.status(500).send(err); + } else { + messages.push('created and fetched data') + res.status(202).json(messages); + } + + }); + }); }); diff --git a/test/app/redis/node/server.js b/test/app/redis/node/server.js index 1cd2a8ea..eab43032 100644 --- a/test/app/redis/node/server.js +++ b/test/app/redis/node/server.js @@ -1,8 +1,10 @@ /* eslint-disable */ app.get('/redis-test', function (req, res) { + let messages = []; var redis = serviceManager.get('redis'); + if (!redis) { res.status(500).send('redis is not defined in serviceManager'); return; @@ -17,10 +19,8 @@ app.get('/redis-test', function (req, res) { res.status(400).json(err); } else { - // console.log(JSON.stringify(response, null, 2)); messages.push("got data"); res.status(202).json(messages); } - }) }); diff --git a/test/app/watson-conversation/node/server.js b/test/app/watson-conversation/node/server.js index 469d13ef..c1fb4a4a 100644 --- a/test/app/watson-conversation/node/server.js +++ b/test/app/watson-conversation/node/server.js @@ -14,6 +14,7 @@ app.get('/watson-conversation-test', function (req, res) { res.status(500).send('watson-conversation is not defined in serviceManager'); return; } + messages.push("received response for conversation"); conversation.message({ @@ -25,7 +26,6 @@ app.get('/watson-conversation-test', function (req, res) { res.status(400).json(err); } else { - //console.log(JSON.stringify(response, null, 2)); res.status(202).json(messages); } }); From faea0fa445ae3b255cfec05303d9aace8558166f Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Wed, 1 Nov 2017 16:05:09 -0500 Subject: [PATCH 6/8] add READMEs --- .../service-postgre/templates/node/README.md | 48 +++++++++++++++++++ .../service-redis/templates/node/README.md | 15 +++++- .../templates/node/README.md | 16 ++++++- test/app/postgre/node/server.js | 2 - test/app/redis/node/server.js | 8 ++-- test/app/watson-conversation/node/server.js | 2 + 6 files changed, 83 insertions(+), 8 deletions(-) diff --git a/generators/service-postgre/templates/node/README.md b/generators/service-postgre/templates/node/README.md index e69de29b..49911e4c 100644 --- a/generators/service-postgre/templates/node/README.md +++ b/generators/service-postgre/templates/node/README.md @@ -0,0 +1,48 @@ +# Postgre + +Postgres is a powerful, open source object-relational database that is highly customizable. Build apps quickly and scale easily with hosted and fully managed PostgreSQL, a feature-rich open source SQL database. Compose for PostgreSQL makes Postgres even better by managing it for you. This includes offering an easy, auto-scaling deployment system which delivers high availability and redundancy, automated no-stop backups and much more. + +## Credentials + +### LocalDevConfig + +This is where your local configuration is stored for Postgre. +``` +{ + "postgre_uri": "{{uri}}" +} +``` + +## Usage + +The `service_manager` returns an instance of a `postgre-client` instance configured to connect to the supplied database. Database management is done using the `pg` client, whose full documentation can [be found here](https://www.npmjs.com/package/pg), +but a small getting started example can be found below: + +```javascript + pair = (100, "abc'def") + + var client = serviceManager.get('postgre-client'); + + client.query('CREATE TABLE IF NOT EXISTS "sch.test" (var1 integer NOT NULL, var2 varchar(256) NOT NULL);', function (err, result) { + if (err) { + console.log('error:', err); + return; + } + + client.query('INSERT INTO "sch.test" (var1, var2) VALUES ($1, $2)', [pair[0], pair[1]], function (err, result) { + if (err) { + console.log('error:', err); + return; + } + }); + client.query('SELECT * FROM "sch.test";', function (err, result) { + if (err) { + console.log('error:', err); + } else { + console.log(JSON.stringify(result, null, 2)); + } + + }); + + }); +``` diff --git a/generators/service-redis/templates/node/README.md b/generators/service-redis/templates/node/README.md index 82871113..d753aecf 100644 --- a/generators/service-redis/templates/node/README.md +++ b/generators/service-redis/templates/node/README.md @@ -15,9 +15,20 @@ This is where your local configuration is stored for Redis. ## Usage -The `service_manager` returns an instance of a `redis` instance configured to connect to the supplied database. Database management is done using the `redis` client, whose full documentation can [be found here](https://pypi.python.org/pypi/redis), +The `service_manager` returns an instance of a `redis` instance configured to connect to the supplied database. Database management is done using the `redis` client, whose full documentation can [be found here](https://www.npmjs.com/package/redis), but a small getting started example can be found below: ```javascript - + var redis = serviceManager.get('redis'); + + redis.set("test-key", "test-val"); + + redis.get("test-key", function (err, response) { + if (err) { + console.log('error:', err); + } + else { + console.log(JSON.stringify(response, null, 2)); + } + } ``` diff --git a/generators/service-watson-conversation/templates/node/README.md b/generators/service-watson-conversation/templates/node/README.md index fd87e940..1af8c052 100644 --- a/generators/service-watson-conversation/templates/node/README.md +++ b/generators/service-watson-conversation/templates/node/README.md @@ -17,11 +17,25 @@ This is where your local configuration is stored for Watson Conversation. ## Usage -The `service_manager` returns an instance of a `ConversationV1` client which is preconfigured to use the credentials supplied. You will need to specify the `workspace_id` for the conversation workspace you have created, as each service integration can include multiple workspaces. The full documentation for `python ConversationV1` can [be found here](https://www.ibm.com/watson/developercloud/conversation/api/v1/?python), +The `service_manager` returns an instance of a `ConversationV1` client which is preconfigured to use the credentials supplied. You will need to specify the `workspace_id` for the conversation workspace you have created, as each service integration can include multiple workspaces. The full documentation for the `IBM Watson Conversation` service for Node can [be found here](https://www.ibm.com/watson/developercloud/conversation/api/v1/?node), but a small getting started example can be found below: ```javascript + var workspace_id = 'the-workspace-id-from-your-generated-service'; + var serviceManager = require('./services/service-manager'); + + var conversation = serviceManager.get('watson-conversation'); + + conversation.message({ + workspace_id: workspace_id, + input: { 'text': 'Hello!' } + }, function (err, response) { + if (err) + console.log('error:', err); + else + console.log(JSON.stringify(response, null, 2)); + }); ``` ## Extended Example diff --git a/test/app/postgre/node/server.js b/test/app/postgre/node/server.js index 5205a16c..9e585bbd 100644 --- a/test/app/postgre/node/server.js +++ b/test/app/postgre/node/server.js @@ -35,5 +35,3 @@ app.get('/postgre-test', function (req, res) { }); }); - - diff --git a/test/app/redis/node/server.js b/test/app/redis/node/server.js index eab43032..c9102cf0 100644 --- a/test/app/redis/node/server.js +++ b/test/app/redis/node/server.js @@ -1,17 +1,17 @@ /* eslint-disable */ app.get('/redis-test', function (req, res) { - + let messages = []; var redis = serviceManager.get('redis'); - + if (!redis) { res.status(500).send('redis is not defined in serviceManager'); return; } redis.set("test-key", "test-val"); - + messages.push("set data"); redis.get("test-key", function (err, response) { @@ -24,3 +24,5 @@ app.get('/redis-test', function (req, res) { } }) }); + + diff --git a/test/app/watson-conversation/node/server.js b/test/app/watson-conversation/node/server.js index c1fb4a4a..38f10d6f 100644 --- a/test/app/watson-conversation/node/server.js +++ b/test/app/watson-conversation/node/server.js @@ -30,3 +30,5 @@ app.get('/watson-conversation-test', function (req, res) { } }); }); + + From 8df8b381b894ce7424263791063ccf2c49b1942d Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Wed, 1 Nov 2017 18:17:58 -0500 Subject: [PATCH 7/8] remove unused service helpers --- test/lib/service-helpers.js | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/test/lib/service-helpers.js b/test/lib/service-helpers.js index 8f44edc0..9caf2996 100644 --- a/test/lib/service-helpers.js +++ b/test/lib/service-helpers.js @@ -121,36 +121,6 @@ function serviceAlertNotification(optionsBluemix) { }; } -function serviceRedis(optionsBluemix) { - return { - location: 'service-redis', - bluemixName: 'redis', - localDevConfig: { - redis_uri: optionsBluemix.redis.uri - }, - instrumentation: { - java_liberty: [], - java_spring: [] - } - }; -} - -function servicePostgre(optionsBluemix) { - return { - location: 'service-postgre', - bluemixName: 'postgre', - localDevConfig: { - postgre_uri: optionsBluemix.postgre.uri, - postgre_ca_certificate_base64: optionsBluemix.postgre.ca_certificate_base64, - postgre_deployment_id: optionsBluemix.postgre.deployment_id - }, - instrumentation: { - java_liberty: [], - java_spring: [] - } - }; -} - function serviceTest(optionsBluemix) { return { location: 'service-test', From 8a8fe64df817b3a36a9729c87ebcc1e795d052bc Mon Sep 17 00:00:00 2001 From: jkingoliver Date: Wed, 1 Nov 2017 23:19:23 -0500 Subject: [PATCH 8/8] expand test cases --- test/app/postgre/node/server.js | 26 +++++++++++++-------- test/app/redis/node/server.js | 15 ++++++++---- test/app/watson-conversation/node/server.js | 6 +++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/test/app/postgre/node/server.js b/test/app/postgre/node/server.js index 9e585bbd..d68f3289 100644 --- a/test/app/postgre/node/server.js +++ b/test/app/postgre/node/server.js @@ -2,7 +2,7 @@ app.get('/postgre-test', function (req, res) { let messages = []; - pair = (100, "abc'def") + var pair = [1, "two"] var client = serviceManager.get('postgre-client'); @@ -11,27 +11,33 @@ app.get('/postgre-test', function (req, res) { return; } - client.query('CREATE TABLE IF NOT EXISTS "sch.test" (var1 integer NOT NULL, var2 varchar(256) NOT NULL);', function (err, result) { + client.query('CREATE TABLE IF NOT EXISTS "sch.test" (num integer NOT NULL, data varchar(256) NOT NULL);', function (err, result) { + if (err) { - res.status(500).send(err); + res.status(400).send(err); return; } - client.query('INSERT INTO "sch.test" (var1, var2) VALUES ($1, $2)', [pair[0], pair[1]], function (err, result) { + client.query('INSERT INTO "sch.test" (num, data) VALUES ($1, $2)', [pair[0], pair[1]], function (err, result) { if (err) { - res.status(500).send(err); + res.status(400).send(err); return; } }); client.query('SELECT * FROM "sch.test";', function (err, result) { if (err) { - res.status(500).send(err); + res.status(400).send(err); } else { - messages.push('created and fetched data') - res.status(202).json(messages); + + if (result.rows[0].num == pair[0] && result.rows[0].data == pair[1]) { + messages.push('created and fetched data') + client.query('DROP TABLE IF EXISTS "sch.test";'); + res.status(202).json(messages); + } + else { + res.status(400).send('error processing data'); + } } - }); - }); }); diff --git a/test/app/redis/node/server.js b/test/app/redis/node/server.js index c9102cf0..361ed279 100644 --- a/test/app/redis/node/server.js +++ b/test/app/redis/node/server.js @@ -2,6 +2,8 @@ app.get('/redis-test', function (req, res) { let messages = []; + let key = "test-key"; + let val = "test-val"; var redis = serviceManager.get('redis'); @@ -10,17 +12,22 @@ app.get('/redis-test', function (req, res) { return; } - redis.set("test-key", "test-val"); + redis.set(key, val); messages.push("set data"); - redis.get("test-key", function (err, response) { + redis.get(key, function (err, response) { if (err) { res.status(400).json(err); } else { - messages.push("got data"); - res.status(202).json(messages); + if (response == val) { + messages.push("got data"); + res.status(202).json(messages); + } + else { + res.status(400).send('error processing data'); + } } }) }); diff --git a/test/app/watson-conversation/node/server.js b/test/app/watson-conversation/node/server.js index 38f10d6f..41f9c3c1 100644 --- a/test/app/watson-conversation/node/server.js +++ b/test/app/watson-conversation/node/server.js @@ -22,12 +22,14 @@ app.get('/watson-conversation-test', function (req, res) { input: { 'text': 'Hello' } }, function (err, response) { if (err) { - console.log('error:', err); res.status(400).json(err); } - else { + else if (response.output.text) { res.status(202).json(messages); } + else { + res.status(400).json('Error processing response') + } }); });