DFC automated tests

Test cases and suites for DFC automated test

Issue-ID: DCAEGEN2-1434

Change-Id: Ibe2200f7dad358520d78217bad4ca6d3b514a3c3
Signed-off-by: BjornMagnussonXA <bjorn.magnusson@est.tech>
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/.gitignore b/test/mocks/datafilecollector-testharness/simulator-group/.gitignore
new file mode 100644
index 0000000..48e8e80
--- /dev/null
+++ b/test/mocks/datafilecollector-testharness/simulator-group/.gitignore
@@ -0,0 +1,6 @@
+configuration
+tls
+docker-compose.yml
+node_modules
+package.json
+prepare-images.sh
\ No newline at end of file
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/Dockerfile-sim-monitor b/test/mocks/datafilecollector-testharness/simulator-group/Dockerfile-sim-monitor
new file mode 100644
index 0000000..145d2d9
--- /dev/null
+++ b/test/mocks/datafilecollector-testharness/simulator-group/Dockerfile-sim-monitor
@@ -0,0 +1,15 @@
+#Image for monitor simulator
+
+FROM node:8
+
+WORKDIR /app
+
+COPY sim-monitor.js ./
+COPY package*.json ./
+
+RUN npm install express
+RUN npm install argparse
+
+EXPOSE 9999
+
+CMD node /app/sim-monitor.js
\ No newline at end of file
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/README.md b/test/mocks/datafilecollector-testharness/simulator-group/README.md
index 5981c79..dc8f286 100644
--- a/test/mocks/datafilecollector-testharness/simulator-group/README.md
+++ b/test/mocks/datafilecollector-testharness/simulator-group/README.md
@@ -31,11 +31,12 @@
 ###Execution
 
 Edit the `docker-compose-setup.sh` (or create a copy) to setup the env variables to the desired test behavior for each simulators.
-See each simulator to find a description of the available settings.
+See each simulator to find a description of the available settings (DR_TC, DR_REDIR_TC and MR_TC).
 The following env variables shall be set (example values).
 Note that NUM_FTPFILES and NUM_PNFS controls the number of ftp files created in the ftp servers. 
-A total of NUM_FTPFILES * NUM_PNFS ftp files will be created in each dtp server (4 files in the below example). 
+A total of NUM_FTPFILES * NUM_PNFS ftp files will be created in each ftp server (4 files in the below example). 
 Large settings will be time consuming at start of the servers.
+Note that the number of files must match the number of file references emitted from the MR sim.
 
 DR_TC="--tc normal"           #Normal behavior of the DR sim
 
@@ -49,6 +50,12 @@
 
 NUM_PNFS="2"                  #Two PNFs
 
+To minimize the number of ftp file creation, the following two variables can be configured in the same file.
+FILE_SIZE="1MB"               #File size for FTP file (1KB, 1MB, 5MB, 50MB or ALL)
+FTP_TYPE="SFTP"               #Type of FTP files to generate (SFTP, FTPS or ALL) 
+
+If `FTP_TYPE` is set to `ALL`, both ftp servers will be populated with the same files. If set to `SFTP` or `FTPS` then only the server serving that protocol will be populated with files.
+
 Run the script `docker-compose-setup.sh`to create a docker-compose with the desired settings. The desired setting
 in the script need to be manually adapted to for each specific simulator behavior according to the above. Check each simulator for available
 parameters.
@@ -73,3 +80,12 @@
 ###Simulator monitor
 Start the simulator monitor server with `sim-monitor-start.sh` and the open a browser with the url `localhost:9999/mon`
 to see the statisics page with data from MR sim, DR sim and DR redir sim.
+Or run as a container, build image first. Note, does not work on Mac.
+
+`cp ../dr-sim/package.json .`
+
+`docker build  -t sim-mon:latest -f Dockerfile-sim-monitor  .`
+
+Then run it, `docker run --network="host" --name sim-mon -it -d sim-mon:latest`
+
+Stop it with `docker stop sim-mon` and if desired, remove the container by `docker rm sim-mon`
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-setup.sh b/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-setup.sh
index af36d05..b9b38f8 100755
--- a/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-setup.sh
+++ b/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-setup.sh
@@ -2,13 +2,13 @@
 
 #Script for manually starting all simulators with test setting below
 
-export DR_TC="--tc normal"
-export DR_REDIR_TC="--tc normal"
-export MR_TC="--tc100"
+export DR_TC="--tc normal"           #Test behaviour for DR sim
+export DR_REDIR_TC="--tc normal"     #Test behaviour for DR redir sim
+export MR_TC="--tc710"               #Test behaviour for MR sim
 export BC_TC=""  #Not in use yet
-export NUM_FTPFILES="10"
-export NUM_PNFS="700"
-export FILE_SIZE="1MB"
-export FTP_TYPE="SFTP"
+export NUM_FTPFILES="105"            #Number of FTP files to generate per PNF
+export NUM_PNFS="700"                #Number of unuqie PNFs to generate FTP file for
+export FILE_SIZE="1MB"               #File size for FTP file (1KB, 1MB, 5MB, 50MB or ALL)
+export FTP_TYPE="SFTP"               #Type of FTP files to generate (SFTP, FTPS or ALL)
 
 source ./simulators-start.sh
