aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models/src/test/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java66
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java21
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java64
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java37
4 files changed, 139 insertions, 49 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
index 733ba3807..f5a2149b4 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
@@ -46,7 +46,8 @@ import org.onap.policy.models.base.PfConceptKey;
*/
class JpaAutomationCompositionTest {
- private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+ private static final String NULL_KEY_ERROR = "instanceId is marked .*ull but is null";
+ private static final UUID INSTANCE_ID = UUID.fromString("709c62b3-8918-41b9-a747-d21eb79c6c20");
private static final String COMPOSITION_ID = "709c62b3-8918-41b9-a747-e21eb79c6c41";
@Test
@@ -56,74 +57,70 @@ class JpaAutomationCompositionTest {
}).hasMessageMatching("copyConcept is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition((PfConceptKey) null);
+ new JpaAutomationComposition(null, null, null, null, null);
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, null);
+ new JpaAutomationComposition(null, null, null, null, new LinkedHashMap<>());
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, new LinkedHashMap<>());
+ new JpaAutomationComposition(null, null, null, AutomationCompositionState.UNINITIALISED, null);
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, "key", null, null);
+ new JpaAutomationComposition(null, null, null, AutomationCompositionState.UNINITIALISED,
+ new LinkedHashMap<>());
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, "key", null, new LinkedHashMap<>());
+ new JpaAutomationComposition(null, null, "key", null, new LinkedHashMap<>());
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, "key", AutomationCompositionState.UNINITIALISED, null);
+ new JpaAutomationComposition(null, null, "key", AutomationCompositionState.UNINITIALISED, null);
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, "key", AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
+ new JpaAutomationComposition(null, null, "key", AutomationCompositionState.UNINITIALISED,
+ new LinkedHashMap<>());
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), null, null, null);
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null, null, null);
}).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), null, null, new LinkedHashMap<>());
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null, null, new LinkedHashMap<>());
}).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED, null);
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null,
+ AutomationCompositionState.UNINITIALISED, null);
}).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null,
+ AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
}).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), "key", null, null);
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key", null, null);
}).hasMessageMatching("state is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), "key", null, new LinkedHashMap<>());
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key", null,
+ new LinkedHashMap<>());
}).hasMessageMatching("state is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), "key", AutomationCompositionState.UNINITIALISED, null);
+ new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key",
+ AutomationCompositionState.UNINITIALISED, null);
}).hasMessageMatching("elements is marked .*ull but is null");
assertNotNull(new JpaAutomationComposition());
- assertNotNull(new JpaAutomationComposition((new PfConceptKey())));
- assertNotNull(new JpaAutomationComposition(new PfConceptKey(), "key", AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>()));
+ assertNotNull(new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key",
+ AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()));
}
@Test
@@ -182,23 +179,24 @@ class JpaAutomationCompositionTest {
new StandardCoder().decode(new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"),
AutomationComposition.class);
+ noOrderedStateAc.setInstanceId(INSTANCE_ID);
var noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
assertNull(noOrderedStateJpaAc.getOrderedState());
noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
assertEquals(testJpaAutomationComposition, noOrderedStateJpaAc);
- var automationCompositionsWithElements = new StandardCoder().decode(
- new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class);
+ var acWithElements =
+ new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
+ AutomationCompositions.class).getAutomationCompositionList().get(0);
- var jpaAutomationCompositionWithElements =
- new JpaAutomationComposition(automationCompositionsWithElements.getAutomationCompositionList().get(0));
+ acWithElements.setInstanceId(INSTANCE_ID);
+ var jpaAutomationCompositionWithElements = new JpaAutomationComposition(acWithElements);
assertEquals(4, jpaAutomationCompositionWithElements.getElements().size());
assertEquals(17, jpaAutomationCompositionWithElements.getKeys().size());
assertThatCode(jpaAutomationCompositionWithElements::clean).doesNotThrowAnyException();
- assertEquals(automationCompositionsWithElements.getAutomationCompositionList().get(0),
- jpaAutomationCompositionWithElements.toAuthorative());
+ assertEquals(acWithElements, jpaAutomationCompositionWithElements.toAuthorative());
}
@Test
@@ -282,6 +280,7 @@ class JpaAutomationCompositionTest {
var ac2 = new JpaAutomationComposition();
ac2.setCompositionId(COMPOSITION_ID);
+ ac2.setInstanceId(ac0.getInstanceId());
assertEquals(ac2, ac0);
}
@@ -299,6 +298,7 @@ class JpaAutomationCompositionTest {
private AutomationComposition createAutomationCompositionInstance() {
var testAutomationComposition = new AutomationComposition();
testAutomationComposition.setName("automation-composition");
+ testAutomationComposition.setInstanceId(INSTANCE_ID);
testAutomationComposition.setVersion("0.0.1");
testAutomationComposition.setCompositionId(UUID.fromString(COMPOSITION_ID));
testAutomationComposition.setElements(new LinkedHashMap<>());
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 a2d6d69c2..50953d692 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
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -46,6 +47,8 @@ import org.springframework.data.domain.Example;
class AcDefinitionProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML_PROP =
+ "clamp/acm/test/tosca-template-additional-properties.yaml";
private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
@@ -57,6 +60,24 @@ class AcDefinitionProviderTest {
}
@Test
+ void testDocCopyCompare() {
+
+ var inputServiceTemplateProperties = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP);
+ var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplateProperties);
+ var docServiceTemplateCopy = new DocToscaServiceTemplate(docServiceTemplate);
+
+ assertTrue(docServiceTemplate.compareTo(docServiceTemplateCopy) < -1);
+ assertThat(docServiceTemplate.compareToWithoutEntities(docServiceTemplateCopy)).isZero();
+
+ var acmDefinition = getAcDefinition(docServiceTemplate);
+ var acmDefinitionCopy = getAcDefinition(docServiceTemplateCopy);
+
+ assertThat(acmDefinition.getServiceTemplate().getName()).isEqualTo(
+ acmDefinitionCopy.getServiceTemplate().getName());
+
+ }
+
+ @Test
void testCreateServiceTemplate() {
var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
var acmDefinition = getAcDefinition(docServiceTemplate);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
index 5b12eee17..d7d96e9bd 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
import java.util.List;
import java.util.Optional;
+import java.util.UUID;
import javax.persistence.EntityNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -40,7 +41,6 @@ import org.onap.policy.clamp.models.acm.persistence.repository.AutomationComposi
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class AutomationCompositionProviderTest {
@@ -68,18 +68,32 @@ class AutomationCompositionProviderTest {
}
@Test
- void testAutomationCompositionSave() {
+ void testAutomationCompositionCreate() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertThatThrownBy(() -> automationCompositionProvider.saveAutomationComposition(null))
+ when(automationCompositionRepository.save(any(JpaAutomationComposition.class)))
+ .thenReturn(inputAutomationCompositionsJpa.get(0));
+ var inputAc = inputAutomationCompositions.getAutomationCompositionList().get(0);
+
+ var createdAutomationComposition = automationCompositionProvider.createAutomationComposition(inputAc);
+ inputAc.setInstanceId(createdAutomationComposition.getInstanceId());
+ assertEquals(inputAc, createdAutomationComposition);
+ }
+
+ @Test
+ void testAutomationCompositionUpdate() {
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+
+ assertThatThrownBy(() -> automationCompositionProvider.updateAutomationComposition(null))
.hasMessageMatching(OBJECT_IS_NULL);
when(automationCompositionRepository.save(inputAutomationCompositionsJpa.get(0)))
.thenReturn(inputAutomationCompositionsJpa.get(0));
var createdAutomationComposition = automationCompositionProvider
- .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0));
+ .updateAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0));
assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), createdAutomationComposition);
}
@@ -121,31 +135,49 @@ class AutomationCompositionProviderTest {
.getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)))
.hasMessageMatching("AutomationComposition not found");
- ac = automationCompositionProvider.findAutomationComposition(ID_NAME, ID_VERSION)
- .orElse(new AutomationComposition());
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
-
assertThat(automationCompositionProvider
.findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty();
}
@Test
- void testDeleteAutomationComposition() {
+ void testGetAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertThatThrownBy(
- () -> automationCompositionProvider.deleteAutomationComposition(ID_NAME_NOT_EXTST, ID_VERSION))
- .hasMessageMatching(".*.failed, automation composition does not exist");
+ var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ when(automationCompositionRepository.findByInstanceId(automationComposition.getInstanceId().toString()))
+ .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
+ var ac = automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId());
+ assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), ac);
+ }
+
+ @Test
+ void testGetAcInstancesByCompositionId() {
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
- var name = automationComposition.getName();
- var version = automationComposition.getVersion();
+ when(automationCompositionRepository.findByCompositionId(automationComposition.getCompositionId().toString()))
+ .thenReturn(inputAutomationCompositionsJpa);
+ var acList =
+ automationCompositionProvider.getAcInstancesByCompositionId(automationComposition.getCompositionId());
+ assertEquals(inputAutomationCompositions.getAutomationCompositionList(), acList);
+ }
- when(automationCompositionRepository.findById(new PfConceptKey(name, version)))
+ @Test
+ void testDeleteAutomationComposition() {
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+
+ assertThatThrownBy(() -> automationCompositionProvider.deleteAutomationComposition(UUID.randomUUID()))
+ .hasMessageMatching(".*.failed, automation composition does not exist");
+
+ var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ when(automationCompositionRepository.findByInstanceId(automationComposition.getInstanceId().toString()))
.thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
- AutomationComposition deletedAc = automationCompositionProvider.deleteAutomationComposition(name, version);
+ var deletedAc =
+ automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId());
assertEquals(automationComposition, deletedAc);
}
}
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 ccb4b8360..617b2459c 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
@@ -22,19 +22,26 @@ package org.onap.policy.clamp.models.acm.utils;
import static org.assertj.core.api.Assertions.assertThat;
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 java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
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.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
+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.ToscaConceptIdentifier;
@@ -115,6 +122,36 @@ class AcmUtilsTest {
assertThat(result).hasSize(6);
}
+ @Test
+ void testValidateAutomationComposition() throws Exception {
+ var automationComposition = getDummyAutomationComposition();
+ var toscaServiceTemplate = getDummyToscaServiceTemplate();
+ var result = AcmUtils.validateAutomationComposition(automationComposition, toscaServiceTemplate);
+ assertNotNull(result);
+ assertFalse(result.isValid());
+
+ Map<String, ToscaNodeTemplate> nodeTemplates = new HashMap<>();
+ var nodeTemplate = new ToscaNodeTemplate();
+ 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());
+ }
+
+ private AutomationComposition getDummyAutomationComposition() throws CoderException {
+ 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);
+ automationComposition.setElements(map);
+ return automationComposition;
+ }
+
private ToscaServiceTemplate getDummyToscaServiceTemplate() {
var toscaServiceTemplate = new ToscaServiceTemplate();
var policyTypes = getDummyPolicyTypesMap();