mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2017 European Support Limited |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | const {Then, When} = require('cucumber'); |
| 17 | const assert = require('assert'); |
| 18 | const util = require('./Utils.js'); |
| 19 | |
| 20 | |
| 21 | When('I want to create a VF', function() { |
| 22 | let inputData = util.getJSONFromFile('resources/json/operation/createVF_From_Catalog.json'); |
| 23 | |
| 24 | inputData.name = util.random(); |
| 25 | inputData.tags[0] = util.random(); |
| 26 | |
| 27 | let path = '/catalog/resources'; |
| 28 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
| 29 | this.context.item = {uniqueId : result.data.uniqueId, id : result.data.inputs[0].uniqueId, name : result.data.inputs[0].name}; |
| 30 | this.context.vf = {uniqueId : result.data.uniqueId, id : result.data.inputs[0].uniqueId, name : result.data.inputs[0].name}; |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | function makeType() { |
| 35 | var text = ""; |
| 36 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 37 | |
| 38 | for (var i = 0; i < 5; i++) |
| 39 | text += possible.charAt(Math.floor(Math.random() * possible.length)); |
| 40 | |
| 41 | return text; |
| 42 | } |
| 43 | |
| 44 | When('I want to create an Operation', function() { |
| 45 | let inputData = util.getJSONFromFile('resources/json/operation/createOperation.json'); |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 46 | let path = '/catalog/resources/' + this.context.vf.uniqueId +'/interfaceOperations'; |
| 47 | |
| 48 | inputData.interfaceOperations.create.operationType = makeType(); |
mojahidi | a8480d1 | 2018-07-19 12:35:31 +0530 | [diff] [blame^] | 49 | inputData.interfaceOperations.create.description = makeType(); |
mojahidi | 4720f5a | 2018-06-22 16:37:52 +0530 | [diff] [blame] | 50 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 51 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
| 52 | inputData.interfaceOperations.create.outputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 53 | inputData.interfaceOperations.create.outputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
mojahidi | a8480d1 | 2018-07-19 12:35:31 +0530 | [diff] [blame^] | 54 | inputData.interfaceOperations.create.workflowId = makeType(); |
| 55 | inputData.interfaceOperations.create.workflowVersionId = makeType(); |
mojahidi | 4720f5a | 2018-06-22 16:37:52 +0530 | [diff] [blame] | 56 | |
| 57 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
| 58 | this.context.item = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 59 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 60 | }); |
| 61 | }); |
| 62 | |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 63 | |
mojahidi | a8480d1 | 2018-07-19 12:35:31 +0530 | [diff] [blame^] | 64 | |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 65 | When('I want to list Operations', function () { |
| 66 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/filteredDataByParams?include=interfaces'; |
| 67 | return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | |
| 72 | When('I want to get an Operation by Id', function () { |
| 73 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; |
| 74 | return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { |
| 75 | this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType}; |
| 76 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 77 | }); |
| 78 | }); |
| 79 | |
| 80 | |
| 81 | When('I want to update an Operation', function () { |
| 82 | let inputData = util.getJSONFromFile('resources/json/operation/updateOperation.json'); |
| 83 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/'; |
| 84 | inputData.interfaceOperations.create.uniqueId = this.context.operation.uniqueId; |
| 85 | inputData.interfaceOperations.create.operationType = this.context.operation.operationType; |
| 86 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 87 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
| 88 | return util.request(this.context, 'PUT', path, inputData, false, 'vf').then((result)=> { |
| 89 | this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType}; |
| 90 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 91 | }); |
| 92 | }); |
| 93 | |
| 94 | |
| 95 | When('I want to delete an Operation', function() { |
| 96 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; |
| 97 | return util.request(this.context, 'DELETE', path, null, false, 'vf'); |
| 98 | }); |
| 99 | |
| 100 | |
| 101 | When('I want to checkin this VF', function () { |
| 102 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/CHECKIN' ; |
| 103 | let inputData = {userRemarks: 'checkin'}; |
| 104 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
| 105 | this.context.item ={uniqueId : result.data.uniqueId}; |
| 106 | this.context.vf = {uniqueId : result.data.uniqueId}; |
| 107 | }); |
| 108 | }); |
| 109 | |
| 110 | |
| 111 | Then('I want to submit this VF', function () { |
| 112 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/certificationRequest' ; |
| 113 | let inputData = {userRemarks: 'submit'}; |
| 114 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
| 115 | this.context.item ={uniqueId : result.data.uniqueId}; |
| 116 | this.context.vf = {uniqueId : result.data.uniqueId}; |
| 117 | }); |
| 118 | }); |
| 119 | |
| 120 | |
| 121 | |
| 122 | |