Fixed Instance Properties Name

Fixed issue where the system put append _Instance1
so the end user can put their own custom name

Issue-ID: POLICY-3978
Change-Id: I04500148aeee49c64f278ce00daa55d14f964b90
Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
index c12d4fb..ac18bca 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
@@ -14,7 +14,7 @@
     description: Participant Description
     participantId:
       name: K8sParticipant0
-      version: 2.3.4
+      version: 1.0.0
     participantType:
       name: org.onap.policy.clamp.acm.KubernetesParticipant
       version: 2.3.4
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
index dfb9d15..9e07cde 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
@@ -63,7 +63,7 @@
 @Transactional
 public class CommissioningProvider {
     public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
-    private static final String INSTANCE_TEXT = "_Instance";
+    private static final String HYPHEN = "-";
 
     private final ServiceTemplateProvider serviceTemplateProvider;
     private final AutomationCompositionProvider acProvider;
@@ -356,7 +356,7 @@
             Map<String, ToscaNodeTemplate> toscaNodeTemplates = new HashMap<>();
 
             serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> {
-                if (!nodeTemplate.getName().contains(INSTANCE_TEXT)) {
+                if (!nodeTemplate.getName().contains(HYPHEN)) {
                     toscaNodeTemplates.put(key, nodeTemplate);
                 }
             });
@@ -377,7 +377,7 @@
      */
     private boolean verifyIfInstancePropertiesExists() {
         return acProvider.getAllNodeTemplates().stream()
-            .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(INSTANCE_TEXT));
+            .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(HYPHEN));
 
     }
 }
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 39d8402..40d4c5a 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -81,7 +81,7 @@
     private static final String PARTICIPANT_TYPE_PROPERTY_KEY = "participantType";
     private static final String AC_ELEMENT_NAME = "name";
     private static final String AC_ELEMENT_VERSION = "version";
-    private static final String INSTANCE_TEXT = "_Instance";
+    private static final String HYPHEN = "-";
 
     private static final Gson GSON = new Gson();
 
@@ -101,7 +101,7 @@
     public InstancePropertiesResponse createInstanceProperties(ToscaServiceTemplate serviceTemplate)
         throws PfModelException {
 
-        String instanceName = generateSequentialInstanceName();
+        String instanceName = serviceTemplate.getName();
         AutomationComposition automationComposition = new AutomationComposition();
         Map<UUID, AutomationCompositionElement> automationCompositionElements = new HashMap<>();
 
@@ -114,9 +114,9 @@
 
         nodeTemplates.forEach((key, template) -> {
             ToscaNodeTemplate newNodeTemplate = new ToscaNodeTemplate();
-            String name = key + instanceName;
+            String name = key + "-" + instanceName;
             String version = template.getVersion();
-            String description = template.getDescription() + instanceName;
+            String description = template.getDescription() + " " + instanceName;
             newNodeTemplate.setName(name);
             newNodeTemplate.setVersion(version);
             newNodeTemplate.setDescription(description);
@@ -528,9 +528,9 @@
             automationCompositionElements.put(automationCompositionElement.getId(), automationCompositionElement);
         }
 
-        automationComposition.setName("PMSH" + instanceName);
+        automationComposition.setName(instanceName);
         automationComposition.setVersion(template.getVersion());
-        automationComposition.setDescription("PMSH automation composition " + instanceName);
+        automationComposition.setDescription("Automation composition " + instanceName);
         automationComposition.setState(AutomationCompositionState.UNINITIALISED);
         automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
     }
@@ -550,10 +550,10 @@
 
         return toscaDefinitionsNames.stream().reduce("", (s1, s2) -> {
 
-            if (s2.contains(INSTANCE_TEXT)) {
-                String[] instances = s2.split(INSTANCE_TEXT);
+            if (s2.contains(HYPHEN)) {
+                String[] instances = s2.split(HYPHEN);
 
-                return INSTANCE_TEXT + instances[1];
+                return HYPHEN + instances[1];
             }
 
             return s1;
@@ -561,24 +561,6 @@
     }
 
     /**
-     * Generates Instance Name in sequential order and return it to append to the Node Template Name.
-     *
-     * @return instanceName
-     */
-    private String generateSequentialInstanceName() {
-        List<ToscaNodeTemplate> nodeTemplates = automationCompositionProvider.getAllNodeTemplates();
-
-        int instanceNumber = nodeTemplates.stream().map(ToscaNodeTemplate::getName)
-            .filter(name -> name.contains(INSTANCE_TEXT)).map(n -> {
-                String[] defNameArr = n.split(INSTANCE_TEXT);
-
-                return Integer.parseInt(defNameArr[1]);
-            }).reduce(0, Math::max);
-
-        return INSTANCE_TEXT + (instanceNumber + 1);
-    }
-
-    /**
      * Retrieves automation composition Definition.
      *
      * @param template tosca node template
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 30ed89e..5db0b0a 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -57,7 +57,7 @@
  *
  */
 class AutomationCompositionInstantiationProviderTest {
-    private static final String ID_NAME = "PMSH_Instance1";
+    private static final String ID_NAME = "PMSH_Test_Instance";
     private static final String ID_VERSION = "1.2.3";
     private static final String AC_INSTANTIATION_CREATE_JSON =
         "src/test/resources/rest/acm/AutomationCompositions.json";
@@ -97,7 +97,7 @@
     }
 
     @Test
-    void testIntanceResponses() throws Exception {
+    void testInstanceResponse() throws Exception {
         var participantProvider = Mockito.mock(ParticipantProvider.class);
         var acProvider = mock(AutomationCompositionProvider.class);
         var supervisionHandler = mock(SupervisionHandler.class);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index 2ad15bd..eae2883 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -68,7 +68,7 @@
 @TestPropertySource(locations = {"classpath:application_test.properties"})
 class InstantiationControllerTest extends CommonRestController {
 
-    private static final String ID_NAME = "PMSH_Instance1";
+    private static final String ID_NAME = "PMSH_Test_Instance";
     private static final String ID_VERSION = "1.2.3";
 
     private static final String AC_INSTANTIATION_CREATE_JSON =
diff --git a/runtime-acm/src/test/resources/rest/servicetemplates/pmsh_multiple_ac_tosca.yaml b/runtime-acm/src/test/resources/rest/servicetemplates/pmsh_multiple_ac_tosca.yaml
index 1d3825f..2a85a5f 100644
--- a/runtime-acm/src/test/resources/rest/servicetemplates/pmsh_multiple_ac_tosca.yaml
+++ b/runtime-acm/src/test/resources/rest/servicetemplates/pmsh_multiple_ac_tosca.yaml
@@ -1,4 +1,5 @@
 tosca_definitions_version: tosca_simple_yaml_1_3
+name: PMSH_Test_Instance
 data_types:
   onap.datatypes.ToscaConceptIdentifier:
     derived_from: tosca.datatypes.Root