summaryrefslogtreecommitdiffstats
path: root/models/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-26 17:31:46 +0000
committerLiam Fallon <liam.fallon@est.tech>2023-01-30 16:39:27 +0000
commit934f7bd443225a6945b0542fa5cb7c043deac426 (patch)
tree55d490b816af0a50f521ee777f82757f28f9a16e /models/src/test/java
parenta178851e9f2e148c17d81c29a9310644e0330b9a (diff)
Refactor Prime and Deprime messages in ACM
Issue-ID: POLICY-4502 Change-Id: Ib0ecc513285bf971a0c25cec528dcdeec5ad63a2 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java31
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java1
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java13
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java68
4 files changed, 73 insertions, 40 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
index b3efc2765..6bb7f1eb7 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
@@ -24,13 +24,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
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.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class ParticipantUtilsTest {
@@ -38,12 +36,6 @@ class ParticipantUtilsTest {
private static final String TOSCA_TEMPLATE_YAML = "examples/acm/test-pm-subscription-handling.yaml";
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
- private static final String AUTOMATION_COMPOSITION_ELEMENT =
- "org.onap.policy.clamp.acm.AutomationCompositionElement";
- private static final String POLICY_AUTOMATION_COMPOSITION_ELEMENT =
- "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement";
- private static final String PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT = "org.onap.policy.clamp.acm.Participant";
- private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
@Test
void testFindStartPhase() {
@@ -54,30 +46,11 @@ class ParticipantUtilsTest {
@Test
void testGetFirstStartPhase() throws CoderException {
- var serviceTemplate =
- YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
var automationCompositions =
CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class);
var result = ParticipantUtils.getFirstStartPhase(automationCompositions.getAutomationCompositionList().get(0),
serviceTemplate);
assertThat(result).isZero();
}
-
- @Test
- void testCheckIfNodeTemplateIsAutomationCompositionElement() throws CoderException {
- var serviceTemplate =
- YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), ToscaServiceTemplate.class);
- var nodeTemplate = new ToscaNodeTemplate();
- nodeTemplate.setType(AUTOMATION_COMPOSITION_ELEMENT);
- assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate))
- .isTrue();
-
- nodeTemplate.setType(POLICY_AUTOMATION_COMPOSITION_ELEMENT);
- assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate))
- .isTrue();
-
- nodeTemplate.setType(PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT);
- assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate))
- .isFalse();
- }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
index a27a74be4..784f1cfde 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
@@ -200,6 +200,7 @@ class AcDefinitionProviderTest {
nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID());
nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier("name", "1.0.0"));
nodeTemplateState.setState(AcTypeState.COMMISSIONED);
+ nodeTemplateState.setParticipantId(UUID.randomUUID());
acmDefinition.setElementStateMap(Map.of(nodeTemplateState.getNodeTemplateId().getName(), nodeTemplateState));
return acmDefinition;
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
index a40d1cc1f..0c5137824 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
@@ -104,6 +104,9 @@ class ParticipantProviderTest {
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size());
+ assertThatThrownBy(() -> participantProvider.getParticipantById(inputParticipants.get(0).getParticipantId()))
+ .hasMessageMatching("Participant Not Found with ID: " + inputParticipants.get(0).getParticipantId());
+
when(participantRepository.findById(any())).thenReturn(
Optional.ofNullable(jpaParticipantList.get(0)));
@@ -128,4 +131,14 @@ class ParticipantProviderTest {
var deletedParticipant = participantProvider.deleteParticipant(participantId);
assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(deletedParticipant);
}
+
+ @Test
+ void testGetSupportedElementMap() {
+ var participantRepository = mock(ParticipantRepository.class);
+ when(participantRepository.findAll()).thenReturn(jpaParticipantList);
+ var participantProvider = new ParticipantProvider(participantRepository);
+
+ var result = participantProvider.getSupportedElementMap();
+ assertThat(result).hasSize(2);
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index c5acada59..c23c38c5b 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
@@ -21,11 +21,13 @@
package org.onap.policy.clamp.models.acm.utils;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.util.ArrayList;
@@ -38,7 +40,7 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
-import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
@@ -50,7 +52,10 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
class AcmUtilsTest {
- private static final ToscaConceptIdentifier TYPE = new ToscaConceptIdentifier("id", "1.0.0");
+ private static final String POLICY_AUTOMATION_COMPOSITION_ELEMENT =
+ "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement";
+ private static final String PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT = "org.onap.policy.clamp.acm.Participant";
+ private static final String TOSCA_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
@Test
void testCommonUtilsParticipantUpdate() {
@@ -72,6 +77,39 @@ class AcmUtilsTest {
}
@Test
+ void testCheckIfNodeTemplateIsAutomationCompositionElement() {
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+ var nodeTemplate = new ToscaNodeTemplate();
+ nodeTemplate.setType(AcmUtils.AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(AcmUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)).isTrue();
+
+ nodeTemplate.setType(POLICY_AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(AcmUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)).isTrue();
+
+ nodeTemplate.setType(PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(AcmUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)).isFalse();
+ }
+
+ @Test
+ void testPrepareParticipantPriming() {
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+
+ var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate);
+ Map<ToscaConceptIdentifier, UUID> map = new HashMap<>();
+ var participantId = UUID.randomUUID();
+ assertThatThrownBy(() -> AcmUtils.prepareParticipantPriming(acElements, map)).hasMessageMatching(
+ "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.1 not supported");
+ map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"),
+ participantId);
+ map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement",
+ "1.0.1"), participantId);
+ map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"),
+ participantId);
+ var result = AcmUtils.prepareParticipantPriming(acElements, map);
+ assertThat(result).isNotEmpty().hasSize(1);
+ }
+
+ @Test
void testCommonUtilsServiceTemplate() {
var acElement = new AutomationCompositionElement();
var toscaServiceTemplate = getDummyToscaServiceTemplate();
@@ -90,7 +128,7 @@ class AcmUtilsTest {
}
@Test
- void testValidateAutomationComposition() throws Exception {
+ void testValidateAutomationComposition() {
var automationComposition = getDummyAutomationComposition();
var toscaServiceTemplate = getDummyToscaServiceTemplate();
var result = AcmUtils.validateAutomationComposition(automationComposition, toscaServiceTemplate);
@@ -102,19 +140,27 @@ class AcmUtilsTest {
nodeTemplate.setType("org.onap.policy.clamp.acm.AutomationComposition");
nodeTemplates.put("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", nodeTemplate);
toscaServiceTemplate.getToscaTopologyTemplate().setNodeTemplates(nodeTemplates);
- var result2 = AcmUtils.validateAutomationComposition(automationComposition, toscaServiceTemplate);
- toscaServiceTemplate.setToscaTopologyTemplate(null);
- assertFalse(result2.isValid());
+ result = AcmUtils.validateAutomationComposition(automationComposition, toscaServiceTemplate);
+ assertFalse(result.isValid());
+
+ var doc = new DocToscaServiceTemplate(CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML));
+ result = AcmUtils.validateAutomationComposition(automationComposition, doc.toAuthorative());
+ assertFalse(result.isValid());
}
- private AutomationComposition getDummyAutomationComposition() throws CoderException {
+ private AutomationComposition getDummyAutomationComposition() {
var automationComposition = new AutomationComposition();
- var element = new StandardCoder().decode(
- new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
- AutomationCompositionElement.class);
automationComposition.setCompositionId(UUID.randomUUID());
Map<UUID, AutomationCompositionElement> map = new LinkedHashMap<>();
- map.put(UUID.randomUUID(), element);
+ try {
+ var element = new StandardCoder().decode(
+ new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
+ AutomationCompositionElement.class);
+ map.put(UUID.randomUUID(), element);
+ } catch (Exception e) {
+ fail("Cannot read or decode " + e.getMessage());
+ return null;
+ }
automationComposition.setElements(map);
return automationComposition;
}