Merge "Update gRPC example for JSON Stringify" into guilin
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
index 3adea1a..991257e 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
@@ -131,8 +131,15 @@
             }
         }
 
-        reader.close();
-        writer.close();
+        writer.flush();
+
+        if (!System.in.equals(inputStream)) {
+            reader.close();
+        }
+
+        if (!System.out.equals(outputStream) && !System.err.equals(outputStream)) {
+            writer.close();
+        }
 
         return executionStatus.getRight();
     }
diff --git a/examples/examples-onap-vcpe/src/main/resources/examples/config/ONAPvCPEStandalone/ApexConfig_Sim.json b/examples/examples-onap-vcpe/src/main/resources/examples/config/ONAPvCPEStandalone/ApexConfig_Sim.json
index 39a1b2d..3646959 100644
--- a/examples/examples-onap-vcpe/src/main/resources/examples/config/ONAPvCPEStandalone/ApexConfig_Sim.json
+++ b/examples/examples-onap-vcpe/src/main/resources/examples/config/ONAPvCPEStandalone/ApexConfig_Sim.json
@@ -35,7 +35,7 @@
             "carrierTechnologyParameters": {
                 "carrierTechnology": "FILE",
                 "parameters": {
-                    "fileName": "examples/events/ONAPvCPEStandalone/ConfigureBlackWhiteLists.json"
+                    "fileName": "src/main/resources/examples/events/ONAPvCPEStandalone/ConfigureBlackWhiteLists.json"
                 }
             },
             "eventProtocolParameters": {
@@ -46,7 +46,7 @@
             "carrierTechnologyParameters": {
                 "carrierTechnology": "FILE",
                 "parameters": {
-                    "fileName": "examples/events/ONAPvCPEStandalone/MultiEvents.json"
+                    "fileName": "src/main/resources/examples/events/ONAPvCPEStandalone/MultiEvents.json"
                 }
             },
             "eventProtocolParameters": {
diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js
index 13129f2..eabde8e 100644
--- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js
+++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js
@@ -1,7 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Nordix Foundation.
- *  Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -68,8 +67,8 @@
         var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance(
                 "VCPE_AAI_Type");
 
-        aaiInfo.put("genericVnfResourceVersion", clEvent.get("AAI").get(
-                new utf8Type("generic_DasH_vnf_DoT_resource_DasH_version")));
+        aaiInfo.put("genericVnfResourceVersion", new utf8Type(clEvent.get("AAI").get(
+                new utf8Type("generic_DasH_vnf_DoT_resource_DasH_version"))));
         aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name")));
         aaiInfo.put("genericVnfProvStatus", clEvent.get("AAI").get(
                 new utf8Type("generic_DasH_vnf_DoT_prov_DasH_status")));
@@ -79,9 +78,8 @@
                 new utf8Type("generic_DasH_vnf_DoT_orchestration_DasH_status")));
         aaiInfo.put("genericVnfVnfType", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_type")));
         aaiInfo.put("genericVnfInMaint", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_in_DasH_maint")));
-        aaiInfo
-                .put("genericVnfServiceId", clEvent.get("AAI")
-                        .get(new utf8Type("generic_DasH_vnf_DoT_service_DasH_id")));
+        aaiInfo.put("genericVnfServiceId", clEvent.get("AAI")
+               .get(new utf8Type("generic_DasH_vnf_DoT_service_DasH_id")));
         aaiInfo.put("genericVnfVnfId", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")));
         aaiInfo.put("vserverIsClosedLoopDisabled", clEvent.get("AAI").get(
                 new utf8Type("vserver_DoT_is_DasH_closed_DasH_loop_DasH_disabled")));
@@ -98,6 +96,11 @@
 
         executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfID.toString(), vcpeClosedLoopStatus);
 
+        // Test of stringify
+        executor.logger.info(new java.lang.String("vcpeClosedLoopStatus as JSON:"));
+        executor.logger.info(executor.stringify2Json(vcpeClosedLoopStatus,
+            executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper()));
+
         executor.logger.info("Created context information for new vCPE VNF \"" + vnfID.toString() + "\"");
     }
 
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java
index 768f372..2c2cf52 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +22,9 @@
 
 package org.onap.policy.apex.domains.onap.vcpe;
 
+import static org.awaitility.Awaitility.await;
+
+import java.util.concurrent.TimeUnit;
 import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
@@ -61,6 +65,10 @@
 
         final ApexMain apexMain = new ApexMain(apexArgs);
 
+        await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+
+        // This test should be amended to start and shutdown the simulator as part of the test and not separately as
+        // is done in the gRPC test.
         ThreadUtilities.sleep(1000000);
         apexMain.shutdown();
     }
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java
index 310c0c0..61c2df7 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java
@@ -20,6 +20,9 @@
 
 package org.onap.policy.apex.domains.onap.vcpe;
 
+import static org.awaitility.Awaitility.await;
+
+import java.util.concurrent.TimeUnit;
 import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
@@ -55,6 +58,10 @@
         // @formatter:on
         final ApexMain apexMain = new ApexMain(apexArgs);
 
+        await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+
+        // This test should be amended to start and shutdown the simulator as part of the test and not separately as
+        // is done in the gRPC test.
         ThreadUtilities.sleep(1000000);
         apexMain.shutdown();
     }
diff --git a/examples/examples-onap-vcpe/src/test/resources/etc/Notes.txt b/examples/examples-onap-vcpe/src/test/resources/etc/Notes.txt
index d0a5a69..aa378af 100644
--- a/examples/examples-onap-vcpe/src/test/resources/etc/Notes.txt
+++ b/examples/examples-onap-vcpe/src/test/resources/etc/Notes.txt
@@ -50,3 +50,6 @@
 
 On an extraction of the Apex tarball, run the Apex client
 bin/apexApps.sh full-client
+
+Run standalone version using Maven
+mvn exec:java  -Dexec.classpathScope="test" -Dexec.mainClass=org.onap.policy.apex.domains.onap.vcpe.OnapVcpeStandaloneRunner
diff --git a/examples/examples-onap-vcpe/src/test/resources/logback-test.xml b/examples/examples-onap-vcpe/src/test/resources/logback-test.xml
index b3a202c..e48e25b 100644
--- a/examples/examples-onap-vcpe/src/test/resources/logback-test.xml
+++ b/examples/examples-onap-vcpe/src/test/resources/logback-test.xml
@@ -2,6 +2,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2016-2018 Ericsson. All rights reserved.
+   Modifications Copyright (C) 2020 Nordix Foundation.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -23,7 +24,6 @@
 
     <contextName>Apex</contextName>
     <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
-    <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" />
 
     <!-- USE FOR STD OUT ONLY -->
     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">