Fix for adding BDD prefixes for for download

Change-Id: Id796408470330300f79120ba5d39987989aff206
Issue-ID: SDC-990
Signed-off-by: ilanap <ilanap@amdocs.com>
diff --git a/openecomp-bdd/.gitignore b/openecomp-bdd/.gitignore
index 24d45c4..ce33f66 100644
--- a/openecomp-bdd/.gitignore
+++ b/openecomp-bdd/.gitignore
@@ -7,4 +7,4 @@
 node_modules
 .npmrc
 npm-debug.log
-config.json
\ No newline at end of file
+devConfig.json
diff --git a/openecomp-bdd/config.json b/openecomp-bdd/config.json
index 6038f18..3806355 100644
--- a/openecomp-bdd/config.json
+++ b/openecomp-bdd/config.json
@@ -1,13 +1,16 @@
 {
   "protocol" : "http",
-  "server": "SET_TO_YOUR_SERVER_IP",
 
-  "port": 8285,
-
-  "prefix" : {
-    "onboarding":"sdc1/feProxy/onboarding-api/v1.0",
-    "vf":"sdc1/feProxy/rest/v1",
-    "activity_spec":"sdc1/feProxy/activityspec-api/v1"
-
+  "onboarding" : {
+    "port" : 8285,
+    "prefix" : "sdc1/feProxy/onboarding-api/v1.0"
+  },
+  "vf" : {
+    "port" : 8285,
+    "prefix" : "sdc1/feProxy/rest/v1"
+  },
+  "activity_spec" : {
+    "port" : 8080,
+    "prefix" : "sdc1/feProxy/activityspec-api/v1"
   }
 }
\ No newline at end of file
diff --git a/openecomp-bdd/plugins/README.md b/openecomp-bdd/plugins/README.md
index 50d4758..118e029 100644
--- a/openecomp-bdd/plugins/README.md
+++ b/openecomp-bdd/plugins/README.md
@@ -4,8 +4,12 @@
 The Modules on the left contains all steps for particalar aress and/or explanations of what they do.<br>
 <br><br>
 <h3>How to set the server</h3>
-<li> Either update the config.json file and set the server
-<li> Or set the SERVER environment variable and it will override the configuration file
+<li> Create a "devConfig.json" file under the openecomp-bdd directory with the following content and replace the placeholders:
+{
+  "server": "[YOUR_SERVER]",
+  "user": "[USER_ID_FOR_APPLICATION]"
+}
+<li> Or set the SERVER and USER environment variables and it will override the configuration file
 <h3>How to run with Maven</h3>
 <li>"mvn install" will install npm if needed, download all modules and create the documentation under the "docs" folder
 <li>"mvn test-and-report" will run all  tests in the features folder and create an HTML report under the "reports" folder
diff --git a/openecomp-bdd/stepDefinitions/Utils.js b/openecomp-bdd/stepDefinitions/Utils.js
index 08d0a2b..4a54ebe 100644
--- a/openecomp-bdd/stepDefinitions/Utils.js
+++ b/openecomp-bdd/stepDefinitions/Utils.js
@@ -17,8 +17,8 @@
 const fs = require('fs');
 require('node-zip');
 
-function _request(context, method, path, data, isBinary=false, prefix='onboarding') {
-	let server = context.server + '/' + context.prefix[prefix];
+function _request(context, method, path, data, isBinary=false, type='onboarding') {
+	let server = context.getUrlForType(type);
 
 	let options = {
 		method: method,
@@ -99,13 +99,14 @@
 	});
 }
 
-function download(context, path, filePath,  callback){
-		let options = {
+function download(context, path, filePath,  callback, type='onboarding') {
+	let server = context.getUrlForType(type);
+	let options = {
 			method: 'GET',
-			url: context.onboarding_server + path,
+			url: server + path,
 			headers: context.headers
 		};
-		var file = fs.createWriteStream(filePath);
+	var file = fs.createWriteStream(filePath);
 		var r = request(options).pipe(file);
 		r.on('error', function (err) {
 			console.log(err);
diff --git a/openecomp-bdd/stepDefinitions/world.js b/openecomp-bdd/stepDefinitions/world.js
index ba6d57a..fd72505 100644
--- a/openecomp-bdd/stepDefinitions/world.js
+++ b/openecomp-bdd/stepDefinitions/world.js
@@ -15,6 +15,10 @@
  */
 const { setWorldConstructor } = require('cucumber');
 const config = require('../config.json');
+let localDevConfig = {};
+try {
+	localDevConfig = require('../devConfig.json');
+} catch (e) {}
 var {setDefaultTimeout} = require('cucumber');
 
 /**
@@ -32,19 +36,18 @@
  **/
 class CustomWorld {
 	constructor(options) {
-		this.context = {}
-		if (options.parameters && options.parameters.server) {
-			this.context.server =  options.parameters.server;
-		} else if (process.env.SERVER) {
-			this.context.server = process.env.SERVER;
-		} else {
-			this.context.server = config.server;
-		}
-		this.context.server = (config.protocol + '://' + this.context.server + ':' + config.port);
-
-
+		this.context = {};
 		this.context.headers = {};
-		this.context.headers['USER_ID']  = 'cs0008';
+		if (localDevConfig.user) {
+			this.context.headers['USER_ID'] = localDevConfig.user;
+		} else {
+			this.context.headers['USER_ID'] = process.env.USER;
+		}
+		if (localDevConfig.server) {
+			this.context.server = localDevConfig.server;
+		} else {
+			this.context.server = process.env.SERVER;
+		}
 
 		this.context.vlm = {id: null, versionId: null};
 		this.context.vsp = {id: null, versionId: null};
@@ -55,15 +58,31 @@
 		this.context.inputData = null;
 		this.context.responseData = null;
 
+		this.context.defaultServerType = 'onboarding';
+
 		this.context.prefix = config.prefix;
+		this.context.port = config.port;
+		this.context.protocol = config.protocol;
 
 		this.setServer = function(server) {
-			this.context.server = (config.protocol + '://' + this.context.server + ':' + config.port);
-		}
+			this.context.server = server;
+		};
+
+		let context = this.context;
+		this.context.getUrlForType = (function(type) {
+			var that = context;
+			return function(type) {
+				let typeData = that[type];
+				return (config.protocol + '://' +
+					that.server + ':' +
+					typeData.port + '/' +
+					typeData.prefix);
+			}
+		})();
 
 		setDefaultTimeout(60 * 1000);
 	}
 }
 
 
-setWorldConstructor(CustomWorld)
+setWorldConstructor(CustomWorld);