aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'models/src/test')
-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/AutomationCompositionProviderTest.java64
-rw-r--r--models/src/test/resources/providers/TestAutomationCompositions.json2
3 files changed, 83 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/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/resources/providers/TestAutomationCompositions.json b/models/src/test/resources/providers/TestAutomationCompositions.json
index 171ce07f6..286759988 100644
--- a/models/src/test/resources/providers/TestAutomationCompositions.json
+++ b/models/src/test/resources/providers/TestAutomationCompositions.json
@@ -2,6 +2,7 @@
"automationCompositionList": [
{
"compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40",
+ "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c89",
"state": "UNINITIALISED",
"orderedState": "UNINITIALISED",
"elements": {
@@ -68,6 +69,7 @@
},
{
"compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40",
+ "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c90",
"state": "UNINITIALISED",
"orderedState": "UNINITIALISED",
"elements": {