diff options
Diffstat (limited to 'models/src/test')
7 files changed, 129 insertions, 76 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java index 7f595fbbb..d7d7e4327 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java @@ -24,38 +24,40 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; -import java.time.Instant; +import java.util.Map; import java.util.UUID; +import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -/** - * Test the copy constructor and other methods. - */ -class ParticipantHealthCheckTest { +class ControlLoopAckTest { @Test void testCopyConstructor() { - assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new ControlLoopAck((ControlLoopAck) null)) + .isInstanceOf(NullPointerException.class); - ParticipantHealthCheck orig = new ParticipantHealthCheck(); + final ControlLoopAck orig = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_UPDATE); // verify with null values assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantHealthCheck(orig).toString())); + removeVariableFields(new ControlLoopAck(orig).toString())); // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); orig.setControlLoopId(id); orig.setParticipantId(id); - orig.setMessageId(UUID.randomUUID()); - orig.setState(ParticipantState.ACTIVE); - orig.setTimestamp(Instant.ofEpochMilli(3000)); + orig.setParticipantType(id); + + Pair<Boolean, String> clElementResult = Pair.of(true, "ControlLoopElement result"); + final Map<UUID, Pair<Boolean, String>> controlLoopResultMap = Map.of(UUID.randomUUID(), clElementResult); + orig.setControlLoopResultMap(controlLoopResultMap); + + orig.setResponseTo(UUID.randomUUID()); + orig.setResult(true); + orig.setMessage("Successfully processed ControlLoopUpdate message"); assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantHealthCheck(orig).toString())); + removeVariableFields(new ControlLoopAck(orig).toString())); } } diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java index c37268ac0..dd6a814a7 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java @@ -28,34 +28,34 @@ import java.time.Instant; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** * Test the copy constructor and other methods. */ -class ParticipantControlLoopStateChangeTest { +class ControlLoopStateChangeTest { @Test void testCopyConstructor() { - assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new ControlLoopStateChange(null)).isInstanceOf(NullPointerException.class); - ParticipantControlLoopStateChange orig = new ParticipantControlLoopStateChange(); + ControlLoopStateChange orig = new ControlLoopStateChange(); // verify with null values assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantControlLoopStateChange(orig).toString())); + removeVariableFields(new ControlLoopStateChange(orig).toString())); // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); orig.setControlLoopId(id); orig.setParticipantId(id); orig.setMessageId(UUID.randomUUID()); orig.setOrderedState(ControlLoopOrderedState.RUNNING); + orig.setCurrentState(ControlLoopState.PASSIVE); orig.setTimestamp(Instant.ofEpochMilli(3000)); assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantControlLoopStateChange(orig).toString())); + removeVariableFields(new ControlLoopStateChange(orig).toString())); } } diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java index 5d87095ba..0ac4f5331 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java @@ -22,50 +22,59 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; import java.time.Instant; +import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * Test the copy constructor. */ -class ParticipantControlLoopUpdateTest { +class ControlLoopUpdateTest { @Test void testCopyConstructor() { - assertThatThrownBy(() -> new ParticipantControlLoopUpdate(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new ControlLoopUpdate(null)).isInstanceOf(NullPointerException.class); - ParticipantControlLoopUpdate orig = new ParticipantControlLoopUpdate(); + ControlLoopUpdate orig = new ControlLoopUpdate(); // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); orig.setControlLoopId(id); - orig.setParticipantId(id); + orig.setParticipantId(null); orig.setMessageId(UUID.randomUUID()); orig.setTimestamp(Instant.ofEpochMilli(3000)); + ControlLoopElement clElement = new ControlLoopElement(); + clElement.setId(UUID.randomUUID()); + clElement.setDefinition(id); + clElement.setDescription("Description"); + clElement.setOrderedState(ControlLoopOrderedState.PASSIVE); + clElement.setState(ControlLoopState.PASSIVE); + clElement.setParticipantId(id); + clElement.setParticipantType(id); + ControlLoop controlLoop = new ControlLoop(); controlLoop.setName("controlLoop"); - ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); - toscaServiceTemplate.setName("serviceTemplate"); - toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); - toscaServiceTemplate.setDescription("Description of serviceTemplate"); - toscaServiceTemplate.setVersion("1.2.3"); - orig.setControlLoopDefinition(toscaServiceTemplate); + Map<UUID, ControlLoopElement> elements = Map.of(clElement.getId(), clElement); + controlLoop.setElements(elements); orig.setControlLoop(controlLoop); - ParticipantControlLoopUpdate other = new ParticipantControlLoopUpdate(orig); + Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue"); + clElement.setCommonPropertiesMap(commonPropertiesMap); - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + Map<UUID, ControlLoopElement> controlLoopElementMap = Map.of(UUID.randomUUID(), clElement); + Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>> + participantUpdateMap = Map.of(id, controlLoopElementMap); + orig.setParticipantUpdateMap(participantUpdateMap); - // ensure list and items are not the same object - assertNotSame(other.getControlLoop(), controlLoop); - assertNotSame(other.getControlLoopDefinition(), toscaServiceTemplate); + ControlLoopUpdate other = new ControlLoopUpdate(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); } } diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java index 1a56a3979..e67fbc143 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java @@ -46,6 +46,8 @@ class ParticipantPojosTest { pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class)); pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class)); pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAck.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAckTest.class)); // @formatter:off final Validator validator = ValidatorBuilder diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java index 6c73c6d3e..b391aa2cf 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java @@ -27,35 +27,26 @@ import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participan import java.time.Instant; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** - * Test the copy constructor and the other methods. + * Test the copy constructor. */ -class ParticipantStateChangeTest { - +class ParticipantStatusReqTest { @Test void testCopyConstructor() { - assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class); - - ParticipantStateChange orig = new ParticipantStateChange(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantStateChange(orig).toString())); + assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class); + ParticipantStatusReq orig = new ParticipantStatusReq(); // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setControlLoopId(id); + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); orig.setParticipantId(id); + orig.setControlLoopId(null); + orig.setParticipantType(null); orig.setMessageId(UUID.randomUUID()); - orig.setState(ParticipantState.ACTIVE); orig.setTimestamp(Instant.ofEpochMilli(3000)); - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantStateChange(orig).toString())); + ParticipantStatusReq other = new ParticipantStatusReq(orig); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); } } diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java index 706e58b91..05cfdd78b 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java @@ -25,10 +25,20 @@ import static org.junit.Assert.assertEquals; import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; import java.time.Instant; +import java.util.List; +import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; class ParticipantStatusTest { @@ -43,20 +53,64 @@ class ParticipantStatusTest { removeVariableFields(new ParticipantStatus(orig).toString())); // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); orig.setControlLoopId(id); orig.setParticipantId(id); + orig.setParticipantType(id); orig.setMessageId(UUID.randomUUID()); orig.setState(ParticipantState.ACTIVE); + orig.setHealthStatus(ParticipantHealthStatus.HEALTHY); orig.setTimestamp(Instant.ofEpochMilli(3000)); - final ParticipantResponseDetails resp = new ParticipantResponseDetails(); - resp.setResponseMessage("my-response"); - orig.setResponse(resp); + ControlLoopInfo clInfo = getControlLoopInfo(id); + orig.setControlLoopInfoMap(Map.of(id, clInfo)); + + ControlLoopElementDefinition clDefinition = getClElementDefinition(); + Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition); + Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>> + participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap); + orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap); assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new ParticipantStatus(orig).toString())); } + + private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) { + ControlLoopInfo clInfo = new ControlLoopInfo(); + clInfo.setState(ControlLoopState.PASSIVE2RUNNING); + + ControlLoopStatistics clStatistics = new ControlLoopStatistics(); + clStatistics.setControlLoopId(id); + clStatistics.setAverageExecutionTime(12345); + clStatistics.setEventCount(12345); + clStatistics.setLastEnterTime(12345); + clStatistics.setLastExecutionTime(12345); + clStatistics.setLastStart(12345); + clStatistics.setTimeStamp(Instant.ofEpochMilli(3000)); + clStatistics.setUpTime(12345); + ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList(); + ClElementStatistics clElementStatistics = new ClElementStatistics(); + clElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + clElementStatistics.setTimeStamp(Instant.now()); + clElementStatisticsList.setClElementStatistics(List.of(clElementStatistics)); + clStatistics.setClElementStatisticsList(clElementStatisticsList); + + clInfo.setControlLoopStatistics(clStatistics); + return clInfo; + } + + private ControlLoopElementDefinition getClElementDefinition() { + ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); + toscaServiceTemplate.setName("serviceTemplate"); + toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); + toscaServiceTemplate.setDescription("Description of serviceTemplate"); + toscaServiceTemplate.setVersion("1.2.3"); + + ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); + clDefinition.setId(UUID.randomUUID()); + clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate); + Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue"); + clDefinition.setCommonPropertiesMap(commonPropertiesMap); + return clDefinition; + } } diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java index 4f8b42b3a..094431233 100644 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java +++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java @@ -22,11 +22,9 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; import java.time.Instant; -import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -62,16 +60,13 @@ class ParticipantUpdateTest { ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); clDefinition.setId(UUID.randomUUID()); clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate); - Map<String, String> commonPropertiesMap = new LinkedHashMap<>(); - commonPropertiesMap.put("Prop1", "PropValue"); + Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue"); clDefinition.setCommonPropertiesMap(commonPropertiesMap); - Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>(); - controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition); + Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition); Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>> - participantDefinitionUpdateMap = new LinkedHashMap<>(); - participantDefinitionUpdateMap.put(id, controlLoopElementDefinitionMap); + participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap); orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap); ParticipantUpdate other = new ParticipantUpdate(orig); |