3e2321963ce8c52a128c36d6a6feae9984a3ce0b
[sdc.git] / cucumber-js-test-apis-ci / 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/createVFWithoutCSAR.json');
23
24     var resourceName = util.random();
25     inputData.name =  resourceName;
26     inputData.tags[0] = resourceName;
27
28     var type = "resources";
29     let path = '/catalog/' + type;
30     return util.request(this.context, 'POST', path,  inputData, false, 'catalog').then(result => {
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()  {
36     let inputData = util.getJSONFromFile('resources/json/createService.json');
37
38     var serviceName = util.random();
39     inputData.name =  serviceName;
40     inputData.tags[0] = serviceName;
41
42     var type = "services";
43     let path = '/catalog/' + type;
44     return util.request(this.context, 'POST', path,  inputData, false, 'catalog').then(result => {
45         this.context.component = {uniqueId : result.data.uniqueId, type : type, id : result.data.inputs[0].uniqueId};
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
59 When('I want to create an Operation', function()  {
60     let path = '/catalog/' + this.context.component.type + '/' + this.context.component.uniqueId + '/interfaceOperations';
61     let inputData = util.getJSONFromFile('resources/json/interfaceOperation/createInterfaceOperations.json');
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";
70
71     return util.request(this.context, 'POST', path, inputData, false, 'catalog').then(result => {
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         };
77 });
78 });
79
80 When('I want to update an Operation', function () {
81     let inputData = util.getJSONFromFile('resources/json/interfaceOperation/updateInterfaceOperation.json');
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();
88
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     };
95 });
96 });
97
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
112 When('I want to list Operations', function () {
113     let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/filteredDataByParams?include=interfaces';
114     return util.request(this.context, 'GET', path, null, false, 'catalog').then((result)=> {
115     });
116 });
117
118
119 When('I want to delete an Operation', function()  {
120     let path = '/catalog/'+ this.context.component.type + '/'+ this.context.component.uniqueId +'/interfaces/' +
121         this.context.interface.interfaceUniqueId + '/operations/' +this.context.interface.operationUniqueId ;
122     return util.request(this.context, 'DELETE', path, null, false, 'catalog');
123 });
124
125
126 When('I want to checkin this component', function () {
127     let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/lifecycleState/CHECKIN' ;
128     let inputData = {userRemarks: 'checkin'};
129     return util.request(this.context, 'POST', path, inputData, false, 'catalog').then((result)=> {
130     this.context.component = {uniqueId : result.data.uniqueId, type : this.context.component.type};
131 });
132 });
133
134
135 Then('I want to submit this component', function () {
136     let path = '/catalog/'+ this.context.component.type + '/' + this.context.component.uniqueId + '/lifecycleState/certificationRequest' ;
137     let inputData = {userRemarks: 'submit'};
138     return util.request(this.context, 'POST', path, inputData, false, 'catalog').then((result)=> {
139     this.context.component = {uniqueId : result.data.uniqueId};
140 });
141 });
142
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'};
146     return util.request(this.context, 'POST', path, inputData, false, 'catalog').then((result)=> {
147     this.context.component = {uniqueId : result.data.uniqueId};
148 });
149 });