diff options
Diffstat (limited to 'tosca-controlloop/models/src/test/java/org')
6 files changed, 44 insertions, 45 deletions
diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java index 2c0a45541..c865b76ab 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.UUID; import org.junit.Test; import org.onap.policy.models.base.PfKey; @@ -51,6 +51,7 @@ public class ControlLoopTest { public void testControlLoopLombok() { assertNotNull(new ControlLoop()); ControlLoop cl0 = new ControlLoop(); + cl0.setElements(new LinkedHashMap<>()); assertThat(cl0.toString()).contains("ControlLoop("); assertThat(cl0.hashCode()).isNotZero(); @@ -61,7 +62,7 @@ public class ControlLoopTest { cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); cl1.setDescription("Description"); - cl1.setElements(new ArrayList<>()); + cl1.setElements(new LinkedHashMap<>()); cl1.setName("Name"); cl1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); cl1.setState(ControlLoopState.UNINITIALISED); @@ -75,6 +76,7 @@ public class ControlLoopTest { assertNotEquals(cl1, cl0); ControlLoop cl2 = new ControlLoop(); + cl2.setElements(new LinkedHashMap<>()); // @formatter:off assertThatThrownBy(() -> cl2.setDefinition(null)). isInstanceOf(NullPointerException.class); @@ -87,14 +89,13 @@ public class ControlLoopTest { cl1.setCascadedOrderedState(ControlLoopOrderedState.PASSIVE); assertEquals(ControlLoopOrderedState.PASSIVE, cl1.getOrderedState()); - cl1.getElements().add(new ControlLoopElement()); + cl1.getElements().put(UUID.randomUUID(), new ControlLoopElement()); cl1.setCascadedOrderedState(ControlLoopOrderedState.RUNNING); assertEquals(ControlLoopOrderedState.RUNNING, cl1.getOrderedState()); - assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().get(0).getOrderedState()); + assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().values().iterator().next().getOrderedState()); - assertNull(cl0.getElement(UUID.randomUUID())); - assertNull(cl1.getElement(UUID.randomUUID())); - assertEquals(cl1.getElements().get(0), cl1.getElement(cl1.getElements().get(0).getId())); + assertNull(cl0.getElements().get(UUID.randomUUID())); + assertNull(cl1.getElements().get(UUID.randomUUID())); assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName()); } diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java index c82dcf060..16c302f94 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java @@ -83,7 +83,7 @@ public class JpaClElementStatisticsTest { }).hasMessageMatching("clElementStatistics is marked .*ull but is null"); assertThatThrownBy(() -> new JpaClElementStatistics((JpaClElementStatistics) null)) - .isInstanceOf(NullPointerException.class); + .isInstanceOf(NullPointerException.class); JpaClElementStatistics testJpaClElementStatisticsFa = new JpaClElementStatistics(); testJpaClElementStatisticsFa.setKey(null); diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java index cd105a671..032d655e3 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java @@ -112,11 +112,11 @@ public class JpaControlLoopElementTest { assertThatThrownBy(() -> { new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, null); - }).hasMessageMatching("participantId is marked .*ull but is null"); + }).hasMessageMatching("participantType is marked .*ull but is null"); assertThatThrownBy(() -> { new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, ControlLoopState.UNINITIALISED); - }).hasMessageMatching("participantId is marked .*ull but is null"); + }).hasMessageMatching("participantType is marked .*ull but is null"); assertThatThrownBy(() -> { new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), @@ -240,9 +240,9 @@ public class JpaControlLoopElementTest { testJpaControlLoopElement.setState(ControlLoopState.UNINITIALISED); assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setParticipantId(new PfConceptKey("dummy", "0.0.1")); + testJpaControlLoopElement.setParticipantType(new PfConceptKey("dummy", "0.0.1")); assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setParticipantId(new PfConceptKey("participant", "0.0.1")); + testJpaControlLoopElement.setParticipantType(new PfConceptKey("participantType", "0.0.1")); assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); assertEquals(testJpaControlLoopElement, new JpaControlLoopElement(testJpaControlLoopElement)); @@ -293,7 +293,7 @@ public class JpaControlLoopElementTest { ControlLoopElement controlLoopElement = new ControlLoopElement(); controlLoopElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); controlLoopElement.setDefinition(new ToscaConceptIdentifier("cleDef", "0.0.1")); - controlLoopElement.setParticipantId(new ToscaConceptIdentifier("participant", "0.0.1")); + controlLoopElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1")); return controlLoopElement; } diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java index 7ef7e3276..01062b046 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java @@ -30,7 +30,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.ArrayList; +import java.util.LinkedHashMap; import org.junit.Test; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; @@ -63,7 +63,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, null, null, new ArrayList<>()); + new JpaControlLoop(null, null, null, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -71,7 +71,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new ArrayList<>()); + new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -79,7 +79,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), null, new ArrayList<>()); + new JpaControlLoop(null, new PfConceptKey(), null, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -87,7 +87,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new ArrayList<>()); + new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -95,7 +95,7 @@ public class JpaControlLoopTest { }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, null, new ArrayList<>()); + new JpaControlLoop(new PfConceptKey(), null, null, new LinkedHashMap<>()); }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { @@ -103,7 +103,7 @@ public class JpaControlLoopTest { }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new ArrayList<>()); + new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { @@ -111,7 +111,7 @@ public class JpaControlLoopTest { }).hasMessageMatching("state is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new ArrayList<>()); + new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>()); }).hasMessageMatching("state is marked .*ull but is null"); assertThatThrownBy(() -> { @@ -121,7 +121,7 @@ public class JpaControlLoopTest { assertNotNull(new JpaControlLoop()); assertNotNull(new JpaControlLoop((new PfConceptKey()))); assertNotNull(new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, - new ArrayList<>())); + new LinkedHashMap<>())); } @Test @@ -188,7 +188,7 @@ public class JpaControlLoopTest { JpaControlLoop jpaControlLoopWithElements = new JpaControlLoop(controlLoopsWithElements.getControlLoopList().get(0)); assertEquals(4, jpaControlLoopWithElements.getElements().size()); - assertEquals(14, jpaControlLoopWithElements.getKeys().size()); + assertEquals(18, jpaControlLoopWithElements.getKeys().size()); assertThatCode(() -> jpaControlLoopWithElements.clean()).doesNotThrowAnyException(); assertEquals(controlLoopsWithElements.getControlLoopList().get(0), jpaControlLoopWithElements.toAuthorative()); @@ -258,7 +258,7 @@ public class JpaControlLoopTest { cl1.setDefinition(new PfConceptKey("defName", "0.0.1")); cl1.setDescription("Description"); - cl1.setElements(new ArrayList<>()); + cl1.setElements(new LinkedHashMap<>()); cl1.setKey(new PfConceptKey("participant", "0.0.1")); cl1.setState(ControlLoopState.UNINITIALISED); @@ -289,7 +289,7 @@ public class JpaControlLoopTest { testControlLoop.setName("control-loop"); testControlLoop.setVersion("0.0.1"); testControlLoop.setDefinition(new ToscaConceptIdentifier("controlLoopDefinitionName", "0.0.1")); - testControlLoop.setElements(new ArrayList<>()); + testControlLoop.setElements(new LinkedHashMap<>()); return testControlLoop; } diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java index fb443c82e..96b63a23d 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java @@ -91,11 +91,8 @@ public class ControlLoopProviderTest { ControlLoops createdControlLoops = new ControlLoops(); createdControlLoops .setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList())); - String createdJson = CODER.encode(createdControlLoops, true); - System.err.println(originalJson); - System.out.println(createdJson); - assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + assertEquals(inputControlLoops, createdControlLoops); } @Test diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java index f66c99262..d27d3a22c 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java @@ -57,9 +57,11 @@ public class ParticipantMessageTest { public void testAppliesTo_NullParticipantId() { message = makeMessage(); - assertThatThrownBy(() -> message.appliesTo(null)) - .isInstanceOf(NullPointerException.class); - + assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.6"), null)) + .isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(null, new ToscaConceptIdentifier("id", "1.2.3"))) + .isInstanceOf(NullPointerException.class); } @Test @@ -67,33 +69,32 @@ public class ParticipantMessageTest { message = makeMessage(); // ParticipantId matches - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - assertTrue(message.appliesTo(id)); + assertTrue(message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.6"), + new ToscaConceptIdentifier("id", "1.2.3"))); + assertFalse(message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.6"), + new ToscaConceptIdentifier("id", "1.2.4"))); + assertFalse(message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.7"), + new ToscaConceptIdentifier("id", "1.2.3"))); } @Test public void testAppliesTo_ParticipantIdNoMatch() { message = makeMessage(); - // ParticipantId doesnot match + // ParticipantId does not match ToscaConceptIdentifier id = new ToscaConceptIdentifier(); id.setName("id1111"); id.setVersion("3.2.1"); - assertFalse(message.appliesTo(id)); - message.setParticipantId(null); - assertTrue(message.appliesTo(id)); + assertFalse(message.appliesTo(id, id)); + message.setParticipantType(null); + assertTrue(message.appliesTo(id, id)); } private ParticipantMessage makeMessage() { ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - msg.setControlLoopId(id); - msg.setParticipantId(id); + msg.setParticipantType(new ToscaConceptIdentifier("PType", "4.5.6")); + msg.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); msg.setMessageId(UUID.randomUUID()); msg.setTimestamp(Instant.ofEpochMilli(3000)); |