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() { |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 22 | let inputData = util.getJSONFromFile('resources/json/operation/createVF.json'); |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 23 | |
| 24 | inputData.name = util.random(); |
| 25 | inputData.tags[0] = util.random(); |
| 26 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 27 | var type = "resources"; |
| 28 | let path = '/catalog/' + type; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 29 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 30 | this.context.component = {uniqueId : result.data.uniqueId, type : type, id : result.data.inputs[0].uniqueId}; |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | When('I want to create a Service', function() { |
| 35 | let inputData = util.getJSONFromFile('resources/json/operation/createService.json'); |
| 36 | |
| 37 | inputData.name = util.random(); |
| 38 | inputData.tags[0] = util.random(); |
| 39 | |
| 40 | var type = "services"; |
| 41 | let path = '/catalog/' + type; |
| 42 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
| 43 | this.context.component = {uniqueId : result.data.uniqueId, type : type, id : result.data.inputs[0].uniqueId}; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 44 | }); |
| 45 | }); |
| 46 | |
| 47 | function makeType() { |
| 48 | var text = ""; |
| 49 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 50 | |
| 51 | for (var i = 0; i < 5; i++) |
| 52 | text += possible.charAt(Math.floor(Math.random() * possible.length)); |
| 53 | |
| 54 | return text; |
| 55 | } |
| 56 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 57 | When('I want to create an Operation with input output', function() { |
| 58 | let path = '/catalog/' + this.context.component.type + '/' + this.context.component.uniqueId + '/interfaceOperations'; |
| 59 | let inputData = util.getJSONFromFile('resources/json/operation/createOperationWithInputOutput.json'); |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 60 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 61 | inputData.interfaceOperations.operation.inputParams.listToscaDataDefinition[0].name = util.random(); |
| 62 | inputData.interfaceOperations.operation.inputParams.listToscaDataDefinition[0].property = this.context.component.id; |
| 63 | inputData.interfaceOperations.operation.outputParams.listToscaDataDefinition[0].name = util.random(); |
| 64 | inputData.interfaceOperations.operation.operationType = makeType(); |
| 65 | inputData.interfaceOperations.operation.description = makeType(); |
mojahidi | 4720f5a | 2018-06-22 16:37:52 +0530 | [diff] [blame] | 66 | |
| 67 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
mojahidi | 4720f5a | 2018-06-22 16:37:52 +0530 | [diff] [blame] | 68 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 69 | }); |
| 70 | }); |
| 71 | |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 72 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 73 | When('I want to create an Operation', function() { |
| 74 | let path = '/catalog/' + this.context.component.type + '/' + this.context.component.uniqueId + '/interfaceOperations'; |
| 75 | let inputData = util.getJSONFromFile('resources/json/operation/createOperation.json'); |
| 76 | inputData.interfaceOperations.operation.operationType = makeType(); |
| 77 | inputData.interfaceOperations.operation.description = makeType(); |
mojahidi | a8480d1 | 2018-07-19 12:35:31 +0530 | [diff] [blame] | 78 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 79 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then(result => { |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 80 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 81 | }); |
| 82 | }); |
| 83 | |
| 84 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 85 | When('I want to list Operations', function () { |
| 86 | let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/filteredDataByParams?include=interfaces'; |
| 87 | return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | When('I want to get an Operation by Id', function () { |
| 92 | let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId; |
| 93 | return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> { |
| 94 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
| 95 | }); |
| 96 | }); |
| 97 | |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 98 | When('I want to update an Operation', function () { |
| 99 | let inputData = util.getJSONFromFile('resources/json/operation/updateOperation.json'); |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 100 | let path = '/catalog/'+ this.context.component.type + '/'+ this.context.component.uniqueId +'/interfaceOperations'; |
| 101 | inputData.interfaceOperations.operation.uniqueId = this.context.operation.uniqueId; |
| 102 | inputData.interfaceOperations.operation.operationType = this.context.operation.operationType; |
| 103 | inputData.interfaceOperations.operation.inputParams.listToscaDataDefinition[0].name = util.random(); |
| 104 | inputData.interfaceOperations.operation.inputParams.listToscaDataDefinition[0].property = this.context.component.id; |
| 105 | inputData.interfaceOperations.operation.outputParams.listToscaDataDefinition[0].name = util.random(); |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 106 | return util.request(this.context, 'PUT', path, inputData, false, 'vf').then((result)=> { |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 107 | this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType}; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 108 | }); |
| 109 | }); |
| 110 | |
| 111 | |
| 112 | When('I want to delete an Operation', function() { |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 113 | let path = '/catalog/'+ this.context.component.type + '/'+ this.context.component.uniqueId +'/interfaceOperations/' + this.context.operation.uniqueId; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 114 | return util.request(this.context, 'DELETE', path, null, false, 'vf'); |
| 115 | }); |
| 116 | |
| 117 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 118 | When('I want to checkin this component', function () { |
| 119 | let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/lifecycleState/CHECKIN' ; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 120 | let inputData = {userRemarks: 'checkin'}; |
| 121 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 122 | this.context.component = {uniqueId : result.data.uniqueId, type : this.context.component.type}; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 123 | }); |
| 124 | }); |
| 125 | |
| 126 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 127 | Then('I want to submit this component', function () { |
| 128 | let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/lifecycleState/certificationRequest' ; |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 129 | let inputData = {userRemarks: 'submit'}; |
| 130 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
mojahidi | 65204c6 | 2018-04-25 18:39:53 +0530 | [diff] [blame] | 131 | this.context.vf = {uniqueId : result.data.uniqueId}; |
| 132 | }); |
| 133 | }); |
| 134 | |
mojahidi | 5082ac8 | 2018-09-07 11:07:49 +0530 | [diff] [blame] | 135 | Then('I want to certify this component', function () { |
| 136 | let path = '/catalog/'+ this.context.component.type +'/' + this.context.component.uniqueId + '/lifecycleState/certify' ; |
| 137 | let inputData = {userRemarks: 'certify'}; |
| 138 | return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> { |
| 139 | this.context.component = {uniqueId : result.data.uniqueId}; |
| 140 | }); |
| 141 | }); |