aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-09-29 18:13:56 +0100
committerlapentafd <francesco.lapenta@est.tech>2021-10-05 09:57:51 +0100
commit2ee602a5070f473f3fce9cb09c124222e5164ae9 (patch)
tree7b69479726fe8508c61a67ab07136a9eb660bb08 /models/src/test/java
parent2e1d9ec7bf612998b7316d2c3395e824b372044e (diff)
Code coverage in clamp/models
Issue-ID: POLICY-3452 Change-Id: I4c24c85edd7a22b05ae81ee7779da13974127164 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'models/src/test/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java34
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java68
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java72
3 files changed, 155 insertions, 19 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java
index 9e285a4f0..ed579febb 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java
@@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -33,24 +34,45 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class ControlLoopElementTest {
@Test
void testControlLoopElement() {
+ var cle0 = new ControlLoopElement();
+ var cle1 = new ControlLoopElement(cle0);
+ assertEquals(cle0, cle1);
- ControlLoopElement cle0 = new ControlLoopElement();
+ cle1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
+ cle1.setDescription("Description");
+ cle1.setId(UUID.randomUUID());
+ cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ cle1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3"));
+ cle1.setState(ControlLoopState.UNINITIALISED);
- ControlLoopElement cle1 = new ControlLoopElement(cle0);
- assertEquals(cle0, cle1);
+ var cle2 = new ControlLoopElement(cle1);
+ assertEquals(cle1, cle2);
+ }
+
+ @Test
+ void testControlLoopState() {
+ var cle0 = new ControlLoopElement();
+
+ assertTrue(
+ cle0.getOrderedState()
+ .equalsControlLoopState(ControlLoopState.UNINITIALISED));
+
+ assertTrue(
+ cle0.getOrderedState().asState()
+ .equalsControlLoopOrderedState(ControlLoopOrderedState.UNINITIALISED));
}
@Test
void testControlLoopElementLombok() {
assertNotNull(new ControlLoopElement());
- ControlLoopElement cle0 = new ControlLoopElement();
+ var cle0 = new ControlLoopElement();
assertThat(cle0.toString()).contains("ControlLoopElement(");
assertThat(cle0.hashCode()).isNotZero();
assertEquals(true, cle0.equals(cle0));
assertEquals(false, cle0.equals(null));
- ControlLoopElement cle1 = new ControlLoopElement();
+ var cle1 = new ControlLoopElement();
cle1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
cle1.setDescription("Description");
@@ -66,7 +88,7 @@ class ControlLoopElementTest {
assertNotEquals(cle1, cle0);
- ControlLoopElement cle2 = new ControlLoopElement();
+ var cle2 = new ControlLoopElement();
// @formatter:off
assertThatThrownBy(() -> cle2.setDefinition(null)). isInstanceOf(NullPointerException.class);
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
index 243d8dcd5..51a4fc7ae 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
@@ -27,7 +27,9 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.time.Instant;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.models.base.PfKey;
@@ -36,12 +38,12 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class ControlLoopTest {
@Test
void testControlLoop() {
- ControlLoop cl0 = new ControlLoop();
+ var cl0 = new ControlLoop();
cl0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3"));
assertEquals("dfName", cl0.getType());
assertEquals("1.2.3", cl0.getTypeVersion());
- ControlLoop cl1 = new ControlLoop(cl0);
+ var cl1 = new ControlLoop(cl0);
assertEquals(cl0, cl1);
assertEquals(0, cl0.compareTo(cl1));
@@ -50,7 +52,7 @@ class ControlLoopTest {
@Test
void testControlLoopLombok() {
assertNotNull(new ControlLoop());
- ControlLoop cl0 = new ControlLoop();
+ var cl0 = new ControlLoop();
cl0.setElements(new LinkedHashMap<>());
assertThat(cl0.toString()).contains("ControlLoop(");
@@ -58,7 +60,7 @@ class ControlLoopTest {
assertEquals(true, cl0.equals(cl0));
assertEquals(false, cl0.equals(null));
- ControlLoop cl1 = new ControlLoop();
+ var cl1 = new ControlLoop();
cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
cl1.setDescription("Description");
@@ -75,7 +77,7 @@ class ControlLoopTest {
assertNotEquals(cl1, cl0);
- ControlLoop cl2 = new ControlLoop();
+ var cl2 = new ControlLoop();
cl2.setElements(new LinkedHashMap<>());
// @formatter:off
@@ -98,5 +100,61 @@ class ControlLoopTest {
assertNull(cl1.getElements().get(UUID.randomUUID()));
assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName());
+
+ }
+
+ @Test
+ void testControlLoopElementStatisticsList() {
+ var cl = new ControlLoop();
+ List<ClElementStatistics> emptylist = cl.getControlLoopElementStatisticsList(cl);
+ assertNull(emptylist);
+
+ var cl1 = getControlLoopTest();
+ List<ClElementStatistics> list = cl1.getControlLoopElementStatisticsList(cl1);
+ assertNotNull(list);
+ assertEquals(2, list.size());
+ assertEquals(ControlLoopState.UNINITIALISED, list.get(0).getControlLoopState());
+ }
+
+ private ControlLoop getControlLoopTest() {
+ var cl = new ControlLoop();
+ cl.setDefinition(new ToscaConceptIdentifier("defName", "1.2.3"));
+ cl.setDescription("Description");
+ cl.setElements(new LinkedHashMap<>());
+ cl.setName("Name");
+ cl.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ cl.setState(ControlLoopState.UNINITIALISED);
+ cl.setVersion("0.0.1");
+
+ var uuid = UUID.randomUUID();
+ var id = new ToscaConceptIdentifier(
+ "org.onap.policy.controlloop.PolicyControlLoopParticipant", "1.0.1");
+ var clElement = getControlLoopElementTest(uuid, id);
+
+ var uuid2 = UUID.randomUUID();
+ var id2 = new ToscaConceptIdentifier(
+ "org.onap.policy.controlloop.PolicyControlLoopParticipantIntermediary", "0.0.1");
+ var clElement2 = getControlLoopElementTest(uuid2, id2);
+
+ cl.getElements().put(uuid, clElement);
+ cl.getElements().put(uuid2, clElement2);
+ return cl;
+ }
+
+ private ControlLoopElement getControlLoopElementTest(UUID uuid, ToscaConceptIdentifier id) {
+ var clElement = new ControlLoopElement();
+ clElement.setId(uuid);
+ clElement.setParticipantId(id);
+ clElement.setDefinition(id);
+ clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ clElement.setClElementStatistics(clElementStatistics);
+
+ return clElement;
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java
index 8aec568b2..9805edb86 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provide
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.List;
@@ -35,9 +36,12 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
class ControlLoopProviderTest {
@@ -46,7 +50,9 @@ class ControlLoopProviderTest {
private static final Coder CODER = new StandardCoder();
private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json";
private static final String UPDATE_CL_JSON = "src/test/resources/providers/UpdateControlLoops.json";
+ private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml";
+ private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static AtomicInteger dbNameCounter = new AtomicInteger();
private PolicyModelsProviderParameters parameters;
@@ -85,7 +91,7 @@ class ControlLoopProviderTest {
controlLoopProvider.createControlLoops(null);
}).hasMessageMatching(LIST_IS_NULL);
- ControlLoops createdControlLoops = new ControlLoops();
+ var createdControlLoops = new ControlLoops();
createdControlLoops
.setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList()));
@@ -102,11 +108,11 @@ class ControlLoopProviderTest {
assertThat(getResponse).isEmpty();
controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList());
- String name = inputControlLoops.getControlLoopList().get(0).getName();
- String version = inputControlLoops.getControlLoopList().get(0).getVersion();
+ var name = inputControlLoops.getControlLoopList().get(0).getName();
+ var version = inputControlLoops.getControlLoopList().get(0).getVersion();
assertEquals(1, controlLoopProvider.getControlLoops(name, version).size());
- ControlLoop cl = new ControlLoop();
+ var cl = new ControlLoop();
cl = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier("PMSHInstance1", "1.0.1"));
assertEquals(inputControlLoops.getControlLoopList().get(1), cl);
@@ -127,10 +133,10 @@ class ControlLoopProviderTest {
controlLoopProvider.updateControlLoops(null);
}).hasMessageMatching("controlLoops is marked .*ull but is null");
- ControlLoops existingControlLoops = new ControlLoops();
+ var existingControlLoops = new ControlLoops();
existingControlLoops
.setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList()));
- ControlLoop updateResponse = new ControlLoop();
+ var updateResponse = new ControlLoop();
updateResponse = controlLoopProvider.updateControlLoop(updateControlLoops.getControlLoopList().get(0));
assertEquals(ControlLoopOrderedState.RUNNING, updateResponse.getOrderedState());
@@ -144,11 +150,61 @@ class ControlLoopProviderTest {
ControlLoop deletedCl;
List<ControlLoop> clList = controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList());
- String name = inputControlLoops.getControlLoopList().get(0).getName();
- String version = inputControlLoops.getControlLoopList().get(0).getVersion();
+ var name = inputControlLoops.getControlLoopList().get(0).getName();
+ var version = inputControlLoops.getControlLoopList().get(0).getVersion();
deletedCl = controlLoopProvider.deleteControlLoop(name, version);
assertEquals(clList.get(0), deletedCl);
+ }
+
+ @Test
+ void testDeleteAllInstanceProperties() throws Exception {
+ var toscaServiceTemplate = testControlLoopRead();
+ controlLoopProvider.deleteInstanceProperties(
+ controlLoopProvider.saveInstanceProperties(toscaServiceTemplate),
+ controlLoopProvider.getNodeTemplates(null, null));
+ assertThat(controlLoopProvider.getControlLoops(null, null)).isEmpty();
+ }
+
+ @Test
+ void testSaveAndDeleteInstanceProperties() throws Exception {
+ var toscaServiceTest = testControlLoopRead();
+ controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList());
+
+ controlLoopProvider.saveInstanceProperties(toscaServiceTest);
+ assertThat(controlLoopProvider.getNodeTemplates(
+ "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "2.3.1")).isNotEmpty();
+
+ controlLoopProvider.deleteInstanceProperties(
+ controlLoopProvider.saveInstanceProperties(toscaServiceTest),
+ controlLoopProvider.getNodeTemplates(
+ "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "2.3.1"));
+
+ assertThat(controlLoopProvider.getNodeTemplates(
+ "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "2.3.1")).isEmpty();
+ }
+
+ @Test
+ void testGetNodeTemplates() throws Exception {
+ //Getting all nodes
+ List<ToscaNodeTemplate> listNodes = controlLoopProvider.getNodeTemplates(null, null);
+ assertNotNull(listNodes);
+
+ assertThatThrownBy(() -> {
+ controlLoopProvider.getFilteredNodeTemplates(null);
+ }).hasMessageMatching("filter is marked non-null but is null");
+ }
+
+ private static ToscaServiceTemplate testControlLoopRead() {
+ return testControlLoopYamlSerialization(TOSCA_TEMPLATE_YAML);
+ }
+ private static ToscaServiceTemplate testControlLoopYamlSerialization(String controlLoopFilePath) {
+ String controlLoopString = ResourceUtils.getResourceAsString(controlLoopFilePath);
+ ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class);
+ return serviceTemplate;
}
}