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'); |
| 46 | //let path = '/catalog/resources/f3dc81bb-85e9-4dfd-bd1b-37f5dc5e5534/interfaceOperations'; |
| 47 | let path = '/catalog/resources/' + this.context.vf.uniqueId +'/interfaceOperations'; |
| 48 | |
| 49 | inputData.interfaceOperations.create.operationType = makeType(); |
| 50 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 51 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
| 52 | |
| 53 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
| 54 | this.context.item = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 55 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | |
mojahidi | 4720f5a | 2018-06-22 16:37:52 +0530 | [diff] [blame] | 60 | When('I want to create an Operation with outputParameter', function() { |
| 61 | let inputData = util.getJSONFromFile('resources/json/operation/createOperation.json'); |
| 62 | //let path = '/catalog/resources/f3dc81bb-85e9-4dfd-bd1b-37f5dc5e5534/interfaceOperations'; |
| 63 | let path = '/catalog/resources/' + this.context.vf.uniqueId +'/interfaceOperations'; |
| 64 | |
| 65 | inputData.interfaceOperations.create.operationType = makeType(); |
| 66 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 67 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
| 68 | inputData.interfaceOperations.create.outputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 69 | inputData.interfaceOperations.create.outputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
| 70 | |
| 71 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
| 72 | this.context.item = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 73 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 74 | }); |
| 75 | }); |
| 76 | |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 77 | |
| 78 | When('I want to list Operations', function () { |
| 79 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/filteredDataByParams?include=interfaces'; |
| 80 | return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { |
| 81 | }); |
| 82 | }); |
| 83 | |
| 84 | |
| 85 | When('I want to get an Operation by Id', function () { |
| 86 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; |
| 87 | return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { |
| 88 | this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType}; |
| 89 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 90 | }); |
| 91 | }); |
| 92 | |
| 93 | |
| 94 | When('I want to update an Operation', function () { |
| 95 | let inputData = util.getJSONFromFile('resources/json/operation/updateOperation.json'); |
| 96 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/'; |
| 97 | inputData.interfaceOperations.create.uniqueId = this.context.operation.uniqueId; |
| 98 | inputData.interfaceOperations.create.operationType = this.context.operation.operationType; |
| 99 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random(); |
| 100 | inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id; |
| 101 | return util.request(this.context, 'PUT', path, inputData, false, 'vf').then((result)=> { |
| 102 | this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType}; |
| 103 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 104 | }); |
| 105 | }); |
| 106 | |
| 107 | |
| 108 | When('I want to delete an Operation', function() { |
| 109 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; |
| 110 | return util.request(this.context, 'DELETE', path, null, false, 'vf'); |
| 111 | }); |
| 112 | |
| 113 | |
| 114 | When('I want to checkin this VF', function () { |
| 115 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/CHECKIN' ; |
| 116 | let inputData = {userRemarks: 'checkin'}; |
| 117 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
| 118 | this.context.item ={uniqueId : result.data.uniqueId}; |
| 119 | this.context.vf = {uniqueId : result.data.uniqueId}; |
| 120 | }); |
| 121 | }); |
| 122 | |
| 123 | |
| 124 | Then('I want to submit this VF', function () { |
| 125 | let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/certificationRequest' ; |
| 126 | let inputData = {userRemarks: 'submit'}; |
| 127 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
| 128 | this.context.item ={uniqueId : result.data.uniqueId}; |
| 129 | this.context.vf = {uniqueId : result.data.uniqueId}; |
| 130 | }); |
| 131 | }); |
| 132 | |
| 133 | |
| 134 | |
| 135 | |