diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-a1pms')
3 files changed, 55 insertions, 53 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java index 9b942b961..bcc3fd498 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java @@ -23,9 +23,7 @@ package org.onap.policy.clamp.acm.participant.a1pms.handler; import java.lang.invoke.MethodHandles; import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.UUID; -import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.ValidationException; import lombok.AccessLevel; @@ -46,8 +44,6 @@ import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -75,18 +71,19 @@ public class AutomationCompositionElementHandler implements AutomationCompositio /** * Handle a automation composition element state change. * + * @param automationCompositionId the ID of the automation composition * @param automationCompositionElementId the ID of the automation composition element * @param currentState the current state of the automation composition element * @param newState the state to which the automation composition element is changing to * @throws PfModelException in case of a model exception */ @Override - public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId, + public void automationCompositionElementStateChange(UUID automationCompositionId, UUID automationCompositionElementId, AutomationCompositionState currentState, AutomationCompositionOrderedState newState) throws A1PolicyServiceException { switch (newState) { case UNINITIALISED: - ConfigurationEntity configurationEntity = configRequestMap.get(automationCompositionElementId); + var configurationEntity = configRequestMap.get(automationCompositionElementId); if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) { acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities()); configRequestMap.remove(automationCompositionElementId); @@ -118,15 +115,16 @@ public class AutomationCompositionElementHandler implements AutomationCompositio /** * Callback method to handle an update on an automation composition element. * + * @param automationCompositionId the ID of the automation composition * @param element the information on the automation composition element - * @param nodeTemplate toscaNodeTemplate + * @param properties properties Map */ @Override - public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId, - AutomationCompositionElement element, ToscaNodeTemplate nodeTemplate) throws A1PolicyServiceException { + public void automationCompositionElementUpdate(UUID automationCompositionId, + AutomationCompositionElement element, Map<String, Object> properties) throws A1PolicyServiceException { try { - var configurationEntity = CODER.convert(nodeTemplate.getProperties(), ConfigurationEntity.class); - Set<ConstraintViolation<ConfigurationEntity>> violations = + var configurationEntity = CODER.convert(properties, ConfigurationEntity.class); + var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity); if (violations.isEmpty()) { if (acA1PmsClient.isPmsHealthy()) { diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java index 635b77486..ce775b616 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java @@ -39,10 +39,8 @@ import org.onap.policy.clamp.acm.participant.a1pms.utils.CommonTestData; import org.onap.policy.clamp.acm.participant.a1pms.utils.ToscaUtils; import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -54,14 +52,13 @@ class AcElementHandlerTest { @InjectMocks @Spy private AutomationCompositionElementHandler automationCompositionElementHandler = - new AutomationCompositionElementHandler(acA1PmsClient); - + new AutomationCompositionElementHandler(acA1PmsClient); private final CommonTestData commonTestData = new CommonTestData(); private static ToscaServiceTemplate serviceTemplate; private static final String A1_AUTOMATION_COMPOSITION_ELEMENT = - "org.onap.domain.database.A1PMSAutomationCompositionElement"; + "org.onap.domain.database.A1PMSAutomationCompositionElement"; @BeforeAll static void init() { @@ -81,22 +78,22 @@ class AcElementHandlerTest { var element = commonTestData.getAutomationCompositionElement(); var automationCompositionElementId = element.getId(); - Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - automationCompositionElementHandler.automationCompositionElementUpdate( - commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT)); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + automationCompositionElementHandler + .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.PASSIVE)); + automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, + AutomationCompositionOrderedState.PASSIVE)); assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.UNINITIALISED)); + automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, + AutomationCompositionOrderedState.UNINITIALISED)); assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.RUNNING)); + automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, + AutomationCompositionOrderedState.RUNNING)); when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE); assertThrows(A1PolicyServiceException.class, @@ -107,35 +104,30 @@ class AcElementHandlerTest { @Test void test_AutomationCompositionElementUpdate() { - AutomationCompositionElement element = commonTestData.getAutomationCompositionElement(); + var element = commonTestData.getAutomationCompositionElement(); - Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementUpdate( - commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT))); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + assertDoesNotThrow(() -> automationCompositionElementHandler + .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties())); } @Test void test_AutomationCompositionElementUpdateWithUnhealthyA1pms() { - AutomationCompositionElement element = commonTestData.getAutomationCompositionElement(); + var 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))); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler + .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties())); } @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)); + var element = commonTestData.getAutomationCompositionElement(); + assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler + .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, + Map.of())); } } diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java index be573cb37..b68faa692 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java +++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java @@ -31,6 +31,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; public class CommonTestData { private static final String TEST_KEY_NAME = "org.onap.domain.database.A1PMSAutomationCompositionElement"; + private static final List<UUID> AC_ID_LIST = List.of(UUID.randomUUID(), UUID.randomUUID()); /** * Get a automationComposition Element. @@ -38,7 +39,7 @@ public class CommonTestData { * @return automationCompositionElement object */ public AutomationCompositionElement getAutomationCompositionElement() { - AutomationCompositionElement element = new AutomationCompositionElement(); + var element = new AutomationCompositionElement(); element.setId(UUID.randomUUID()); element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1")); element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); @@ -48,30 +49,41 @@ public class CommonTestData { /** * Get automation composition id. * + * @param instanceNo Identifier instance no * @return ToscaConceptIdentifier automationCompositionId */ - public ToscaConceptIdentifier getAutomationCompositionId() { + public ToscaConceptIdentifier getA1PolicyServiceId(int instanceNo) { + return new ToscaConceptIdentifier("A1PMSInstance" + instanceNo, "1.0.0"); + } + + /** + * Get automation composition id. + * + * @return UUID automationCompositionId + */ + public UUID getAutomationCompositionId() { return getAutomationCompositionId(0); } /** * Get automation composition id. + * * @param instanceNo Identifier instance no - * @return ToscaConceptIdentifier automationCompositionId + * @return UUID automationCompositionId */ - public ToscaConceptIdentifier getAutomationCompositionId(int instanceNo) { - return new ToscaConceptIdentifier("A1PMSInstance" + instanceNo, "1.0.0"); + public UUID getAutomationCompositionId(int instanceNo) { + return AC_ID_LIST.get(instanceNo); } - /** * Get valid policy entities. + * * @return List of policy entities */ public List<A1PolicyServiceEntity> getValidPolicyEntities() { - A1PolicyServiceEntity a1PolicyServiceEntity1 = new A1PolicyServiceEntity(getAutomationCompositionId(0), + var a1PolicyServiceEntity1 = new A1PolicyServiceEntity(getA1PolicyServiceId(0), "testService1", "http://localhost", 0); - A1PolicyServiceEntity a1PolicyServiceEntity2 = new A1PolicyServiceEntity(getAutomationCompositionId(1), + var a1PolicyServiceEntity2 = new A1PolicyServiceEntity(getA1PolicyServiceId(1), "testService2", "http://127.0.0.1", 0); return List.of(a1PolicyServiceEntity1, a1PolicyServiceEntity2); } |