blob: b957e6f7230b6fdabb0cbce108fc2cc0bcbc59ed [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)];
110});