From 3fb47c47b301bf8f401cabf63b13f17a39182d85 Mon Sep 17 00:00:00 2001 From: ayalaben Date: Sun, 24 Jun 2018 10:42:43 +0300 Subject: BDD cucumber Change-Id: I34f9950dab1c15f8c19da5f696783d793ee3511f Issue-ID: SDC-1442 Signed-off-by: ayalaben --- .../stepDefinitions/Collaboration_Steps.js | 113 ++++++++ workflow-bdd/stepDefinitions/General_Steps.js | 310 +++++++++++++++++++++ workflow-bdd/stepDefinitions/InputData_steps.js | 83 ++++++ .../stepDefinitions/InterfaceOperationSteps.js | 118 ++++++++ workflow-bdd/stepDefinitions/Item_steps.js | 91 ++++++ workflow-bdd/stepDefinitions/REST_Steps.js | 80 ++++++ workflow-bdd/stepDefinitions/Utils.js | 148 ++++++++++ workflow-bdd/stepDefinitions/VLM_steps.js | 79 ++++++ workflow-bdd/stepDefinitions/VSP_steps.js | 182 ++++++++++++ workflow-bdd/stepDefinitions/world.js | 92 ++++++ 10 files changed, 1296 insertions(+) create mode 100644 workflow-bdd/stepDefinitions/Collaboration_Steps.js create mode 100644 workflow-bdd/stepDefinitions/General_Steps.js create mode 100644 workflow-bdd/stepDefinitions/InputData_steps.js create mode 100644 workflow-bdd/stepDefinitions/InterfaceOperationSteps.js create mode 100644 workflow-bdd/stepDefinitions/Item_steps.js create mode 100644 workflow-bdd/stepDefinitions/REST_Steps.js create mode 100644 workflow-bdd/stepDefinitions/Utils.js create mode 100644 workflow-bdd/stepDefinitions/VLM_steps.js create mode 100644 workflow-bdd/stepDefinitions/VSP_steps.js create mode 100644 workflow-bdd/stepDefinitions/world.js (limited to 'workflow-bdd/stepDefinitions') diff --git a/workflow-bdd/stepDefinitions/Collaboration_Steps.js b/workflow-bdd/stepDefinitions/Collaboration_Steps.js new file mode 100644 index 00000000..c4de7583 --- /dev/null +++ b/workflow-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['onboarding'].USER_ID = string; +}); diff --git a/workflow-bdd/stepDefinitions/General_Steps.js b/workflow-bdd/stepDefinitions/General_Steps.js new file mode 100644 index 00000000..448c97f8 --- /dev/null +++ b/workflow-bdd/stepDefinitions/General_Steps.js @@ -0,0 +1,310 @@ +/* + * 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'); + +function getPath(path, context) { + let compiled = _.template(path); + return compiled(context); +} + +/** + * @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::
+ * """
+ * {jsonObject}
+ * """
+ * @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 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 value. property can be a path + * (example: results[0].id). Supports comparison to a long String by allowing a line break + * @exampleFile VirtualMachineInterfaceValidationHeatResourceMissingProperties.feature + * @step I want to check property {string} for value {string} + **/ + +Then('I want to check property {string} for value:', function(string, docString) { + assert.equal(_.get(this.context.responseData, string), docString.trim()); +}); +/** + * @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 {word}', function(string, string2) { + assert.equal(_.get(this.context.responseData, string), string2.toLowerCase() == "true"); +}); +/** + * @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 ContextData + * @description Set this in order to check that the following Rest call will have the error message on the return data + * @exampleFile DeleteVLMCertified.feature + * @step I want the following to fail with error message {string} + **/ +Then('I want the following to fail with error message {string}', function(string) { + this.context.shouldFail = true; + let errorMessage = getPath(string, this.context); + this.context.errorMessage = errorMessage; +}); + +/** + * @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(); +}); + +/** + * @module ResponseData + * @description Check that the result list doesn't contain an element with property x which has value + * equals to saved property y + * @exampleFile ListItemsFilters.feature + * @step I want to check that element in the response list with {string} equals to value of saved property {string} does not exist + **/ +Then('I want to check that element in the response list with {string} equals to value of saved property {string} does not exist', function (propertyPath, valueProperty) { + const results = this.context.responseData.results; + assert.equal(results.find(result => this.context[valueProperty] === _.get(result, propertyPath)), undefined); +}); + +/** + * @module ResponseData + * @description Check that the result list contains an element with property x which has value + * equals to saved property y + * @exampleFile ListItemsFilters.feature + * @step I want to check that element in the response list with {string} equals to value of saved property {string} exists + **/ +Then('I want to check that element in the response list with {string} equals to value of saved property {string} exists', function(propertyPath, valueProperty) { + const results = this.context.responseData.results; + assert.notEqual(results.find(result => this.context[valueProperty] === _.get(result, propertyPath)), undefined); +}); + + +Then('I want to check that property {string} in the response equals to value of saved property {string}', function(propertyPath, valueProperty) { + const results = this.context.responseData; + assert.equal(results[propertyPath],this.context[valueProperty]); +}); + +/** + * @module ResponseData + * @description Check that the itemId from context exits in result of responseData + * exampleFile ArchiveItem.feature + * step I want to check that item exits in response + **/ +Then('I want to check that item exits in response', function() { + + const id = this.context.item.id; + const results = this.context.responseData.results; + var testResult = false; + + for(var i=0; i< results.length; i++){ + if ( id == results[i].id){ + testResult = true; + } + } + + assert.equal(testResult,true); +}); + + +/** + * @module ResponseData + * @description Check that the itemId from context does NOT exits in result of responseData + * exampleFile ArchiveItem.feature + * step I want to check that item does not exits in response + **/ +Then('I want to check that item does not exits in response', function() { + + const id = this.context.item.id; + const results = this.context.responseData.results; + var testResult = false; + + for(var i=0; i< results.length; i++){ + if ( id == results[i].id){ + testResult = true; + } + } + + assert.equal(testResult,false); +}); \ No newline at end of file diff --git a/workflow-bdd/stepDefinitions/InputData_steps.js b/workflow-bdd/stepDefinitions/InputData_steps.js new file mode 100644 index 00000000..73695d0e --- /dev/null +++ b/workflow-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:
+ * """
+ * {jsonObject}
+ * """
+ * @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/workflow-bdd/stepDefinitions/InterfaceOperationSteps.js b/workflow-bdd/stepDefinitions/InterfaceOperationSteps.js new file mode 100644 index 00000000..4c00debc --- /dev/null +++ b/workflow-bdd/stepDefinitions/InterfaceOperationSteps.js @@ -0,0 +1,118 @@ +/* + * 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'); + + +When('I want to create a VF', function() { + let inputData = util.getJSONFromFile('resources/json/operation/createVF_From_Catalog.json'); + + inputData.name = util.random(); + inputData.tags[0] = util.random(); + + let path = '/catalog/resources'; + return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { + this.context.item = {uniqueId : result.data.uniqueId, id : result.data.inputs[0].uniqueId, name : result.data.inputs[0].name}; + this.context.vf = {uniqueId : result.data.uniqueId, id : result.data.inputs[0].uniqueId, name : result.data.inputs[0].name}; +}); +}); + +function makeType() { + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + + for (var i = 0; i < 5; i++) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} + +When('I want to create an Operation', function() { + let inputData = util.getJSONFromFile('resources/json/operation/createOperation.json'); + //let path = '/catalog/resources/f3dc81bb-85e9-4dfd-bd1b-37f5dc5e5534/interfaceOperations'; + let path = '/catalog/resources/' + this.context.vf.uniqueId +'/interfaceOperations'; + + inputData.interfaceOperations.create.operationType = makeType(); + inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); + inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; + + return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { + this.context.item = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; + this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; +}); +}); + + + +When('I want to list Operations', function () { + let path = '/catalog/resources/' + this.context.vf.uniqueId + '/filteredDataByParams?include=interfaces'; + return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { +}); +}); + + +When('I want to get an Operation by Id', function () { + let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; + return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { + this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType}; + this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; +}); +}); + + +When('I want to update an Operation', function () { + let inputData = util.getJSONFromFile('resources/json/operation/updateOperation.json'); + let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/'; + inputData.interfaceOperations.create.uniqueId = this.context.operation.uniqueId; + inputData.interfaceOperations.create.operationType = this.context.operation.operationType; + inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); + inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; + return util.request(this.context, 'PUT', path, inputData, false, 'vf').then((result)=> { + this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType}; + this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; +}); +}); + + +When('I want to delete an Operation', function() { + let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; + return util.request(this.context, 'DELETE', path, null, false, 'vf'); +}); + + +When('I want to checkin this VF', function () { + let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/CHECKIN' ; + let inputData = {userRemarks: 'checkin'}; + return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { + this.context.item ={uniqueId : result.data.uniqueId}; + this.context.vf = {uniqueId : result.data.uniqueId}; +}); +}); + + +Then('I want to submit this VF', function () { + let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/certificationRequest' ; + let inputData = {userRemarks: 'submit'}; + return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { + this.context.item ={uniqueId : result.data.uniqueId}; + this.context.vf = {uniqueId : result.data.uniqueId}; +}); +}); + + + + diff --git a/workflow-bdd/stepDefinitions/Item_steps.js b/workflow-bdd/stepDefinitions/Item_steps.js new file mode 100644 index 00000000..3ff7f20f --- /dev/null +++ b/workflow-bdd/stepDefinitions/Item_steps.js @@ -0,0 +1,91 @@ +/* + * 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); +}); + + +/** + * @module Item + * @exampleFile ArchiveItem.feature + * @step I want to archive this item + **/ +Then('I want to archive this item', function() { + let path = '/items/' + this.context.item.id + '/actions' + let inputData = {action: 'ARCHIVE'}; + return util.request(this.context, 'PUT', path, inputData); +}); + + +/** + * @module Item + * @exampleFile ArchiveItem.feature + * @step I want to restore this item + **/ +Then('I want to restore this item', function() { + let path = '/items/' + this.context.item.id + '/actions' + let inputData = {action: 'RESTORE'}; + return util.request(this.context, 'PUT', path, inputData); +}); + diff --git a/workflow-bdd/stepDefinitions/REST_Steps.js b/workflow-bdd/stepDefinitions/REST_Steps.js new file mode 100644 index 00000000..c3844124 --- /dev/null +++ b/workflow-bdd/stepDefinitions/REST_Steps.js @@ -0,0 +1,80 @@ +/* + * Copyright © 2016-2018 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)
+ * @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)
+ * @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 DELETE request to the given path and appends the saved property (path is appended after the "onboarding-api/v1.0" prefix)
+ * @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}', function (string) { + 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)
+ * @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)
+ * @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/workflow-bdd/stepDefinitions/Utils.js b/workflow-bdd/stepDefinitions/Utils.js new file mode 100644 index 00000000..66e959f6 --- /dev/null +++ b/workflow-bdd/stepDefinitions/Utils.js @@ -0,0 +1,148 @@ +/* + * 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, type='onboarding') { + let server = context.getUrlForType(type); + + let options = { + method: method, + url: server + path, + headers: context.headers[type] + }; + console.log('--> Calling REST ' + options.method +' url: ' + options.url); + + 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) { + if (typeof data === 'string' && data) { + data = JSON.parse(data); + } + 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.errorMessage) { + if (typeof data === 'string' && data) { + data = JSON.parse(data); + } + let errorMessage = data.message; + let contextErrorMessage = context.errorMessage; + context.errorMessage = null; + if (errorMessage !== contextErrorMessage) { + reject('Error Message was ' + errorMessage + ' instead of ' + contextErrorMessage); + } + } + 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, type='onboarding') { + let server = context.getUrlForType(type); + let options = { + method: 'GET', + url: server + path, + headers: context.headers[type] + }; + console.log('--> Calling REST download url: ' + options.url); + + 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/workflow-bdd/stepDefinitions/VLM_steps.js b/workflow-bdd/stepDefinitions/VLM_steps.js new file mode 100644 index 00000000..35e78b2d --- /dev/null +++ b/workflow-bdd/stepDefinitions/VLM_steps.js @@ -0,0 +1,79 @@ +/* + * 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
+ * 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); +}); + +/** + * @module VLM + * @exampleFile DeleteVLMDraft.feature + * @step I want to delete this VLM + **/ +Then('I want to delete this VLM', function() { + let path = '/vendor-license-models/' + this.context.item.id ; + return util.request(this.context, 'DELETE', path); +}); + + +/** + * @module VLM + * @exampleFile ArchiveItem.feature + * @step I want to list Archived VLMs + **/ +Then('I want to list Archived VLMs', function() { + let path = '/vendor-license-models/?Status=ARCHIVED'; + return util.request(this.context, 'GET', path); +}); + +/** + * @module VLM + * @exampleFile ArchiveItem.feature + * @step I want to list Active VLMs + **/ +Then('I want to list Active VLMs', function() { + let path = '/vendor-license-models'; + return util.request(this.context, 'GET', path); +}); + + diff --git a/workflow-bdd/stepDefinitions/VSP_steps.js b/workflow-bdd/stepDefinitions/VSP_steps.js new file mode 100644 index 00000000..1f753fef --- /dev/null +++ b/workflow-bdd/stepDefinitions/VSP_steps.js @@ -0,0 +1,182 @@ +/* + * 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
+ * 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
+ * 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)]; +}); + + +/** + * @module VSP + * @exampleFile DeleteVSPDraft.feature + * @step I want to delete this VSP + **/ +Then('I want to delete this VSP', function() { + let path = '/vendor-software-products/' + this.context.item.id ; + return util.request(this.context, 'DELETE', path); +}); + +/** + * @module VSP + * @exampleFile ArchiveItem.feature + * @step I want to list Archived VSPs + **/ +Then('I want to list Archived VSPs', function() { + let path = '/vendor-software-products/?Status=ARCHIVED'; + return util.request(this.context, 'GET', path); +}); + +/** + * @module VSP + * @exampleFile ArchiveItem.feature + * @step I want to list Active VSPs + **/ +Then('I want to list Active VSPs', function() { + let path = '/vendor-software-products'; + return util.request(this.context, 'GET', path); +}); + + +/** + * @module VSP + * @exampleFile FilterArchivedVSPpackage.feature + * @step I want to list Archived VSPs packages + **/ +Then('I want to list Archived VSPs packages', function() { + let path = '/vendor-software-products/packages?Status=ARCHIVED'; + return util.request(this.context, 'GET', path); +}); + +/** + * @module VSP + * @exampleFile FilterArchivedVSPpackage.feature + * @step I want to list Active VSPs packages + **/ +Then('I want to list Active VSPs packages', function() { + let path = '/vendor-software-products/packages'; + return util.request(this.context, 'GET', path); + +}); + +/** + * @module VSP + * @exampleFile FilterArchivedVSPpackage.feature + * @step I want to check that VSP package exits in response + **/ +Then('I want to check that VSP package exits in response', function() { + + const packages = this.context.responseData.results; + const id = this.context.item.id; + var testResult = false; + + for(var i=0; i< packages.length; i++){ + if (id == packages[i].packageId){ + testResult = true; + } + } + assert.equal(testResult,true); +}); \ No newline at end of file diff --git a/workflow-bdd/stepDefinitions/world.js b/workflow-bdd/stepDefinitions/world.js new file mode 100644 index 00000000..4ef03813 --- /dev/null +++ b/workflow-bdd/stepDefinitions/world.js @@ -0,0 +1,92 @@ +/* + * 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 _ = require('lodash'); + +let config = require('../config.json'); +let localConfig = {}; +try { + localConfig = require('../devConfig.json'); +} catch (e) { + try { + localConfig = require('../jenkinsConfig.json'); + } catch (e) { + console.error("no env configuration was found!"); + } +} + +config = _.merge(config, localConfig); +var {setDefaultTimeout} = require('cucumber'); + + +/** + * @module Context + * @description Context that is used per feature file and can be accessed as 'this.context' in all steps.
+ *
+ * Contains the following items:
+ *
  • this.context.server
      REST server and onboarding prefix including version. set either in configuration file or from the command line or SERVER environment variable
    + *
  • this.context.vlm
      When a VLM has been created, this has the an id and versionId set to the correct IDs.
    + *
  • this.context.vsp
      When a VSP has been created, this has the an id and versionId and componentId set to the correct IDs.
    + *
  • this.context.item
      When a VLM or VSP has been created, this has the an id and versionId set to the correct IDs.
    + *
  • this.context
      Object with properties that were saved in the steps.
    + *
  • this.context.inputdata
      Automatically updated with the last responseData from the Rest call
      Object with properties that were prepares in the steps.
    + *
  • this.context.responseData
      Response from the last REST call.
    + **/ +class CustomWorld { + constructor(options) { + this.context = {}; + this.context.headers = {}; + let typeName; + for (typeName in config) { + this.context.headers[typeName] = {}; + if (config[typeName].user) { + this.context.headers[typeName]['USER_ID'] = config[typeName].user; + } + } + + 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.context.defaultServerType = 'workflow'; + + this.config = config; + + let context = this.context; + this.context.getUrlForType = (function(type) { + var _server = context.server; + var _config = config; + return function(type) { + let typeData = _config["workflow"]; + let _url = _config.protocol + '://' + + typeData.server + ':' + + typeData.port + '/' + + typeData.prefix; + return _url; + } + })(); + + setDefaultTimeout(60 * 1000); + } +} + + +setWorldConstructor(CustomWorld); -- cgit 1.2.3-korg