2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 const { setWorldConstructor } = require('cucumber');
17 const _ = require('lodash');
18 const findUp = require('find-up');
22 let configPath = findUp.sync('config.json');
23 configPath = configPath.replace(/\\/g, '/');
25 let config = require(configPath);
28 let devConfigPath = findUp.sync('devConfig.json');
29 devConfigPath = devConfigPath.replace(/\\/g, '/');
30 localConfig = require(devConfigPath);
33 let envdir = findUp.sync('environments', {type: 'directory'});
34 envdir = envdir.replace(/\\/g, '/');
35 localConfig = require(envdir + '/dockerConfig.json');
37 console.error("no env configuration was found!");
41 config = _.merge(config, localConfig);
42 var {setDefaultTimeout} = require('cucumber');
47 * @description Context that is used per feature file and can be accessed as 'this.context' in all steps.<Br>
48 * This class can be extended in order to add additional configurations.
50 * Contains the following items:<br>
51 * <li>this.context.server <ul>REST server and onboarding prefix including version. set either in configuration file or from the command line or SERVER environment variable</ul>
52 * <li>this.context.item <ul>When a VLM or VSP has been created, this has the an id and versionId set to the correct IDs.</ul>
53 * <li>this.context <ul>Object with properties that were saved in the steps.</ul>
54 * <li>this.context.inputdata <ul><b>Automatically updated with the last responseData from the Rest call</b><br>Object with properties that were prepares in the steps.</ul>
55 * <li>this.context.responseData <ul>Response from the last REST call.</ul>
58 constructor(options) {
60 this.context.headers = {};
63 this.context.defaultServerType = 'main';
64 for (typeName in config) {
65 this.context.headers[typeName] = {};
66 if (config[typeName].user) {
67 this.context.headers[typeName]['USER_ID'] = config[typeName].user;
69 // adding additional headers
70 if (config[typeName].additionalHeaders) {
71 _.assign(this.context.headers[typeName] , config[typeName].additionalHeaders);
73 if (config[typeName].isDefault !== undefined && config[typeName].isDefault) {
74 this.context.defaultServerType = typeName;
77 this.context.item = {id: null, versionId: null, componentId: null};
78 // adding the default items that should also be initialized
79 if (config.initData) {
80 _.assign(this.context, config.initData);
83 this.context.shouldFail = false;
84 this.context.errorCode = null;
85 this.context.inputData = null;
86 this.context.responseData = null;
91 let context = this.context;
92 this.context.getUrlForType = (function(type) {
93 var _server = context.server;
95 return function(type) {
96 let typeData = _config[type];
97 let _url = typeData.protocol + '://' +
98 typeData.server + ':' +
104 setDefaultTimeout(60 * 1000);
107 setWorldConstructor(CustomWorld);