\ No newline at end of file
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-template.yml b/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-template.yml
index 89a45a4..8505631 100644
--- a/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-template.yml
+++ b/test/mocks/datafilecollector-testharness/simulator-group/docker-compose-template.yml
@@ -70,4 +70,4 @@
       - ./configuration/vsftpd_ssl.conf:/etc/vsftpd_ssl.conf:ro
 
     restart: on-failure
-  
\ No newline at end of file
+    command: vsftpd /etc/vsftpd_ssl.conf
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/setup-ftp-files-for-image.sh b/test/mocks/datafilecollector-testharness/simulator-group/setup-ftp-files-for-image.sh
index 6c2b4f2..7685c81 100755
--- a/test/mocks/datafilecollector-testharness/simulator-group/setup-ftp-files-for-image.sh
+++ b/test/mocks/datafilecollector-testharness/simulator-group/setup-ftp-files-for-image.sh
@@ -37,10 +37,10 @@
 while [ $p -lt $PNFS ]; do 
     i=0
     while [ $i -lt $NUM ]; do  #Problem with for loop and var substituion in curly bracket....so used good old style loop
-    	if [ $FSIZE = "ALL" ] || [ $FSIZE = "1KB" ]; then ln -s 1KB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-1KB.tar.gz'; fi
-        if [ $FSIZE = "ALL" ] || [ $FSIZE = "1MB" ]; then ln -s 1MB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-1MB.tar.gz'; fi
-        if [ $FSIZE = "ALL" ] || [ $FSIZE = "5MB" ]; then ln -s 5MB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-5MB.tar.gz'; fi
-        if [ $FSIZE = "ALL" ] || [ $FSIZE = "50MB" ]; then ln -s 50MB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-50MB.tar.gz'; fi
+    	if [ $FSIZE = "ALL" ] || [ $FSIZE = "1KB" ]; then ln -s 1KB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-1KB.tar.gz' >& /dev/null; fi
+        if [ $FSIZE = "ALL" ] || [ $FSIZE = "1MB" ]; then ln -s 1MB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-1MB.tar.gz' >& /dev/null; fi
+        if [ $FSIZE = "ALL" ] || [ $FSIZE = "5MB" ]; then ln -s 5MB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-5MB.tar.gz' >& /dev/null; fi
+        if [ $FSIZE = "ALL" ] || [ $FSIZE = "50MB" ]; then ln -s 50MB.tar.gz 'A20000626.2315+0200-2330+0200_PNF'$p'-'$i'-50MB.tar.gz' >& /dev/null; fi
     let i=i+1
     done
     let p=p+1
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/sim-monitor.js b/test/mocks/datafilecollector-testharness/simulator-group/sim-monitor.js
index e4a19c2..634d144 100644
--- a/test/mocks/datafilecollector-testharness/simulator-group/sim-monitor.js
+++ b/test/mocks/datafilecollector-testharness/simulator-group/sim-monitor.js
@@ -30,19 +30,27 @@
 
 	}).on("error", (err) => {
   		console.log("Error: " + err.message);
-  		cb("no response from simulator");
+  		cb("no response");
 	});
 };
 
 //Status variables, for parameters values fetched from other simulators
-var mr1, mr2, mr3, mr4, mr5, mr6, mr7;
+var mr1, mr2, mr3, mr4, mr5, mr6, mr7, mr8, mr9, mr10;
 
-var dr1, dr2, dr3, dr4, dr5, dr6, dr7, dr8, dr9;
+var dr1, dr2, dr3, dr4, dr5, dr6, dr7, dr8, dr9, dr10;
 
 var drr1, drr2, drr3, drr4, drr5, drr6;
 
