summaryrefslogtreecommitdiffstats
path: root/models/src/test
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2022-12-20 09:55:45 +0000
committerGerrit Code Review <gerrit@onap.org>2022-12-20 09:55:45 +0000
commite70bf5c909a4d5abcbc7adcbb4aa120c2e045660 (patch)
tree2622919eb5c86d6400cab8ff35795bd8c75cd730 /models/src/test
parentba5988ab370f3dc5e5214823046e897d25aba0bf (diff)
parente18a523f4fc8075dc5022871fa96ca8754c2c979 (diff)
Merge "Refactor instanceId as primary key in JpaAutomationComposition"
Diffstat (limited to 'models/src/test')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java197
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java127
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java81
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java51
-rw-r--r--models/src/test/resources/providers/TestAutomationCompositions.json8
5 files changed, 163 insertions, 301 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
index d38aaf735..3781c3a7d 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,16 +39,18 @@ import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
- * Test the {@link JpaAutomationCompositionElement} class.
+ * Test the{@link JpaAutomationCompositionElement} class.
*/
class JpaAutomationCompositionElementTest {
- private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+ private static final String NULL_INSTANCE_ID_ERROR = "instanceId is marked .*ull but is null";
+ private static final String NULL_ELEMENT_ID_ERROR = "elementId is marked .*ull but is null";
+ private static final String NULL_ERROR = " is marked .*ull but is null";
+ private static final String ELEMENT_ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e";
+ private static final String INSTANCE_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a";
@Test
void testJpaAutomationCompositionElementConstructor() {
@@ -57,182 +59,121 @@ class JpaAutomationCompositionElementTest {
}).hasMessageMatching("copyConcept is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement((PfReferenceKey) null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", null);
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, null, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement(null, "key");
+ }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, null, AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement(null, null);
+ }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"), null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement(null, null, null, null, null);
+ }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"),
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", null, null, null, AutomationCompositionState.UNINITIALISED);
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), null, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", "key", null, new PfConceptKey("participant", "0.0.1"), null);
+ }).hasMessageMatching("definition" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), null,
+ AutomationCompositionState.UNINITIALISED);
+ }).hasMessageMatching("participantType" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"),
- null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"),
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, null, null);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, null,
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"),
- null);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"),
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null, null);
- }).hasMessageMatching("participantType is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching("participantType is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(),
- new PfConceptKey("participant", "0.0.1"), null);
- }).hasMessageMatching("state is marked .*ull but is null");
+ new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), new PfConceptKey(), null);
+ }).hasMessageMatching("state" + NULL_ERROR);
assertNotNull(new JpaAutomationCompositionElement());
- assertNotNull(new JpaAutomationCompositionElement((new PfReferenceKey())));
- assertNotNull(new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(),
- new PfConceptKey("participant", "0.0.1"), AutomationCompositionState.UNINITIALISED));
+ assertNotNull(new JpaAutomationCompositionElement("key", "key"));
+ assertNotNull(new JpaAutomationCompositionElement("key", "key", new PfConceptKey(),
+ new PfConceptKey("participant", "0.0.1"), AutomationCompositionState.UNINITIALISED));
}
@Test
void testJpaAutomationCompositionElement() {
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAcElement = createJpaAutomationCompositionElementInstance();
var ace = createAutomationCompositionElementInstance();
- assertEquals(ace, testJpaAutomationCompositionElement.toAuthorative());
+ assertEquals(ace, testJpaAcElement.toAuthorative());
assertThatThrownBy(() -> {
- testJpaAutomationCompositionElement.fromAuthorative(null);
+ testJpaAcElement.fromAuthorative(null);
}).hasMessageMatching("element is marked .*ull but is null");
assertThatThrownBy(() -> new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null))
- .isInstanceOf(NullPointerException.class);
-
- var testJpaAutomationCompositionElementFa = new JpaAutomationCompositionElement();
- testJpaAutomationCompositionElementFa.setKey(null);
- testJpaAutomationCompositionElementFa.fromAuthorative(ace);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
- testJpaAutomationCompositionElementFa.setKey(PfReferenceKey.getNullKey());
- testJpaAutomationCompositionElementFa.fromAuthorative(ace);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
- testJpaAutomationCompositionElementFa.setKey(
- new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
- testJpaAutomationCompositionElementFa.fromAuthorative(ace);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
-
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- testJpaAutomationCompositionElement.getKey().getLocalName());
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- new JpaAutomationCompositionElement(createAutomationCompositionElementInstance()).getKey().getLocalName());
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- ((PfReferenceKey) new JpaAutomationCompositionElement(createAutomationCompositionElementInstance())
- .getKeys().get(0)).getLocalName());
-
- testJpaAutomationCompositionElement.clean();
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- testJpaAutomationCompositionElement.getKey().getLocalName());
-
- testJpaAutomationCompositionElement.setDescription(" A Message ");
- testJpaAutomationCompositionElement.clean();
- assertEquals("A Message", testJpaAutomationCompositionElement.getDescription());
-
- var testJpaAutomationCompositionElement2 =
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElement2);
+ .isInstanceOf(NullPointerException.class);
+
+ var testJpaAcElementFa =
+ new JpaAutomationCompositionElement(ace.getId().toString(), testJpaAcElement.getInstanceId());
+ testJpaAcElementFa.fromAuthorative(ace);
+ assertEquals(testJpaAcElement, testJpaAcElementFa);
+
+ assertEquals(ELEMENT_ID, testJpaAcElement.getElementId());
+
+ var testJpaAutomationCompositionElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
+ assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2);
}
@Test
void testJpaAutomationCompositionElementOrderedState() throws CoderException {
var testAutomationCompositionElement = createAutomationCompositionElementInstance();
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
testJpaAutomationCompositionElement.setOrderedState(null);
assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative());
testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
var noOrderedStateAce = new StandardCoder().decode(
- new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
- AutomationCompositionElement.class);
+ new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
+ AutomationCompositionElement.class);
var noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
assertNull(noOrderedStateJpaAce.getOrderedState());
noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
+ noOrderedStateJpaAce.setInstanceId(testJpaAutomationCompositionElement.getInstanceId());
+ noOrderedStateJpaAce.setElementId(testJpaAutomationCompositionElement.getElementId());
assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce);
}
@Test
void testJpaAutomationCompositionElementValidation() {
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
assertThatThrownBy(() -> testJpaAutomationCompositionElement.validate(null))
- .hasMessageMatching("fieldName is marked .*ull but is null");
+ .hasMessageMatching("fieldName is marked .*ull but is null");
assertTrue(testJpaAutomationCompositionElement.validate("").isValid());
}
@Test
void testJpaAutomationCompositionElementCompareTo() {
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
var otherJpaAutomationCompositionElement =
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
+ new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null));
assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement));
assertNotEquals(0,
- testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
+ testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
- testJpaAutomationCompositionElement
- .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ testJpaAutomationCompositionElement.setElementId("BadValue");
assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setKey(
- new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ testJpaAutomationCompositionElement.setElementId(ELEMENT_ID);
+ assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
+
+ testJpaAutomationCompositionElement.setInstanceId("BadValue");
+ assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
+ testJpaAutomationCompositionElement.setInstanceId(INSTANCE_ID);
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
@@ -261,7 +202,7 @@ class JpaAutomationCompositionElementTest {
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
assertEquals(testJpaAutomationCompositionElement,
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
+ new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
}
@Test
@@ -274,7 +215,7 @@ class JpaAutomationCompositionElementTest {
assertEquals(ace0, ace0);
assertNotEquals(null, ace0);
- var ace1 = new JpaAutomationCompositionElement();
+ var ace1 = new JpaAutomationCompositionElement(ace0.getElementId(), ace0.getInstanceId());
ace1.setDefinition(new PfConceptKey("defName", "0.0.1"));
ace1.setDescription("Description");
@@ -289,25 +230,23 @@ class JpaAutomationCompositionElementTest {
assertNotEquals(ace1, ace0);
- var ace2 = new JpaAutomationCompositionElement();
+ var ace2 = new JpaAutomationCompositionElement(ace0.getElementId(), ace0.getInstanceId());
assertEquals(ace2, ace0);
}
private JpaAutomationCompositionElement createJpaAutomationCompositionElementInstance() {
var testAce = createAutomationCompositionElementInstance();
- var testJpaAutomationCompositionElement = new JpaAutomationCompositionElement();
- testJpaAutomationCompositionElement.setKey(null);
- testJpaAutomationCompositionElement.fromAuthorative(testAce);
- testJpaAutomationCompositionElement.setKey(PfReferenceKey.getNullKey());
- testJpaAutomationCompositionElement.fromAuthorative(testAce);
- testJpaAutomationCompositionElement.setProperties(Map.of("key", "{}"));
-
- return testJpaAutomationCompositionElement;
+ var testJpaAcElement =
+ new JpaAutomationCompositionElement(testAce.getId().toString(), INSTANCE_ID);
+ testJpaAcElement.fromAuthorative(testAce);
+ testJpaAcElement.setProperties(Map.of("key", "{}"));
+
+ return testJpaAcElement;
}
private AutomationCompositionElement createAutomationCompositionElementInstance() {
var automationCompositionElement = new AutomationCompositionElement();
- automationCompositionElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ automationCompositionElement.setId(UUID.fromString(ELEMENT_ID));
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1"));
automationCompositionElement.setProperties(Map.of("key", "{}"));
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 f5a2149b4..2164f5782 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,15 +21,15 @@
package org.onap.policy.clamp.models.acm.persistence.concepts;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
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.assertTrue;
import java.io.File;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -42,12 +42,13 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
/**
- * Test the {@link JpaAutomationCompositionTest} class.
+ * Test the{@link JpaAutomationCompositionTest} class.
*/
class JpaAutomationCompositionTest {
- 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 NULL_INSTANCE_ID_ERROR = "instanceId is marked .*ull but is null";
+ private static final String NULL_TEXT_ERROR = " is marked .*ull but is null";
+ private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c20";
private static final String COMPOSITION_ID = "709c62b3-8918-41b9-a747-e21eb79c6c41";
@Test
@@ -58,69 +59,29 @@ class JpaAutomationCompositionTest {
assertThatThrownBy(() -> {
new JpaAutomationComposition(null, null, null, null, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, null, new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationComposition(INSTANCE_ID, null, null, null, new ArrayList<>());
+ }).hasMessageMatching("key" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, "key", null, new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, "key", AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, "key", AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null, null, null);
- }).hasMessageMatching("compositionId is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null, null, new LinkedHashMap<>());
- }).hasMessageMatching("compositionId is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null,
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null,
AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching("compositionId is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
- }).hasMessageMatching("compositionId is marked .*ull but is null");
+ }).hasMessageMatching("compositionId" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key", null, null);
- }).hasMessageMatching("state is marked .*ull but is null");
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), null, null);
+ }).hasMessageMatching("state" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key", null,
- new LinkedHashMap<>());
- }).hasMessageMatching("state is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key",
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching("elements is marked .*ull but is null");
+ }).hasMessageMatching("elements" + NULL_TEXT_ERROR);
assertNotNull(new JpaAutomationComposition());
- assertNotNull(new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key",
- AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()));
+ assertNotNull(new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
+ AutomationCompositionState.UNINITIALISED, new ArrayList<>()));
}
@Test
@@ -138,29 +99,13 @@ class JpaAutomationCompositionTest {
.isInstanceOf(NullPointerException.class);
var testJpaAutomationCompositionFa = new JpaAutomationComposition();
- testJpaAutomationCompositionFa.setKey(null);
- testJpaAutomationCompositionFa.fromAuthorative(participant);
- assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
- testJpaAutomationCompositionFa.setKey(PfConceptKey.getNullKey());
- testJpaAutomationCompositionFa.fromAuthorative(participant);
- assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
- testJpaAutomationCompositionFa.setKey(new PfConceptKey("automation-composition", "0.0.1"));
+ testJpaAutomationCompositionFa.setInstanceId(null);
testJpaAutomationCompositionFa.fromAuthorative(participant);
assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
- assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName());
- assertEquals("automation-composition",
- new JpaAutomationComposition(createAutomationCompositionInstance()).getKey().getName());
+ assertEquals("automation-composition", testJpaAutomationComposition.getName());
assertEquals("automation-composition",
- ((PfConceptKey) new JpaAutomationComposition(createAutomationCompositionInstance()).getKeys().get(0))
- .getName());
-
- testJpaAutomationComposition.clean();
- assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName());
-
- testJpaAutomationComposition.setDescription(" A Message ");
- testJpaAutomationComposition.clean();
- assertEquals("A Message", testJpaAutomationComposition.getDescription());
+ new JpaAutomationComposition(createAutomationCompositionInstance()).getName());
var testJpaAutomationComposition2 = new JpaAutomationComposition(testJpaAutomationComposition);
assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2);
@@ -179,7 +124,7 @@ class JpaAutomationCompositionTest {
new StandardCoder().decode(new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"),
AutomationComposition.class);
- noOrderedStateAc.setInstanceId(INSTANCE_ID);
+ noOrderedStateAc.setInstanceId(UUID.fromString(INSTANCE_ID));
var noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
assertNull(noOrderedStateJpaAc.getOrderedState());
noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
@@ -190,12 +135,9 @@ class JpaAutomationCompositionTest {
new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
AutomationCompositions.class).getAutomationCompositionList().get(0);
- acWithElements.setInstanceId(INSTANCE_ID);
+ acWithElements.setInstanceId(UUID.fromString(INSTANCE_ID));
var jpaAutomationCompositionWithElements = new JpaAutomationComposition(acWithElements);
assertEquals(4, jpaAutomationCompositionWithElements.getElements().size());
- assertEquals(17, jpaAutomationCompositionWithElements.getKeys().size());
- assertThatCode(jpaAutomationCompositionWithElements::clean).doesNotThrowAnyException();
-
assertEquals(acWithElements, jpaAutomationCompositionWithElements.toAuthorative());
}
@@ -219,9 +161,9 @@ class JpaAutomationCompositionTest {
assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition));
assertNotEquals(0, testJpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild()));
- testJpaAutomationComposition.setKey(new PfConceptKey("BadValue", "0.0.1"));
+ testJpaAutomationComposition.setInstanceId("BadValue");
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setKey(new PfConceptKey("automation-composition", "0.0.1"));
+ testJpaAutomationComposition.setInstanceId(INSTANCE_ID);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
testJpaAutomationComposition.setCompositionId(UUID.randomUUID().toString());
@@ -229,6 +171,16 @@ class JpaAutomationCompositionTest {
testJpaAutomationComposition.setCompositionId(COMPOSITION_ID);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setName("BadValue");
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setName("automation-composition");
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
+ testJpaAutomationComposition.setVersion("0.0.0");
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setVersion("0.0.1");
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE);
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
testJpaAutomationComposition.setState(AutomationCompositionState.UNINITIALISED);
@@ -267,8 +219,8 @@ class JpaAutomationCompositionTest {
ac1.setCompositionId(UUID.randomUUID().toString());
ac1.setDescription("Description");
- ac1.setElements(new LinkedHashMap<>());
- ac1.setKey(new PfConceptKey("participant", "0.0.1"));
+ ac1.setElements(new ArrayList<>());
+ ac1.setInstanceId(INSTANCE_ID);
ac1.setState(AutomationCompositionState.UNINITIALISED);
assertThat(ac1.toString()).contains("AutomationComposition(");
@@ -287,9 +239,6 @@ class JpaAutomationCompositionTest {
private JpaAutomationComposition createJpaAutomationCompositionInstance() {
var testAutomationComposition = createAutomationCompositionInstance();
var testJpaAutomationComposition = new JpaAutomationComposition();
- testJpaAutomationComposition.setKey(null);
- testJpaAutomationComposition.fromAuthorative(testAutomationComposition);
- testJpaAutomationComposition.setKey(PfConceptKey.getNullKey());
testJpaAutomationComposition.fromAuthorative(testAutomationComposition);
return testJpaAutomationComposition;
@@ -298,7 +247,7 @@ class JpaAutomationCompositionTest {
private AutomationComposition createAutomationCompositionInstance() {
var testAutomationComposition = new AutomationComposition();
testAutomationComposition.setName("automation-composition");
- testAutomationComposition.setInstanceId(INSTANCE_ID);
+ testAutomationComposition.setInstanceId(UUID.fromString(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 d7d96e9bd..ba1e33c27 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
@@ -24,33 +24,27 @@ 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.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
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;
-import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
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.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.data.domain.Example;
class AutomationCompositionProviderTest {
private static final String OBJECT_IS_NULL = "automationComposition is marked non-null but is null";
- private static final String ID_NAME = "PMSHInstance1";
- private static final String ID_VERSION = "1.0.1";
- private static final String ID_NAME_NOT_EXTST = "not_exist";
-
private static final Coder CODER = new StandardCoder();
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
@@ -100,55 +94,58 @@ class AutomationCompositionProviderTest {
@Test
void testGetAutomationCompositions() throws Exception {
- var automationComposition0 = inputAutomationCompositions.getAutomationCompositionList().get(1);
- var name = automationComposition0.getName();
- var version = automationComposition0.getVersion();
- var automationComposition1 = inputAutomationCompositions.getAutomationCompositionList().get(1);
-
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- when(automationCompositionRepository.getFiltered(eq(JpaAutomationComposition.class), any(), any()))
- .thenReturn(List.of(new JpaAutomationComposition(automationComposition0),
- new JpaAutomationComposition(automationComposition1)));
- when(automationCompositionRepository.findById(automationComposition0.getKey().asIdentifier().asConceptKey()))
- .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition0)));
- when(automationCompositionRepository.getById(automationComposition0.getKey().asIdentifier().asConceptKey()))
- .thenReturn(new JpaAutomationComposition(automationComposition0));
- when(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version))
- .thenReturn(List.of(new JpaAutomationComposition(automationComposition0)));
- when(automationCompositionRepository.findById(automationComposition1.getKey().asIdentifier().asConceptKey()))
- .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1)));
-
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertEquals(1, automationCompositionProvider.getAutomationCompositions(name, version).size());
- var ac = automationCompositionProvider
- .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION))
- .orElse(new AutomationComposition());
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
+ var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(),
+ automationComposition.getName(), automationComposition.getVersion());
+ assertThat(acList).isEmpty();
- ac = automationCompositionProvider.getAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION));
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
+ when(automationCompositionRepository.findAll(Mockito.<Example<JpaAutomationComposition>>any()))
+ .thenReturn(inputAutomationCompositionsJpa);
+ acList = automationCompositionProvider.getAutomationCompositions(automationComposition.getCompositionId(), null,
+ null);
+ assertThat(acList).hasSize(2);
+ }
- when(automationCompositionRepository.getById(any())).thenThrow(EntityNotFoundException.class);
+ @Test
+ void testGetAutomationComposition() {
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertThatThrownBy(() -> automationCompositionProvider
- .getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)))
+ var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ assertThatThrownBy(
+ () -> automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId()))
.hasMessageMatching("AutomationComposition not found");
- assertThat(automationCompositionProvider
- .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty();
+ when(automationCompositionRepository.findById(automationComposition.getInstanceId().toString()))
+ .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
+ var ac = automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId());
+ assertEquals(automationComposition, ac);
}
@Test
- void testGetAutomationComposition() {
+ void testFindAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
- when(automationCompositionRepository.findByInstanceId(automationComposition.getInstanceId().toString()))
+ var acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
+ assertThat(acOpt).isEmpty();
+
+ acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier());
+ assertThat(acOpt).isEmpty();
+
+ when(automationCompositionRepository.findById(automationComposition.getInstanceId().toString()))
.thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
- var ac = automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId());
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), ac);
+ acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
+ assertEquals(automationComposition, acOpt.get());
+
+ when(automationCompositionRepository.findOne(Mockito.<Example<JpaAutomationComposition>>any()))
+ .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
+ acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier());
+ assertEquals(automationComposition, acOpt.get());
}
@Test
@@ -173,7 +170,7 @@ class AutomationCompositionProviderTest {
.hasMessageMatching(".*.failed, automation composition does not exist");
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
- when(automationCompositionRepository.findByInstanceId(automationComposition.getInstanceId().toString()))
+ when(automationCompositionRepository.findById(automationComposition.getInstanceId().toString()))
.thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
var deletedAc =
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java
index 7210a6afd..c441c2fe8 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,28 +22,29 @@ package org.onap.policy.clamp.models.acm.persistence.repository;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
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.dao.PfDao;
-import org.onap.policy.models.dao.PfFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.provider.impl.ModelsProvider;
class FilterRepositoryImplTest {
- private static final String AUTOMATION_COMPOSITION_JSON =
- "src/test/resources/providers/TestAutomationCompositions.json";
+ private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
+ private final List<Participant> inputParticipants = new ArrayList<>();
+ private List<JpaParticipant> jpaParticipantList;
+ private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
private static final Coder CODER = new StandardCoder();
+
private static final AtomicInteger dbNameCounter = new AtomicInteger();
- private static final String originalJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
- private static List<JpaAutomationComposition> jpaAutomationCompositions;
private PfDao pfDao;
@BeforeEach
@@ -58,12 +59,9 @@ class FilterRepositoryImplTest {
parameters.setPersistenceUnit("ToscaConceptTest");
pfDao = ModelsProvider.init(parameters);
- var inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class);
- jpaAutomationCompositions =
- ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
- JpaAutomationComposition::new, "AutomationCompositions");
-
- pfDao.createCollection(jpaAutomationCompositions);
+ inputParticipants.add(CODER.decode(originalJson, Participant.class));
+ jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant");
+ pfDao.createCollection(jpaParticipantList);
}
@Test
@@ -79,31 +77,10 @@ class FilterRepositoryImplTest {
return pfDao;
}
};
- var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, null, null);
- assertThat(result).hasSize(2);
-
- result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class,
- jpaAutomationCompositions.get(0).getName(), null);
+ var result = filterRepositoryImpl.getFiltered(JpaParticipant.class, null, null);
assertThat(result).hasSize(1);
- }
-
- @Test
- void testGetFiltered() {
- var filterRepositoryImpl = new FilterRepositoryImpl() {
- @Override
- protected PfDao getPfDao() {
- return pfDao;
- }
- };
-
- // @formatter:off
- PfFilterParameters filterParams = PfFilterParameters
- .builder()
- .name(jpaAutomationCompositions.get(0).getName())
- .build();
- // @formatter:on
- var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, filterParams);
+ result = filterRepositoryImpl.getFiltered(JpaParticipant.class, jpaParticipantList.get(0).getName(), null);
assertThat(result).hasSize(1);
}
}
diff --git a/models/src/test/resources/providers/TestAutomationCompositions.json b/models/src/test/resources/providers/TestAutomationCompositions.json
index 286759988..bf1d76fbc 100644
--- a/models/src/test/resources/providers/TestAutomationCompositions.json
+++ b/models/src/test/resources/providers/TestAutomationCompositions.json
@@ -7,7 +7,7 @@
"orderedState": "UNINITIALISED",
"elements": {
"709c62b3-8918-41b9-a747-e21eb79c6c20": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c20",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c20",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
"version": "1.2.3"
@@ -21,7 +21,7 @@
"description": "DCAE automation composition element for the PMSH instance 0 automation composition"
},
"709c62b3-8918-41b9-a747-e21eb79c6c21": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c21",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement",
"version": "1.2.3"
@@ -35,7 +35,7 @@
"description": "Monitoring Policy element for the PMSH instance 0 automation composition"
},
"709c62b3-8918-41b9-a747-e21eb79c6c22": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c22",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
"version": "1.2.3"
@@ -49,7 +49,7 @@
"description": "Operational Policy element for the PMSH instance 0 automation composition"
},
"709c62b3-8918-41b9-a747-e21eb79c6c23": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c23",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c23",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement",
"version": "1.2.3"