Fix delete Policy type in policy participant 44/142644/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Thu, 4 Dec 2025 15:39:43 +0000 (15:39 +0000)
committerFrancesco Fiora <francesco.fiora@est.tech>
Thu, 4 Dec 2025 15:41:47 +0000 (15:41 +0000)
Issue-ID: POLICY-5507
Change-Id: Ida7052d50530ea1da9501301e4916023a13d2eac
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java

index 0daf6e4..a33a141 100644 (file)
@@ -108,7 +108,11 @@ public class AutomationCompositionElementHandler extends AcElementListenerV3 {
         }
         // Delete all policy types of this automation composition from policy framework
         for (var policyType : policyTypeList) {
-            apiHttpClient.deletePolicyType(policyType.getName(), policyType.getVersion());
+            try {
+                apiHttpClient.deletePolicyType(policyType.getName(), policyType.getVersion());
+            } catch (WebClientResponseException e) {
+                LOGGER.warn(e.getMessage(), e);
+            }
         }
     }
 
index 5ced117..d28b4ae 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.participant.policy.main.handler;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.clearInvocations;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -117,6 +118,24 @@ class AutomationCompositionElementHandlerTest {
                 "Undeployed");
     }
 
+    @Test
+    void testUnDeploy() throws PfModelException {
+        var api = mock(PolicyApiHttpClient.class);
+        var pap = mock(PolicyPapHttpClient.class);
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
+
+        doThrow(new WebClientResponseException(HttpStatus.BAD_REQUEST.value(), "", null, null, null))
+                .when(api).deletePolicyType(any(), any());
+
+        var compositionElement = getCompositionElement();
+        var instanceElement = getInstanceElement();
+        handler.undeploy(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+                "Undeployed");
+    }
+
     @Test
     void testDeployError() {
         var api = mock(PolicyApiHttpClient.class);