aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-bdd/stepDefinitions
diff options
context:
space:
mode:
authorilanap <ilanap@amdocs.com>2018-02-04 17:06:22 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-02-08 09:30:17 +0000
commit637206b5e05910cc3bdd64bbd35d296ce282524c (patch)
treecec62c6939197229fd69fde997f9ed8d27d654e4 /openecomp-bdd/stepDefinitions
parent20074c4e75e926977b25d57bebf841f44ada12a0 (diff)
Adding BDD cucumber testing component
Change-Id: I4fd7eb798cbc7cad85562453fb0a6f74fd12ff5b Issue-ID: SDC-990 Signed-off-by: ilanap <ilanap@amdocs.com>
Diffstat (limited to 'openecomp-bdd/stepDefinitions')
-rw-r--r--openecomp-bdd/stepDefinitions/Collaboration_Steps.js113
-rw-r--r--openecomp-bdd/stepDefinitions/General_Steps.js217
-rw-r--r--openecomp-bdd/stepDefinitions/InputData_steps.js83
-rw-r--r--openecomp-bdd/stepDefinitions/Item_steps.js67
-rw-r--r--openecomp-bdd/stepDefinitions/NetworkPackage_steps.js54
-rw-r--r--openecomp-bdd/stepDefinitions/Questionnaire_steps.js80
-rw-r--r--openecomp-bdd/stepDefinitions/REST_Steps.js69
-rw-r--r--openecomp-bdd/stepDefinitions/Utils.js128
-rw-r--r--openecomp-bdd/stepDefinitions/VF_steps.js43
-rw-r--r--openecomp-bdd/stepDefinitions/VLM_steps.js47
-rw-r--r--openecomp-bdd/stepDefinitions/VSP_steps.js110
-rw-r--r--openecomp-bdd/stepDefinitions/world.js69
12 files changed, 1080 insertions, 0 deletions
diff --git a/openecomp-bdd/stepDefinitions/Collaboration_Steps.js b/openecomp-bdd/stepDefinitions/Collaboration_Steps.js
new file mode 100644
index 0000000000..5b5062cf34
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/Collaboration_Steps.js
@@ -0,0 +1,113 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When, Given} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+
+/**
+ * @module Collaboration
+ * @description Adds the user with the given user ID as a contributor on the item
+ * @exampleFile Example_Collaboration.feature
+ * @step I want to add user {string} as a contributor to this Item
+ **/
+When('I want to add user {string} as a contributor to this Item', function(string) {
+ let path = '/items/' + this.context.item.id + '/permissions/Contributor';
+ let inputData = {removedUsersIds:[],addedUsersIds:[string]};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
+/**
+ * @module Collaboration
+ * @description Adds the user with the given user ID as a contributor on the item
+ * @exampleFile Example_Collaboration.feature
+ * @step I want to remove user {string} as a contributor to this Item
+ **/
+When('I want to remove user {string} as a contributor to this Item', function(string) {
+ let path = '/items/' + this.context.item.id + '/permissions/Contributor';
+ let inputData = {removedUsersIds:[string],addedUsersIds:[]};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
+/**
+ * @module Collaboration
+ * @description Changes the owner to the given User ID
+ * @exampleFile Example_Collaboration.feature
+ * @step I want to change the owner to user {string} on this Item
+ **/
+When('I want to change the owner to user {string} on this Item', function(string) {
+ let path = '/items/' + this.context.item.id + '/permissions/Owner';
+ let inputData = {removedUsersIds:[],addedUsersIds:[string]};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
+
+/**
+ * @module Collaboration
+ * @description Checks the role for a user on the item by User id and Role can be either: Contributor/Owner
+ * @exampleFile Example_Collaboration.feature
+ * @step I want check user {string} has role {string} on this Item
+ **/
+When('I want to check user {string} has role {string} on this Item', function(string, string2) {
+ let path = '/items/' + this.context.item.id + '/permissions';
+ return util.request(this.context, 'GET', path).then(results => {
+ for (i in results.data.results) {
+ if (results.data.results[i].userId === string) {
+ assert.equal(string2.toLowerCase(), results.data.results[i].permission.toLowerCase());
+ return;
+ }
+ }
+ assert.fail('User not found');
+ });
+});
+
+/**
+ * @module Collaboration
+ * @description Checks the user wth this Id has no permissions on this item
+ * @exampleFile Example_Collaboration.feature
+ * @step I want check user {string} has rno permissions on this Item
+ **/
+When('I want to check user {string} has no permissions on this Item', function(string) {
+ let path = '/items/' + this.context.item.id + '/permissions';
+ return util.request(this.context, 'GET', path).then(results => {
+ for (i in results.data.results) {
+ if (results.data.results[i].userId === string) {
+ assert.fail('Found', null, 'User should not have permissions');
+ return;
+ }
+ }
+ });
+});
+
+/**
+ * @module Collaboration
+ * @description Gets the permissions for the Item
+ * @exampleFile Example_Collaboration.feature
+ * @step I want to get the permissions for this Item
+ **/
+When('I want to get the permissions for this Item', function() {
+ let path = '/items/' + this.context.item.id + '/permissions';
+ return util.request(this.context, 'GET', path);
+});
+
+/**
+ * @module Collaboration
+ * @description Changes the user for the Rest calls
+ * @exampleFile Example_Collaboration.feature
+ * @step I want to set the user to {string}
+ **/
+When('I want to set the user to {string}', function(string) {
+ this.context.headers.USER_ID = string;
+});
diff --git a/openecomp-bdd/stepDefinitions/General_Steps.js b/openecomp-bdd/stepDefinitions/General_Steps.js
new file mode 100644
index 0000000000..389112da84
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/General_Steps.js
@@ -0,0 +1,217 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When, Given} = require('cucumber');
+const assert = require('assert');
+const _ = require('lodash');
+const normalizeNewline = require('normalize-newline');
+require('node-zip');
+YAML = require('yamljs');
+const fs = require('fs');
+const util = require('./Utils.js');
+
+/**
+ * @module ContextData
+ * @description Use with "Given". Use ONLY for local testing when you know the value of the Item you want to use
+ * instead of creating a new one.
+ * @step Item {string} and version Id {string}
+ **/
+Given('Item {string} and version Id {string}', function (string, string2) {
+ this.context.item.id = string;
+ this.context.item.versionId = string2;
+});
+/**
+ * @module ContextData
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @description Response Data::<br>
+ * """<br>
+ * {jsonObject}<br>
+ * """<br>
+ * @step Use with "Given". Use ONLY for local testing, creates a response data object
+ **/
+Given('Response Data:', function (docString) {
+ this.context.responseData = JSON.parse(docString);
+});
+
+/**
+ * @module ContextData
+ * @description Sets the server for the test. overrides configuration.
+ * @step Server with IP
+ **/
+Given('Server host {string}', function (string) {
+ this.setServer(string);
+});
+
+/**
+ * @module ContextData
+ * @description Copy a property from the response data to context Item/VLM/VSP data, example: vsp.componentId
+ * @step I want to save on the context for {string} property {string} with value {string}
+ **/
+Then('I want to save on the context for {string} property {string} with value {string}', function(string, string1, string2) {
+ assert.equal(_.includes(['VLM', 'VSP', 'Item'], string), true);
+ let val = _.get(this.context.responseData, string2);
+ _.set(this.context, string1, val);
+});
+/**
+ * @module ContextData
+ * @description Copy a property from the response data to saved data on the context. Example: save newly generated IDs. Response data value can be from a path, xample: results[0].id
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to save to property {string} from response data path {string}
+ **/
+Then('I want to copy to property {string} from response data path {string}', function(string, string2) {
+ let val = _.get(this.context.responseData, string2);
+ _.set(this.context, string, val);
+});
+/**
+ * @module ContextData
+ * @description This will set the value of a saved property on the context
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to set property {string} to value {string}
+ **/
+Then('I want to set property {string} to value {string}', function(string, string2) {
+ _.set(this.context, string, string2);
+});
+
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a value. property can be a path (example: results[0].id)
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @step I want to check property {string} for value {string}
+ **/
+Then('I want to check property {string} for value {string}', function(string, string2) {
+ assert.equal(_.get(this.context.responseData, string), string2);
+});
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a integer. property can be a path (example: results[0].id)
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @step I want to check property {string} for value {int}
+ **/
+Then('I want to check property {string} for value {int}', function(string, int) {
+ assert.equal(_.get(this.context.responseData, string), int);
+});
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a boolean. property can be a path (example: results[0].id)
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @step I want to check property {string} to be "True/False"
+ **/
+Then('I want to check property {string} to be {string}', function(string, string2) {
+ assert.equal(_.get(this.context.responseData, string), string2.toLowerCase());
+});
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a boolean. property can be a path (example: results[0].id)
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @step I want to check property {string} to have length {int}
+ **/
+Then('I want to check property {string} to have length {int}', function(string, intLength) {
+ let arrayProp = _.get(this.context.responseData, string);
+ assert.equal(arrayProp.length, intLength);
+});
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and make sure it exists
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @step I want to check property {string} exists
+ **/
+Then('I want to check property {string} exists', function(string) {
+ assert.equal(_.has(this.context.responseData, string), true);
+});
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and make sure it does not exist
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @step I want to check property {string} does not exist
+ **/
+Then('I want to check property {string} does not exist', function(string) {
+ assert.equal(_.has(this.context.responseData, string), false);
+});
+
+/**
+* @module ContextData
+* @description Use during development to see what is on the context
+ * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+* @step I want to print context data
+**/
+Then('I want to print the context data', function() {
+ console.log('------------ context ---------------');
+ console.log(JSON.stringify(this.context, null, 2));
+ console.log('--------------------------------------');
+});
+/**
+ * @module ContextData
+ * @description Set this in order to check that the following Rest call will not have response code 200
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want the following to fail
+ **/
+Then('I want the following to fail', function() {
+ this.context.shouldFail = true;
+});
+
+/**
+ * @module ContextData
+ * @description Set this in order to check that the following Rest call will have the error code on the return data
+ * @exampleFile Example_VSP.feature
+ * @step I want the following to fail with error code {string}
+ **/
+Then('I want the following to fail with error code {string}', function(string) {
+ this.context.shouldFail = true;
+ this.context.errorCode = string;
+});
+
+/**
+ * @module ZipData
+ * @description Use this in order to extract a file from a zip file and to compare it to a local file (string comparison).
+ * @exampleFile Example_VSP.feature
+ * @step I want to compare the content of the entry {string} in the zip {string} with file {string}
+ **/
+Then ('I want to compare the content of the entry {string} in the zip {string} with file {string}', function (string, string2, string3) {
+ let zipFile = fs.readFileSync(string2, 'binary');
+ let zip = new JSZip(zipFile, {base64: false, checkCRC32: true});
+ let fileData = zip.files[string]._data;
+ let compareFileData = fs.readFileSync(string3, {encoding: 'ascii'});
+ assert.equal(normalizeNewline(compareFileData), normalizeNewline(fileData));
+});
+
+/**
+ * @module ZipData
+ * @description Loads the yaml from zip file onto the context responseData as JSON for running checks on the output
+ * @exampleFile Example_VSP.feature
+ * @step I want to load the yaml content of the entry {string} in the zip {string} to context
+ **/
+Then ('I want to load the yaml content of the entry {string} in the zip {string} to context', function (string, string2, callback) {
+ let zipFile = fs.readFileSync(string2, 'binary');
+ let zip = new JSZip(zipFile, {base64: false, checkCRC32: true});
+ let fileData = zip.files[string]._data;
+ let nativeObject = YAML.parse(fileData);
+ this.context.responseData = nativeObject;
+ callback();
+});
+
+
+/**
+ * @module ZipData
+ * @description Loads the json from zip file onto the context responseData for running check son the output
+ * @exampleFile Example_VSP.feature
+ * @step I want to load the json content of the entry {string} in the zip {string} to context
+ **/
+When('I want to load the json content of the entry {string} in the zip {string} to context', function (string, string2, callback) {
+ let zipFile = fs.readFileSync(string2, 'binary');
+ let zip = new JSZip(zipFile, {base64: false, checkCRC32: true});
+ let str = zip.files[string]._data;
+ this.context.responseData = JSON.parse(str);
+ callback();
+}); \ No newline at end of file
diff --git a/openecomp-bdd/stepDefinitions/InputData_steps.js b/openecomp-bdd/stepDefinitions/InputData_steps.js
new file mode 100644
index 0000000000..73695d0e7f
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/InputData_steps.js
@@ -0,0 +1,83 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When, Given} = require('cucumber');
+const assert = require('assert');
+const _ = require('lodash');
+const fs = require('fs');
+const util = require('./Utils.js');
+
+/**
+ * @module InputData
+ * @description creates an ampty input data object
+ * @exampleFile Example_Rest_Calls.feature, Example_VLM.feature
+ * @step I want to create input data
+ **/
+When('I want to create input data', function () {
+ this.context.inputData = {};
+});
+
+/**
+ * @module InputData
+ * @exampleFile Example_Heat.feature
+ * @description I want to set the input data to:<br>
+ * """<br>
+ * {jsonObject}<br>
+ * """<br>
+ * @step creates an input data element with the given json object
+ **/
+When('I want to set the input data to:', function (docString) {
+ this.context.inputData = JSON.parse(docString);
+});
+
+/**
+ * @module InputData
+ * @description creates an input data object from the json in the given file
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to set the input data to file {string}
+ **/
+When('I want to set the input data to file {string}', function (string) {
+ this.context.inputData = util.getJSONFromFile(string);
+});
+
+/**
+ * @module InputData
+ * @description sets the property on the input data to the given value
+ * @exampleFile Example_Rest_Calls.feature, Example_VLM.feature
+ * @step I want to update the input property {string} with value {string}
+ **/
+Then('I want to update the input property {string} with value {string}', function(string, string2) {
+ _.set(this.context.inputData, string, string2);
+});
+
+/**
+ * @module InputData
+ * @description removes a property from the input data object
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to remove {string} from the input data
+ **/
+Then('I want to remove {string} from the input data', function(string) {
+ delete this.context.inputData[string];
+});
+
+/**
+ * @module InputData
+ * @description sets the input data property to a random value
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to update the input property {string} with a random value
+ **/
+Then('I want to update the input property {string} with a random value', function(string) {
+ _.set(this.context.inputData, string, util.random());
+});
diff --git a/openecomp-bdd/stepDefinitions/Item_steps.js b/openecomp-bdd/stepDefinitions/Item_steps.js
new file mode 100644
index 0000000000..165df6ca30
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/Item_steps.js
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+/**
+ * @module Item
+ * @description uses item id and version id from context
+ * @exampleFile Example_VSP.feature, Example_VLM.feature
+ * @step I want to make sure this Item has status {string}
+ **/
+Then('I want to make sure this Item has status {string}', function (string) {
+ let path = '/items/' + this.context.item.id + '/versions';
+ return util.request(this.context, 'GET', path).then(result => {
+ assert.equal(result.data.results[0].id, this.context.item.versionId);
+ assert.equal(result.data.results[0].status, string);
+ });
+});
+/**
+ * @module Item
+ * @description uses item id and version id from context
+ * @exampleFile Example_VSP.feature, Example_VLM.feature
+ * @step I want to commit this Item
+ **/
+Then('I want to commit this Item', function () {
+ let path = '/items/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
+ let inputData = {action: 'Commit', commitRequest: {message: '00Behave'}};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+/**
+ * @module Item
+ * @description creates a new major version. item id and version id from context
+ * @exampleFile Example_VLM.feature
+ * @step I want to create a new version for this Item
+ **/
+Then('I want to create a new version for this Item', function () {
+ let path = '/items/' + this.context.item.id + '/versions/' + this.context.item.versionId;
+ let inputData = {description: 'Behave Version', creationMethod: 'major'};
+ return util.request(this.context, 'POST', path, inputData).then(result => {
+ assert.equal(result.data.status, 'Draft');
+ });
+});
+/**
+ * @module Item
+ * @description reverts to a revision with a given saved property. Should be set from the revision list first
+ * @exampleFile Example_VLM.feature
+ * @step I want to commit this Item
+ **/
+Then('I want to revert this Item to the revision with the value from saved property {string}', function (string) {
+ let path = '/items/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
+ let inputData = {action: 'Revert', revisionRequest: {revisionId: this.context[string]}};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
diff --git a/openecomp-bdd/stepDefinitions/NetworkPackage_steps.js b/openecomp-bdd/stepDefinitions/NetworkPackage_steps.js
new file mode 100644
index 0000000000..731d5b8470
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/NetworkPackage_steps.js
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+const _ = require('lodash');
+const fs = require('fs');
+require('node-zip');
+
+/**
+ * @module NetworkPackage
+ * @description Uploads the NetworkPackage file to the VSP on the context
+ * @exampleFile Example_HEAT.feature
+ * @step I want to upload a NetworkPackage for this VSP from path {string}
+ **/
+Then('I want to upload a NetworkPackage for this VSP from path {string}', function (string) {
+ let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/orchestration-template-candidate';
+ return util.request(this.context, 'POST', path, string, true);
+});
+
+/**
+ * @module NetworkPackage
+ * @description Downloads the network package to disk
+ * @exampleFile Example_HEAT.feature
+ * @step I want to download the NetworkPackage for this VSP to path {string}
+ **/
+When('I want to download the NetworkPackage for this VSP to path {string}', function (string, callback) {
+ let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/orchestration-template-candidate';
+ return [util.download(this.context, path, string, callback)];
+});
+
+/**
+ * @module NetworkPackage
+ * @description Processes the NetworkPackage file on the server
+ * @exampleFile Example_HEAT.feature
+ * @step I want to process the NetworkPackage file for this VSP
+ **/
+Then('I want to process the NetworkPackage file for this VSP', function () {
+ let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/orchestration-template-candidate/process';
+ return util.request(this.context, 'PUT', path, this.context.inputData);
+});
diff --git a/openecomp-bdd/stepDefinitions/Questionnaire_steps.js b/openecomp-bdd/stepDefinitions/Questionnaire_steps.js
new file mode 100644
index 0000000000..ce35a1c9ce
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/Questionnaire_steps.js
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+const _ = require('lodash');
+
+/**
+ * @module Questionnaire
+ * @description Gets the questionnaire for the current item and saves it on the context
+ * @exampleFile Example_VSP.feature
+ * @step I want to get the questionnaire for this item
+ **/
+Then('I want to get the questionnaire for this item', function () {
+ let path = "/vendor-software-products/" + this.context.item.id + "/versions/" + this.context.item.versionId + "/questionnaire";
+ return util.request(this.context, 'GET', path).then(result => {
+ this.context.qdata = JSON.parse(result.data.data);
+ this.context.qschema = result.data.schema;
+ this.context.qurl = path;
+ });
+});
+
+/**
+ * @module Questionnaire
+ * @description Gets the questionnaire for the current item and component and saves it on the context
+ * @exampleFile Example_VSP.feature
+ * @step I want to get the questionnaire for this component
+ **/
+Then('I want to get the questionnaire for this component', function () {
+ let path = "/vendor-software-products/" + this.context.item.id + "/versions/" + this.context.item.versionId + "/components/" + this.context.componentId + "/questionnaire";
+ return util.request(this.context, 'GET', path).then(result => {
+ this.context.qdata = JSON.parse(result.data.data);
+ this.context.qschema = result.data.schema;
+ this.context.qurl = path;
+ });
+});
+
+
+/**
+ * @module Questionnaire
+ * @description Updates the property for the saved questionnaire
+ * @exampleFile Example_VSP.feature
+ * @step I want to update this questionnaire with value {string} for path {string}
+ **/
+Then('I want to update this questionnaire with value {string} for property {string}', function (string, string2) {
+ _.set(this.context.qdata, string, string2);
+});
+
+/**
+ * @module Questionnaire
+ * @description Checks the questionnaire data on the context for the given value and property
+ * @exampleFile Example_VSP.feature
+ * @step I want to check this questionnaire has value {string} for property {string}
+ **/
+Then('I want to check this questionnaire has value {string} for property {string}', function (string, string2) {
+ assert.equal(_.get(this.context.qdata, string), string2);
+});
+
+/**
+ * @module Questionnaire
+ * @description Updates the the questionnaire data from the context to the same url that loaded it
+ * @exampleFile Example_VSP.feature
+ * @step I want to update this questionnaire
+ **/
+Then('I want to update this questionnaire', function () {
+ return util.request(this.context, 'PUT', this.context.qurl, this.context.qdata);
+}); \ No newline at end of file
diff --git a/openecomp-bdd/stepDefinitions/REST_Steps.js b/openecomp-bdd/stepDefinitions/REST_Steps.js
new file mode 100644
index 0000000000..314f86825b
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/REST_Steps.js
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {When} = require('cucumber');
+const _ = require('lodash');
+const util = require('./Utils.js');
+_.templateSettings.interpolate = /{([\s\S]+?)}/g;
+
+function getPath(path, context) {
+ let compiled = _.template(path);
+ return compiled(context);
+}
+/**
+ * @module Rest_Calls
+ * @description makes a GET request to the given path (path is appended after the "onboarding-api/v1.0" prefix)<br>
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to get path {string}
+ **/
+When('I want to get path {string}', function(string) {
+ let path = getPath(string, this.context);
+ return util.request(this.context, 'GET', path);
+});
+
+/**
+ * @module Rest_Calls
+ * @description makes a DELETE request to the given path and appends the saved property (path is appended after the "onboarding-api/v1.0" prefix)<br>
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to delete for path {string} with the value from saved property {string}
+ **/
+When('I want to delete for path {string} with the value from saved property {string}', function(string, string2) {
+ let path = getPath(string, this.context);
+ path += '/' + this.context[string2];
+ return util.request(this.context, 'DELETE', path);
+});
+
+
+/**
+ * @module Rest_Calls
+ * @description makes a PUT request to the given path and sends the input data from the context (path is appended after the "onboarding-api/v1.0" prefix)<br>
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to update for path {string} with the input data from the context
+ **/
+When('I want to update for path {string} with the input data from the context', function(string) {
+ let path = getPath(string, this.context);
+ return util.request(this.context, 'PUT', path, this.context.inputData);
+});
+
+/**
+ * @module Rest_Calls
+ * @description makes a POST request to the given path and sends the input data from the context (path is appended after the "onboarding-api/v1.0" prefix)<br>
+ * @exampleFile Example_Rest_Calls.feature
+ * @step I want to create for path {string} with the input data from the context
+ **/
+When('I want to create for path {string} with the input data from the context', function(string) {
+ let path = getPath(string, this.context);
+ return util.request(this.context, 'POST', path, this.context.inputData);
+});
diff --git a/openecomp-bdd/stepDefinitions/Utils.js b/openecomp-bdd/stepDefinitions/Utils.js
new file mode 100644
index 0000000000..e818e72b1b
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/Utils.js
@@ -0,0 +1,128 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const request = require('request');
+const fs = require('fs');
+require('node-zip');
+
+function _request(context, method, path, data, isBinary=false, isVFCall=false) {
+ let server = (isVFCall) ? context.vf_server : context.onboarding_server;
+ let options = {
+ method: method,
+ url: server + path,
+ headers: context.headers
+ };
+ return new Promise(function (resolve, reject) {
+ if (method === 'POST' || method === 'PUT') {
+ if (isBinary) {
+ var formData = {
+ upload: fs.createReadStream(data),
+ };
+ options.formData = formData;
+ } else {
+ options.json = data;
+ }
+ }
+ request(options, function (err, result, data) {
+ context.inputData = null;
+ if (err) {
+ console.error('Request URL: ' + result.request.uri.href);
+ console.error('Request Method: ' + result.request.method);
+ console.error('Response Status Code: ' +result.statusCode);
+ console.log(err);
+ reject(err);
+ } else {
+ let isExpected = (context.shouldFail) ? (result.statusCode != 200 && result.statusCode != 201) : (result.statusCode == 200 || result.statusCode == 201);
+ if (!isExpected) {
+ console.error('Request URL: ' + result.request.uri.href);
+ console.error('Request Method: ' + result.request.method);
+ console.error('Response Status Code: ' +result.statusCode);
+ console.error(result.body);
+ reject('Status Code was ' + result.statusCode);
+ }
+ if (context.shouldFail && context.errorCode) {
+ let errorCode = data.errorCode;
+ let contextErrorCode = context.errorCode;
+ context.errorCode = null;
+ if (errorCode !== contextErrorCode) {
+ reject('Error Code was ' + errorCode + ' instead of ' + contextErrorCode);
+ }
+ }
+ if (context.shouldFail) {
+ context.shouldFail = false;
+ resolve({statusCode: result.statusCode, data: {}});
+ return;
+ }
+ if (method === 'GET' && isBinary) {
+ // downloading (NetworkPackage) files
+ return ({
+ blob: blobUtil.createBlob([data], {type: 'text/plain'}),
+ headers: result.headers
+ });
+ } else {
+ if (typeof data === 'string' && data) {
+ data = JSON.parse(data);
+ }
+ context.responseData = data;
+ context.inputData = data;
+ resolve({statusCode: result.statusCode, data: data});
+ }
+ }
+ });
+ });
+}
+
+function download(context, path, filePath, callback){
+ let options = {
+ method: 'GET',
+ url: context.onboarding_server + path,
+ headers: context.headers
+ };
+ var file = fs.createWriteStream(filePath);
+ var r = request(options).pipe(file);
+ r.on('error', function (err) {
+ console.log(err);
+ callback(err);
+ });
+ r.on('finish', function () {
+ file.close();
+ let zipFile = fs.readFileSync(filePath, 'binary');
+ let zip = new JSZip(zipFile, {base64: false, checkCRC32: true});
+ if (zip.files['MANIFEST.json']) {
+ let manifestData = zip.files['MANIFEST.json']._data;
+ manifestData = manifestData.replace(/\\n/g, '');
+ context.responseData = JSON.parse(manifestData);
+ }
+ callback();
+ });
+
+};
+
+function _random() {
+ let d = new Date();
+ return d.getTime().toString().split('').reverse().join('');
+}
+
+function _getJSONFromFile(file) {
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
+}
+
+
+module.exports = {
+ request: _request,
+ random : _random,
+ getJSONFromFile: _getJSONFromFile,
+ download: download
+};
diff --git a/openecomp-bdd/stepDefinitions/VF_steps.js b/openecomp-bdd/stepDefinitions/VF_steps.js
new file mode 100644
index 0000000000..d00cf9ca6a
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/VF_steps.js
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+
+
+/**
+ * @module VF
+ * @description Creates a VF for this Item (does NOT work on localhost). will get the data for the item and then update the input
+ * data for the VF call.
+ * @exampleFile Example_VSP.feature
+ * @step I want to create a VF for this Item
+ **/
+Then('I want to create a VF for this Item', function () {
+ return util.request(this.context, 'GET', '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId).then(result => {
+ this.context.inputData = util.getJSONFromFile('resources/json/createVF.json');
+ // start replacing stuff
+ this.context.inputData.contactId = this.context.headers["USER_ID"];
+ this.context.inputData.categories[0].uniqueId = result.data.category;
+ this.context.inputData.categories[0].subcategories[0].uniqueId = result.data.subCategory;
+ this.context.inputData.description = result.data.description;
+ this.context.inputData.name = result.data.name;
+ this.context.inputData.tags[0] = result.data.name;
+ this.context.inputData.vendorName = result.data.vendorName;
+ this.context.inputData.csarUUID = this.context.item.id;
+ return util.request(this.context, 'POST', '/catalog/resources', this.context.inputData, false, true);
+ });
+});
+
diff --git a/openecomp-bdd/stepDefinitions/VLM_steps.js b/openecomp-bdd/stepDefinitions/VLM_steps.js
new file mode 100644
index 0000000000..6e0dd318cf
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/VLM_steps.js
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When, Given} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+
+/**
+ * @module VLM
+ * @description Creates a new VLM with a random name and saves the id and versionId on the context item object and the context vlm object<br>
+ * Input data will be taken from the 'resources/json/createVLM.json' file.
+ *@exampleFile Example_VLM.feature
+ * @step I want to create a VLM
+ **/
+When('I want to create a VLM', function() {
+ let inputData = util.getJSONFromFile('resources/json/createVLM.json');
+ inputData.vendorName = util.random();
+ let path = '/vendor-license-models';
+ return util.request(this.context, 'POST', path, inputData).then(result => {
+ this.context.item ={id : result.data.itemId, versionId: result.data.version.id};
+ this.context.vlm = {id : result.data.itemId, name : inputData.vendorName};
+ });
+});
+
+/**
+ * @module VLM
+ * @exampleFile Example_VLM.feature
+ * @step I want to submit this VLM
+ **/
+Then('I want to submit this VLM', function() {
+ let inputData = {action: 'Submit'};
+ let path = '/vendor-license-models/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
diff --git a/openecomp-bdd/stepDefinitions/VSP_steps.js b/openecomp-bdd/stepDefinitions/VSP_steps.js
new file mode 100644
index 0000000000..b957e6f723
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/VSP_steps.js
@@ -0,0 +1,110 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const {Then, When} = require('cucumber');
+const assert = require('assert');
+const util = require('./Utils.js');
+const _ = require('lodash');
+
+
+/**
+ * @module VSP
+ * @description Creates a new VSP with a random name and saves the id and versionId on the context item object and the context vsp object<br>
+ * Input data will be taken from the 'resources/json/createVSP.json' file.
+ * Vendor id and name are taken from the vlm on the context (requires a VLM to be created first).
+ * @exampleFile Example_VSP.feature
+ * @step I want to create a VSP with onboarding type {string}
+ **/
+When('I want to create a VSP with onboarding type {string}', function(string) {
+ let inputData = util.getJSONFromFile('resources/json/createVSP.json');
+ inputData.onboardingMethod = string;
+ inputData.vendorName = this.context.vlm.name;
+ inputData.vendorId = this.context.vlm.id;
+ inputData.name = util.random();
+ let path = '/vendor-software-products';
+ return util.request(this.context, 'POST', path, inputData).then(result => {
+ this.context.item = {id : result.data.itemId, versionId: result.data.version.id};
+ this.context.vsp = {id : result.data.itemId, versionId: result.data.version.id};
+ });
+});
+
+/**
+ * @module VSP
+ * @description Creates a new VSP with the 'NetowrkPackage' onboarding type and with a random name and saves the id and versionId on the context item object and the context vsp object<br>
+ * Input data will be taken from the 'resources/json/createVSP.json' file.
+ * Vendor id and name are taken from the vlm on the context (requires a VLM to be created first).
+ * @exampleFile Example_VSP.feature
+ * @step I want to create a VSP with onboarding type {string}
+ **/
+When('I want to create a VSP', function() {
+ let inputData = util.getJSONFromFile('resources/json/createVSP.json');
+ inputData.vendorName = this.context.vlm.name;
+ inputData.vendorId = this.context.vlm.id;
+ inputData.name = util.random();
+ let path = '/vendor-software-products';
+ return util.request(this.context, 'POST', path, inputData).then(result => {
+ this.context.item = {id : result.data.itemId, versionId: result.data.version.id};
+ this.context.vsp = {id : result.data.itemId, versionId: result.data.version.id};
+ });
+});
+
+
+/**
+ * @module VSP
+ * @exampleFile Example_VSP.feature
+ * @step I want to submit this VSP
+ **/
+Then('I want to submit this VSP', function () {
+ let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
+ let inputData = {action: 'Submit'};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
+/**
+ * @module VSP
+ * @exampleFile Example_VSP.feature
+ * @step I want to package this VSP
+ **/
+Then('I want to package this VSP', function () {
+ let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
+ let inputData = {action: 'Create_Package'};
+ return util.request(this.context, 'PUT', path, inputData);
+});
+
+/**
+ * @module VSP
+ * @description Adds a component to the current item
+ * @exampleFile Example_VSP.feature
+ * @step I want to add a component
+ **/
+Then('I want to add a component', function () {
+ let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/components';
+ let inputData = {name: 'Cucumber Name', displayName: 'Cucumber', description: 'Cucumber Description'};
+ return util.request(this.context, 'POST', path, inputData).then(result => {
+ this.context.componentId = result.data.vfcId;
+ });
+});
+
+
+/**
+ * @module VSP
+ * @description Downloads the packaged file for this component to the given path
+ * @exampleFile Example_VSP.feature
+ * @step I want to get the package for this Item to path {string}
+ **/
+When('I want to get the package for this Item to path {string}', function (string, callback) {
+ let path = '/vendor-software-products/packages/' + this.context.item.id;
+ return [util.download(this.context, path, string, callback)];
+}); \ No newline at end of file
diff --git a/openecomp-bdd/stepDefinitions/world.js b/openecomp-bdd/stepDefinitions/world.js
new file mode 100644
index 0000000000..e87a9b588f
--- /dev/null
+++ b/openecomp-bdd/stepDefinitions/world.js
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+const { setWorldConstructor } = require('cucumber');
+const config = require('../config.json');
+var {setDefaultTimeout} = require('cucumber');
+
+/**
+ * @module Context
+ * @description Context that is used per feature file and can be accessed as 'this.context' in all steps.<Br>
+ *<Br>
+ * Contains the following items:<br>
+ * <li>this.context.server <ul>REST server and onboarding prefix including version. set either in configuration file or from the command line or SERVER environment variable</ul>
+ * <li>this.context.vlm <ul>When a VLM has been created, this has the an id and versionId set to the correct IDs.</ul>
+ * <li>this.context.vsp <ul>When a VSP has been created, this has the an id and versionId and componentId set to the correct IDs.</ul>
+ * <li>this.context.item <ul>When a VLM or VSP has been created, this has the an id and versionId set to the correct IDs.</ul>
+ * <li>this.context <ul>Object with properties that were saved in the steps.</ul>
+ * <li>this.context.inputdata <ul><b>Automatically updated with the last responseData from the Rest call</b><br>Object with properties that were prepares in the steps.</ul>
+ * <li>this.context.responseData <ul>Response from the last REST call.</ul>
+ **/
+class CustomWorld {
+ constructor(options) {
+ this.context = {}
+ if (options.parameters && options.parameters.server) {
+ this.context.server = options.parameters.server;
+ } else if (process.env.SERVER) {
+ this.context.server = process.env.SERVER;
+ } else {
+ this.context.server = config.server;
+ }
+ this.context.onboarding_server = (config.protocol + '://' + this.context.server + ':' + config.port + '/' + config.prefix);
+ this.context.vf_server = (config.protocol + '://' + this.context.server + ':' + config.port + '/' + config.vf_prefix);
+
+
+ this.context.headers = {};
+ this.context.headers['USER_ID'] = 'cs0008';
+
+ this.context.vlm = {id: null, versionId: null};
+ this.context.vsp = {id: null, versionId: null};
+ this.context.item = {id: null, versionId: null, componentId: null};
+
+ this.context.shouldFail = false;
+ this.context.errorCode = null;
+ this.context.inputData = null;
+ this.context.responseData = null;
+
+ this.setServer = function(server) {
+ this.context.onboarding_server = (config.protocol + '://' +server + ':' + config.port + '/' + config.prefix);
+ this.context.vf_server = (config.protocol + '://' +server + ':' + config.port + '/' + config.vf_prefix);
+ }
+
+ setDefaultTimeout(60 * 1000);
+ }
+}
+
+
+setWorldConstructor(CustomWorld)