A1pms: Fix Code smells and coverage 95/132595/1
authoraravind.est <aravindhan.a@est.tech>
Tue, 6 Dec 2022 15:42:08 +0000 (15:42 +0000)
committeraravind.est <aravindhan.a@est.tech>
Tue, 6 Dec 2022 16:07:19 +0000 (16:07 +0000)
Issue-ID: CCSDK-3816
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: Ifa9a5d538d13e59ec842edee6d3cbc43a0f0df1d

participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
pom.xml

index 072d144..9b942b9 100755 (executable)
@@ -145,12 +145,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
                 LOGGER.error("Violations found in the config request parameters: {}", violations);
                 throw new ValidationException("Constraint violations in the config request");
             }
-        } catch (ValidationException | CoderException e) {
-            LOGGER.error("Error invoking the A1PMS request for the config ", e);
+        } catch (ValidationException | CoderException | A1PolicyServiceException e) {
             throw new A1PolicyServiceException(HttpStatus.SC_BAD_REQUEST, "Invalid Configuration", e);
-        } catch (A1PolicyServiceException e) {
-            LOGGER.error("Error invoking the A1PMS request for the config ", e);
-            throw e;
         }
     }
 }
index 690f5f2..635b774 100755 (executable)
@@ -21,6 +21,7 @@
 package org.onap.policy.clamp.acm.participant.a1pms.handler;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
@@ -96,6 +97,12 @@ class AcElementHandlerTest {
         assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
             automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
             AutomationCompositionOrderedState.RUNNING));
+
+        when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
+        assertThrows(A1PolicyServiceException.class,
+                () -> automationCompositionElementHandler.automationCompositionElementStateChange(
+                        automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
+                        AutomationCompositionOrderedState.UNINITIALISED));
     }
 
     @Test
@@ -107,4 +114,28 @@ class AcElementHandlerTest {
             commonTestData.getAutomationCompositionId(), element,
             nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT)));
     }
+
+    @Test
+    void test_AutomationCompositionElementUpdateWithUnhealthyA1pms() {
+        AutomationCompositionElement element = commonTestData.getAutomationCompositionElement();
+        when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
+
+        Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+        assertThrows(A1PolicyServiceException.class,
+                () -> automationCompositionElementHandler.automationCompositionElementUpdate(
+                        commonTestData.getAutomationCompositionId(), element,
+                        nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT)));
+    }
+
+    @Test
+    void test_AutomationCompositionElementUpdateWithInvalidConfiguration() {
+        AutomationCompositionElement element = commonTestData.getAutomationCompositionElement();
+
+        Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+        ToscaNodeTemplate toscaNodeTemplate = nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT);
+        toscaNodeTemplate.setProperties(Map.of());
+        assertThrows(A1PolicyServiceException.class,
+                () -> automationCompositionElementHandler.automationCompositionElementUpdate(
+                        commonTestData.getAutomationCompositionId(), element, toscaNodeTemplate));
+    }
 }
diff --git a/pom.xml b/pom.xml
index 5509194..7ae8c7d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -49,7 +49,7 @@
             o policy-clamp-participant-impl-policy: A standard participant for handling polcies for Policy Framework
             o policy-clamp-acm-element-impl: ACM element implementation for integration testing
             o policy-clamp-participant-impl-http: A standard participant for http configurations
-            o policy-clamp-participant-impl-a1: A standard participant for accessing A1-Policy Management Service
+            o policy-clamp-participant-impl-a1pms: A standard participant for accessing A1-Policy Management Service
     </description>
 
     <properties>