blob: 1f753fef5eadacbf0c32c2cf5d16f9495f35f766 [file] [log] [blame]
ilanap637206b2018-02-04 17:06:22 +02001/*
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 */
16const {Then, When} = require('cucumber');
17const assert = require('assert');
18const util = require('./Utils.js');
19const _ = require('lodash');
20
21
22/**
23 * @module VSP
24 * @description Creates a new VSP with a random name and saves the id and versionId on the context item object and the context vsp object<br>
25 * Input data will be taken from the 'resources/json/createVSP.json' file.
26 * Vendor id and name are taken from the vlm on the context (requires a VLM to be created first).
27 * @exampleFile Example_VSP.feature
28 * @step I want to create a VSP with onboarding type {string}
29 **/
30When('I want to create a VSP with onboarding type {string}', function(string) {
31 let inputData = util.getJSONFromFile('resources/json/createVSP.json');
32 inputData.onboardingMethod = string;
33 inputData.vendorName = this.context.vlm.name;
34 inputData.vendorId = this.context.vlm.id;
35 inputData.name = util.random();
36 let path = '/vendor-software-products';
37 return util.request(this.context, 'POST', path, inputData).then(result => {
38 this.context.item = {id : result.data.itemId, versionId: result.data.version.id};
39 this.context.vsp = {id : result.data.itemId, versionId: result.data.version.id};
40 });
41});
42
43/**
44 * @module VSP
45 * @description Creates a new VSP with the 'NetowrkPackage' onboarding type and with a random name and saves the id and versionId on the context item object and the context vsp object<br>
46 * Input data will be taken from the 'resources/json/createVSP.json' file.
47 * Vendor id and name are taken from the vlm on the context (requires a VLM to be created first).
48 * @exampleFile Example_VSP.feature
49 * @step I want to create a VSP with onboarding type {string}
50 **/
51When('I want to create a VSP', function() {
52 let inputData = util.getJSONFromFile('resources/json/createVSP.json');
53 inputData.vendorName = this.context.vlm.name;
54 inputData.vendorId = this.context.vlm.id;
55 inputData.name = util.random();
56 let path = '/vendor-software-products';
57 return util.request(this.context, 'POST', path, inputData).then(result => {
58 this.context.item = {id : result.data.itemId, versionId: result.data.version.id};
59 this.context.vsp = {id : result.data.itemId, versionId: result.data.version.id};
60 });
61});
62
63
64/**
65 * @module VSP
66 * @exampleFile Example_VSP.feature
67 * @step I want to submit this VSP
68 **/
69Then('I want to submit this VSP', function () {
70 let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
71 let inputData = {action: 'Submit'};
72 return util.request(this.context, 'PUT', path, inputData);
73});
74
75/**
76 * @module VSP
77 * @exampleFile Example_VSP.feature
78 * @step I want to package this VSP
79 **/
80Then('I want to package this VSP', function () {
81 let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions';
82 let inputData = {action: 'Create_Package'};
83 return util.request(this.context, 'PUT', path, inputData);
84});
85
86/**
87 * @module VSP
88 * @description Adds a component to the current item
89 * @exampleFile Example_VSP.feature
90 * @step I want to add a component
91 **/
92Then('I want to add a component', function () {
93 let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/components';
94 let inputData = {name: 'Cucumber Name', displayName: 'Cucumber', description: 'Cucumber Description'};
95 return util.request(this.context, 'POST', path, inputData).then(result => {
96 this.context.componentId = result.data.vfcId;
97 });
98});
99
100
101/**
102 * @module VSP
103 * @description Downloads the packaged file for this component to the given path
104 * @exampleFile Example_VSP.feature
105 * @step I want to get the package for this Item to path {string}
106 **/
107When('I want to get the package for this Item to path {string}', function (string, callback) {
108 let path = '/vendor-software-products/packages/' + this.context.item.id;
109 return [util.download(this.context, path, string, callback)];
ayalabenaad27812018-02-18 10:03:22 +0200110});
111
112
113/**
114 * @module VSP
115 * @exampleFile DeleteVSPDraft.feature
116 * @step I want to delete this VSP
117 **/
118Then('I want to delete this VSP', function() {
119 let path = '/vendor-software-products/' + this.context.item.id ;
120 return util.request(this.context, 'DELETE', path);
ayalaben705fc2b2018-03-15 15:59:25 +0200121});
122
123/**
124 * @module VSP
125 * @exampleFile ArchiveItem.feature
126 * @step I want to list Archived VSPs
127 **/
128Then('I want to list Archived VSPs', function() {
129 let path = '/vendor-software-products/?Status=ARCHIVED';
130 return util.request(this.context, 'GET', path);
131});
132
133/**
134 * @module VSP
135 * @exampleFile ArchiveItem.feature
136 * @step I want to list Active VSPs
137 **/
138Then('I want to list Active VSPs', function() {
139 let path = '/vendor-software-products';
140 return util.request(this.context, 'GET', path);
141});
142
143
144/**
145 * @module VSP
146 * @exampleFile FilterArchivedVSPpackage.feature
147 * @step I want to list Archived VSPs packages
148 **/
149Then('I want to list Archived VSPs packages', function() {
150 let path = '/vendor-software-products/packages?Status=ARCHIVED';
151 return util.request(this.context, 'GET', path);
152});
153
154/**
155 * @module VSP
156 * @exampleFile FilterArchivedVSPpackage.feature
157 * @step I want to list Active VSPs packages
158 **/
159Then('I want to list Active VSPs packages', function() {
160 let path = '/vendor-software-products/packages';
161 return util.request(this.context, 'GET', path);
162
163});
164
165/**
166 * @module VSP
167 * @exampleFile FilterArchivedVSPpackage.feature
168 * @step I want to check that VSP package exits in response
169 **/
170Then('I want to check that VSP package exits in response', function() {
171
172 const packages = this.context.responseData.results;
173 const id = this.context.item.id;
174 var testResult = false;
175
176 for(var i=0; i< packages.length; i++){
177 if (id == packages[i].packageId){
178 testResult = true;
179 }
180 }
181 assert.equal(testResult,true);
ilanap637206b2018-02-04 17:06:22 +0200182});