+//Heartbeat var
+var dfc1;
+
 app.get("/mon",function(req, res){
 
+	//DFC
+	getSimCtr("http://127.0.0.1:8100/heartbeat", function(data) {
+		dfc1 = data;
+    });
+
 	//MR
     getSimCtr("http://127.0.0.1:2222/ctr_requests", function(data) {
     	mr1 = data;
@@ -65,6 +73,15 @@
     getSimCtr("http://127.0.0.1:2222/ctr_unique_PNFs", function(data) {
     	mr7 = data;
     });
+    getSimCtr("http://127.0.0.1:2222/exe_time_first_poll", function(data) {
+    	mr8 = data;
+    });
+    getSimCtr("http://127.0.0.1:2222/ctr_files", function(data) {
+    	mr9 = data;
+    });
+    getSimCtr("http://127.0.0.1:2222/status", function(data) {
+    	mr10 = data;
+    });
 
     //DR
     getSimCtr("http://127.0.0.1:3906/ctr_publish_query", function(data) {
@@ -94,7 +111,10 @@
     getSimCtr("http://127.0.0.1:3906/execution_time", function(data) {
     	dr9 = data;
     });
- 
+    getSimCtr("http://127.0.0.1:3906/ctr_double_publish", function(data) {
+    	dr10 = data;
+    });
+
     //DR REDIR
     getSimCtr("http://127.0.0.1:3908/ctr_publish_requests", function(data) {
     	drr1 = data;
@@ -120,21 +140,28 @@
           "<html>" +
           "<head>" +
             "<meta http-equiv=\"refresh\" content=\"5\">"+  //5 sec auto reefresh
-            "<title>Simulator monitor</title>"+
-          "</head>" +
-          "<body>" +
+            "<title>DFC and simulator monitor</title>"+
+            "</head>" +
+            "<body>" +
+            "<h3>DFC</h3>" +
+            "<font face=\"Courier New\">"+
+            "Heartbeat:....................................." + dfc1 + "<br>" +
+            "</font>"+
             "<h3>MR Simulator</h3>" +
-            "<font face=\"courier\">"+
+            "<font face=\"Courier New\">"+
             "MR TC:........................................." + mr4 + "<br>" +
+            "Status:........................................" + mr10 + "<br>" +
             "Execution time (mm.ss):........................" + mr6 + "<br>" +
+            "Execution time from first poll (mm.ss):....... " + mr8 + "<br>" +
             "Number of requests (polls):...................." + mr1 + "<br>" +
             "Number of responses (polls):..................." + mr2 + "<br>" +
+            "Number of files in all responses:.............." + mr9 + "<br>" +
             "Number of unique files in all responses:......." + mr3 + "<br>" +
             "Number of events..............................." + mr5 + "<br>" +
             "Number of unique PNFs.........................." + mr7 + "<br>" +
             "</font>"+
             "<h3>DR Simulator</h3>" +
-            "<font face=\"courier\">"+
+            "<font face=\"Courier New\">"+
             "DR TC:........................................." + dr8 + "<br>" +
             "Execution time (mm.ss):........................" + dr9 + "<br>" +
             "Number of queries:............................." + dr1 + "<br>" +
@@ -144,9 +171,10 @@
             "Number of responses with redirect:............." + dr5 + "<br>" +
             "Number of responses without redirect:.........." + dr6 + "<br>" +
             "Number of published files:....................." + dr7 + "<br>" +
+            "Number of double published files:.............." + dr10 + "<br>" +
             "</font>"+
             "<h3>DR Redirect Simulator</h3>" +
-            "<font face=\"courier\">"+
+            "<font face=\"Courier New\">"+
             "DR REDIR TC:..................................." + drr3 + "<br>" +
             "Execution time (mm.ss):........................" + drr4 + "<br>" +
             "Number of requests:............................" + drr1 + "<br>" +
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/simulators-kill.sh b/test/mocks/datafilecollector-testharness/simulator-group/simulators-kill.sh
index b7cd6a3..3f0ba35 100755
--- a/test/mocks/datafilecollector-testharness/simulator-group/simulators-kill.sh
+++ b/test/mocks/datafilecollector-testharness/simulator-group/simulators-kill.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-#Stop all simulators 
+#Stop all simulators
 
 docker kill dfc_dr-sim
 docker kill dfc_dr-redir-sim
diff --git a/test/mocks/datafilecollector-testharness/simulator-group/simulators-start.sh b/test/mocks/datafilecollector-testharness/simulator-group/simulators-start.sh
index cc5ce32..774b753 100755
--- a/test/mocks/datafilecollector-testharness/simulator-group/simulators-start.sh
+++ b/test/mocks/datafilecollector-testharness/simulator-group/simulators-start.sh
@@ -51,11 +51,13 @@
 if [ $FTP_TYPE = "ALL" ] || [ $FTP_TYPE = "SFTP" ]; then
 	echo "Creating files for SFTP server, may take time...."
 	docker cp setup-ftp-files-for-image.sh $SFTP_SIM:/tmp/
-	docker exec -w /home/onap/ $SFTP_SIM /tmp/setup-ftp-files-for-image.sh $NUM_FTPFILES $NUM_PNFS $FILE_SIZE #>/dev/null 2>&1
+	#Double slash needed for docker on win...
+	docker exec -w //home/onap/ $SFTP_SIM //tmp/setup-ftp-files-for-image.sh $NUM_FTPFILES $NUM_PNFS $FILE_SIZE #>/dev/null 2>&1
 fi
 if [ $FTP_TYPE = "ALL" ] || [ $FTP_TYPE = "FTPS" ]; then
 	echo "Creating files for FTPS server, may take time...."
 	docker cp setup-ftp-files-for-image.sh $FTPS_SIM:/tmp/setup-ftp-files-for-image.sh
-	docker exec -w /srv $FTPS_SIM /tmp/setup-ftp-files-for-image.sh $NUM_FTPFILES $NUM_PNFS $FILE_SIZE #>/dev/null 2>&1
+	#Double slash needed for docker on win...
+	docker exec -w //srv $FTPS_SIM //tmp/setup-ftp-files-for-image.sh $NUM_FTPFILES $NUM_PNFS $FILE_SIZE #>/dev/null 2>&1
 fi
 echo "Done: All simulators started and configured"