Workflow Docker containers
[sdc/sdc-workflow-designer.git] / workflow / workflow-bdd / stepDefinitions / InterfaceOperationSteps.js
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
60
61 When('I want to list Operations', function () {
62     let path = '/catalog/resources/' + this.context.vf.uniqueId + '/filteredDataByParams?include=interfaces';
63     return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> {
64 });
65 });
66
67
68 When('I want to get an Operation by Id', function () {
69     let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId;
70     return util.request(this.context, 'GET', path, null, false, 'vf').then((result)=> {
71         this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType};
72         this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType};
73 });
74 });
75
76
77 When('I want to update an Operation', function () {
78     let inputData = util.getJSONFromFile('resources/json/operation/updateOperation.json');
79     let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/';
80     inputData.interfaceOperations.create.uniqueId = this.context.operation.uniqueId;
81     inputData.interfaceOperations.create.operationType = this.context.operation.operationType;
82     inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramName = util.random();
83     inputData.interfaceOperations.create.inputParams.listToscaDataDefinition[0].paramId = this.context.vf.id;
84     return util.request(this.context, 'PUT', path, inputData, false, 'vf').then((result)=> {
85         this.context.item ={uniqueId : result.data.uniqueId, operationType: result.data.operationType};
86         this.context.operation = {uniqueId : result.data.uniqueId, operationType : result.data.operationType};
87 });
88 });
89
90
91 When('I want to delete an Operation', function()  {
92     let path = '/catalog/resources/' + this.context.vf.uniqueId + '/interfaceOperations/' + this.context.operation.uniqueId;
93     return util.request(this.context, 'DELETE', path, null, false, 'vf');
94 });
95
96
97 When('I want to checkin this VF', function () {
98     let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/CHECKIN' ;
99     let inputData = {userRemarks: 'checkin'};
100     return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> {
101         this.context.item ={uniqueId : result.data.uniqueId};
102     this.context.vf = {uniqueId : result.data.uniqueId};
103 });
104 });
105
106
107 Then('I want to submit this VF', function () {
108     let path = '/catalog/resources/' + this.context.vf.uniqueId + '/lifecycleState/certificationRequest' ;
109     let inputData = {userRemarks: 'submit'};
110     return util.request(this.context, 'POST', path, inputData, false, 'vf').then((result)=> {
111         this.context.item ={uniqueId : result.data.uniqueId};
112     this.context.vf = {uniqueId : result.data.uniqueId};
113 });
114 });
115
116
117
118