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