aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models/src/test/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java67
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java62
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java81
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java102
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java65
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java84
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java28
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java28
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java28
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java28
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java28
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java189
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java300
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java296
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java193
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java253
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java62
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java115
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java160
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java154
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java109
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java83
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java48
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java58
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java61
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java71
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java61
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java103
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java35
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java61
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java61
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java62
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java59
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java60
34 files changed, 3255 insertions, 0 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java
new file mode 100644
index 000000000..0addc25ad
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ClElementStatisticsTest {
+ @Test
+ public void testClElementStatisticsLombok() {
+ assertNotNull(new ClElementStatistics());
+ ClElementStatistics cles0 = new ClElementStatistics();
+
+ assertThat(cles0.toString()).contains("ClElementStatistics(");
+ assertThat(cles0.hashCode()).isNotZero();
+ assertEquals(true, cles0.equals(cles0));
+ assertEquals(false, cles0.equals(null));
+
+
+ ClElementStatistics cles1 = new ClElementStatistics();
+ cles1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1"));
+ cles1.setTimeStamp(Instant.now());
+
+ assertThat(cles1.toString()).contains("ClElementStatistics(");
+ assertEquals(false, cles1.hashCode() == 0);
+ assertEquals(false, cles1.equals(cles0));
+ assertEquals(false, cles1.equals(null));
+
+ assertNotEquals(cles1, cles0);
+
+ ClElementStatistics cles2 = new ClElementStatistics();
+ cles2.setId(UUID.randomUUID());
+
+ // @formatter:off
+ assertThatThrownBy(() -> cles2.setParticipantId(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cles2.setTimeStamp(null)).isInstanceOf(NullPointerException.class);
+ // @formatter:on
+
+ assertNotEquals(cles2, cles0);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java
new file mode 100644
index 000000000..908c91417
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ToStringTester;
+
+/**
+ * Class to perform unit tests of all pojos.
+ */
+public class ControlLoopConceptPojosTest {
+
+ @Test
+ public void testPojos() {
+ List<PojoClass> pojoClasses =
+ PojoClassFactory.getPojoClasses(ControlLoopConceptPojosTest.class.getPackageName());
+
+ // @formatter:off
+ final Validator validator = ValidatorBuilder
+ .create()
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new EqualsAndHashCodeMatchRule())
+ .with(new NoPublicFieldsExceptStaticFinalRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .with(new ToStringTester())
+ .build();
+
+ validator.validate(pojoClasses);
+ // @formatter:on
+ }
+}
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
new file mode 100644
index 000000000..2264f6dc2
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ControlLoopElementTest {
+ @Test
+ public void testControlLoopElement() {
+
+ ControlLoopElement cle0 = new ControlLoopElement();
+
+ ControlLoopElement cle1 = new ControlLoopElement(cle0);
+ assertEquals(cle0, cle1);
+ }
+
+ @Test
+ public void testControlLoopElementLombok() {
+ assertNotNull(new ControlLoopElement());
+ ControlLoopElement 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();
+
+ 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);
+
+ assertThat(cle1.toString()).contains("ControlLoopElement(");
+ assertEquals(false, cle1.hashCode() == 0);
+ assertEquals(false, cle1.equals(cle0));
+ assertEquals(false, cle1.equals(null));
+
+ assertNotEquals(cle1, cle0);
+
+ ControlLoopElement cle2 = new ControlLoopElement();
+
+ // @formatter:off
+ assertThatThrownBy(() -> cle2.setDefinition(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cle2.setId(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cle2.setOrderedState(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cle2.setParticipantId(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cle2.setState(null)). isInstanceOf(NullPointerException.class);
+ // @formatter:on
+
+ assertNotEquals(cle2, cle0);
+ }
+}
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
new file mode 100644
index 000000000..c865b76ab
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.LinkedHashMap;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ControlLoopTest {
+ @Test
+ public void testControlLoop() {
+ ControlLoop 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);
+ assertEquals(cl0, cl1);
+
+ assertEquals(0, cl0.compareTo(cl1));
+ }
+
+ @Test
+ public void testControlLoopLombok() {
+ assertNotNull(new ControlLoop());
+ ControlLoop cl0 = new ControlLoop();
+ cl0.setElements(new LinkedHashMap<>());
+
+ assertThat(cl0.toString()).contains("ControlLoop(");
+ assertThat(cl0.hashCode()).isNotZero();
+ assertEquals(true, cl0.equals(cl0));
+ assertEquals(false, cl0.equals(null));
+
+ ControlLoop cl1 = new ControlLoop();
+
+ cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
+ cl1.setDescription("Description");
+ cl1.setElements(new LinkedHashMap<>());
+ cl1.setName("Name");
+ cl1.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ cl1.setState(ControlLoopState.UNINITIALISED);
+ cl1.setVersion("0.0.1");
+
+ assertThat(cl1.toString()).contains("ControlLoop(");
+ assertEquals(false, cl1.hashCode() == 0);
+ assertEquals(false, cl1.equals(cl0));
+ assertEquals(false, cl1.equals(null));
+
+ assertNotEquals(cl1, cl0);
+
+ ControlLoop cl2 = new ControlLoop();
+ cl2.setElements(new LinkedHashMap<>());
+
+ // @formatter:off
+ assertThatThrownBy(() -> cl2.setDefinition(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cl2.setOrderedState(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cl2.setState(null)). isInstanceOf(NullPointerException.class);
+ // @formatter:on
+
+ assertEquals(cl2, cl0);
+
+ cl1.setCascadedOrderedState(ControlLoopOrderedState.PASSIVE);
+ assertEquals(ControlLoopOrderedState.PASSIVE, cl1.getOrderedState());
+
+ cl1.getElements().put(UUID.randomUUID(), new ControlLoopElement());
+ cl1.setCascadedOrderedState(ControlLoopOrderedState.RUNNING);
+ assertEquals(ControlLoopOrderedState.RUNNING, cl1.getOrderedState());
+ assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().values().iterator().next().getOrderedState());
+
+ assertNull(cl0.getElements().get(UUID.randomUUID()));
+ assertNull(cl1.getElements().get(UUID.randomUUID()));
+
+ assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName());
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java
new file mode 100644
index 000000000..54eaca00e
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.time.Instant;
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ParticipantStatisticsTest {
+ @Test
+ public void testParticipantStatisticsLombok() {
+ assertNotNull(new ParticipantStatistics());
+ ParticipantStatistics ps0 = new ParticipantStatistics();
+
+ assertThat(ps0.toString()).contains("ParticipantStatistics(");
+ assertThat(ps0.hashCode()).isNotZero();
+ assertEquals(true, ps0.equals(ps0));
+ assertEquals(false, ps0.equals(null));
+
+
+ ParticipantStatistics ps1 = new ParticipantStatistics();
+ ps1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1"));
+ ps1.setTimeStamp(Instant.now());
+
+ assertThat(ps1.toString()).contains("ParticipantStatistics(");
+ assertEquals(false, ps1.hashCode() == 0);
+ assertEquals(false, ps1.equals(ps0));
+ assertEquals(false, ps1.equals(null));
+
+ assertNotEquals(ps1, ps0);
+
+ ParticipantStatistics ps2 = new ParticipantStatistics();
+
+ // @formatter:off
+ assertThatThrownBy(() -> ps2.setParticipantId(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> ps2.setTimeStamp(null)). isInstanceOf(NullPointerException.class);
+ // @formatter:on
+
+ assertEquals(ps2, ps0);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java
new file mode 100644
index 000000000..1eb80db09
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ParticipantTest {
+ @Test
+ public void testParticipant() {
+
+ Participant p0 = new Participant();
+ p0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3"));
+ assertEquals("dfName", p0.getType());
+ assertEquals("1.2.3", p0.getTypeVersion());
+
+ Participant p1 = new Participant(p0);
+ assertEquals(p0, p1);
+
+ assertEquals(0, p0.compareTo(p1));
+ }
+
+ @Test
+ public void testParticipantLombok() {
+ assertNotNull(new Participant());
+ Participant p0 = new Participant();
+
+ assertThat(p0.toString()).contains("Participant(");
+ assertThat(p0.hashCode()).isNotZero();
+ assertEquals(true, p0.equals(p0));
+ assertEquals(false, p0.equals(null));
+
+
+ Participant p1 = new Participant();
+
+ p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
+ p1.setDescription("Description");
+ p1.setHealthStatus(ParticipantHealthStatus.HEALTHY);
+ p1.setName("Name");
+ p1.setParticipantState(ParticipantState.ACTIVE);
+ p1.setVersion("0.0.1");
+
+ assertThat(p1.toString()).contains("Participant(");
+ assertEquals(false, p1.hashCode() == 0);
+ assertEquals(false, p1.equals(p0));
+ assertEquals(false, p1.equals(null));
+
+ assertNotEquals(p1, p0);
+
+ Participant p2 = new Participant();
+
+ // @formatter:off
+ assertThatThrownBy(() -> p2.setDefinition(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> p2.setHealthStatus(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
+ // @formatter:on
+
+ assertEquals(p2, p0);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java
new file mode 100644
index 000000000..b90ccba5b
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+/**
+ * Test class for {@link JpaClElementStatistics} comparisons.
+ */
+public class DummyJpaClElementStatisticsChild extends JpaClElementStatistics {
+ private static final long serialVersionUID = -5101743610779424064L;
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java
new file mode 100644
index 000000000..c4eb364d3
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+/**
+ * Test class for {@link JpaControlLoop} comparisons.
+ */
+public class DummyJpaControlLoopChild extends JpaControlLoop {
+ private static final long serialVersionUID = -5101743610779424064L;
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java
new file mode 100644
index 000000000..2082ff41c
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+/**
+ * Test class for {@link JpaControlLoopElement} comparisons.
+ */
+public class DummyJpaControlLoopElementChild extends JpaControlLoopElement {
+ private static final long serialVersionUID = -5101743610779424064L;
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java
new file mode 100644
index 000000000..e6bc92efb
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+/**
+ * Test class for {@link JpaParticipant} comparisons.
+ */
+public class DummyJpaParticipantChild extends JpaParticipant {
+ private static final long serialVersionUID = -5101743610779424064L;
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java
new file mode 100644
index 000000000..74dd40034
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+/**
+ * Test class for {@link JpaParticipantStatistics} comparisons.
+ */
+public class DummyJpaParticipantStatisticsChild extends JpaParticipantStatistics {
+ private static final long serialVersionUID = -5101743610779424064L;
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java
new file mode 100644
index 000000000..16c302f94
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceTimestampKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Test the {@link JpaClElementStatistics} class.
+ */
+public class JpaClElementStatisticsTest {
+
+ private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+
+ @Test
+ public void testJpaClElementStatisticsConstructor() {
+ assertThatThrownBy(() -> {
+ new JpaClElementStatistics((JpaClElementStatistics) null);
+ }).hasMessageMatching("copyConcept is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaClElementStatistics((PfReferenceTimestampKey) null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaClElementStatistics(null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaClElementStatistics(null, new PfConceptKey());
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaClElementStatistics(new PfReferenceTimestampKey(), null);
+ }).hasMessageMatching("participantId is marked .*ull but is null");
+
+ assertNotNull(new JpaClElementStatistics());
+ assertNotNull(new JpaClElementStatistics((new PfReferenceTimestampKey())));
+ assertNotNull(new JpaClElementStatistics(new PfReferenceTimestampKey(), new PfConceptKey()));
+ }
+
+ @Test
+ public void testJpaClElementStatistics() {
+ JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance();
+
+ ClElementStatistics cles = createClElementStatisticsInstance();
+ assertEquals(cles, testJpaClElementStatistics.toAuthorative());
+
+ assertThatThrownBy(() -> {
+ testJpaClElementStatistics.fromAuthorative(null);
+ }).hasMessageMatching("clElementStatistics is marked .*ull but is null");
+
+ assertThatThrownBy(() -> new JpaClElementStatistics((JpaClElementStatistics) null))
+ .isInstanceOf(NullPointerException.class);
+
+ JpaClElementStatistics testJpaClElementStatisticsFa = new JpaClElementStatistics();
+ testJpaClElementStatisticsFa.setKey(null);
+ testJpaClElementStatisticsFa.fromAuthorative(cles);
+ assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa);
+ testJpaClElementStatisticsFa.setKey(PfReferenceTimestampKey.getNullKey());
+ testJpaClElementStatisticsFa.fromAuthorative(cles);
+ assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa);
+ testJpaClElementStatisticsFa.setKey(new PfReferenceTimestampKey("elementName", "0.0.1",
+ "a95757ba-b34a-4049-a2a8-46773abcbe5e", Instant.ofEpochSecond(123456L)));
+ testJpaClElementStatisticsFa.fromAuthorative(cles);
+ assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa);
+
+ testJpaClElementStatisticsFa = new JpaClElementStatistics(cles);
+ assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa);
+
+ assertEquals(1, testJpaClElementStatistics.getKeys().size());
+
+ assertEquals("elementName", testJpaClElementStatistics.getKey().getReferenceKey().getParentKeyName());
+
+ testJpaClElementStatistics.clean();
+ assertEquals("elementName", testJpaClElementStatistics.getKey().getReferenceKey().getParentKeyName());
+
+ JpaClElementStatistics testJpaClElementStatistics2 = new JpaClElementStatistics(testJpaClElementStatistics);
+ assertEquals(testJpaClElementStatistics, testJpaClElementStatistics2);
+ }
+
+ @Test
+ public void testJpaClElementStatisticsValidation() {
+ JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance();
+
+ assertThatThrownBy(() -> {
+ testJpaClElementStatistics.validate(null);
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
+
+ assertTrue(testJpaClElementStatistics.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaClElementStatisticsCompareTo() {
+ JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance();
+
+ JpaClElementStatistics otherJpaClElementStatistics = new JpaClElementStatistics(testJpaClElementStatistics);
+ assertEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics));
+ assertEquals(-1, testJpaClElementStatistics.compareTo(null));
+ assertEquals(0, testJpaClElementStatistics.compareTo(testJpaClElementStatistics));
+ assertNotEquals(0, testJpaClElementStatistics.compareTo(new DummyJpaClElementStatisticsChild()));
+
+ testJpaClElementStatistics.setState(ControlLoopState.PASSIVE);
+ assertNotEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics));
+ testJpaClElementStatistics.setState(ControlLoopState.UNINITIALISED);
+ assertEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics));
+
+ assertEquals(testJpaClElementStatistics, new JpaClElementStatistics(testJpaClElementStatistics));
+ }
+
+ @Test
+ public void testJpaClElementStatisticsLombok() {
+ assertNotNull(new Participant());
+ JpaClElementStatistics cles0 = new JpaClElementStatistics();
+
+ assertThat(cles0.toString()).contains("JpaClElementStatistics(");
+ assertThat(cles0.hashCode()).isNotZero();
+ assertEquals(true, cles0.equals(cles0));
+ assertEquals(false, cles0.equals(null));
+
+
+ JpaClElementStatistics cles11 = new JpaClElementStatistics();
+
+ cles11.setState(ControlLoopState.UNINITIALISED);
+
+ assertThat(cles11.toString()).contains("JpaClElementStatistics(");
+ assertEquals(false, cles11.hashCode() == 0);
+ assertEquals(false, cles11.equals(cles0));
+ assertEquals(false, cles11.equals(null));
+
+ assertNotEquals(cles11, cles0);
+
+ JpaClElementStatistics cles2 = new JpaClElementStatistics();
+ assertEquals(cles2, cles0);
+ }
+
+ private JpaClElementStatistics createJpaClElementStatisticsInstance() {
+ ClElementStatistics testCles = createClElementStatisticsInstance();
+ JpaClElementStatistics testJpaClElementStatistics = new JpaClElementStatistics();
+ testJpaClElementStatistics.setKey(null);
+ testJpaClElementStatistics.fromAuthorative(testCles);
+ testJpaClElementStatistics.setKey(PfReferenceTimestampKey.getNullKey());
+ testJpaClElementStatistics.fromAuthorative(testCles);
+
+ return testJpaClElementStatistics;
+ }
+
+ private ClElementStatistics createClElementStatisticsInstance() {
+ ClElementStatistics clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(new ToscaConceptIdentifier("elementName", "0.0.1"));
+ clElementStatistics.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ clElementStatistics.setTimeStamp(Instant.ofEpochSecond(123456L));
+ clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED);
+
+ return clElementStatistics;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java
new file mode 100644
index 000000000..032d655e3
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java
@@ -0,0 +1,300 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.UUID;
+import org.junit.Test;
+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.clamp.controlloop.models.controlloop.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 JpaControlLoopElement} class.
+ */
+public class JpaControlLoopElementTest {
+
+ private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+
+ @Test
+ public void testJpaControlLoopElementConstructor() {
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement((JpaControlLoopElement) null);
+ }).hasMessageMatching("copyConcept is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement((PfReferenceKey) null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, null, null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, null, null, ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, null, new PfConceptKey("participant", "0.0.1"), null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, null, new PfConceptKey("participant", "0.0.1"),
+ ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, new PfConceptKey(), null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, new PfConceptKey(), null, ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"),
+ ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), null, null, null);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), null, null, ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), null);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"),
+ ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, null);
+ }).hasMessageMatching("participantType is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, ControlLoopState.UNINITIALISED);
+ }).hasMessageMatching("participantType is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(),
+ new PfConceptKey("participant", "0.0.1"), null);
+ }).hasMessageMatching("state is marked .*ull but is null");
+
+ assertNotNull(new JpaControlLoopElement());
+ assertNotNull(new JpaControlLoopElement((new PfReferenceKey())));
+ assertNotNull(new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(),
+ new PfConceptKey("participant", "0.0.1"), ControlLoopState.UNINITIALISED));
+ }
+
+ @Test
+ public void testJpaControlLoopElement() {
+ JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance();
+
+ ControlLoopElement cle = createControlLoopElementInstance();
+ assertEquals(cle, testJpaControlLoopElement.toAuthorative());
+
+ assertThatThrownBy(() -> {
+ testJpaControlLoopElement.fromAuthorative(null);
+ }).hasMessageMatching("element is marked .*ull but is null");
+
+ assertThatThrownBy(() -> new JpaControlLoopElement((JpaControlLoopElement) null))
+ .isInstanceOf(NullPointerException.class);
+
+ JpaControlLoopElement testJpaControlLoopElementFa = new JpaControlLoopElement();
+ testJpaControlLoopElementFa.setKey(null);
+ testJpaControlLoopElementFa.fromAuthorative(cle);
+ assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa);
+ testJpaControlLoopElementFa.setKey(PfReferenceKey.getNullKey());
+ testJpaControlLoopElementFa.fromAuthorative(cle);
+ assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa);
+ testJpaControlLoopElementFa.setKey(new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION,
+ "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ testJpaControlLoopElementFa.fromAuthorative(cle);
+ assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa);
+
+ assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", testJpaControlLoopElement.getKey().getLocalName());
+ assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
+ new JpaControlLoopElement(createControlLoopElementInstance()).getKey().getLocalName());
+ assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
+ ((PfReferenceKey) new JpaControlLoopElement(createControlLoopElementInstance()).getKeys().get(0))
+ .getLocalName());
+
+ testJpaControlLoopElement.clean();
+ assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", testJpaControlLoopElement.getKey().getLocalName());
+
+ testJpaControlLoopElement.setDescription(" A Message ");
+ testJpaControlLoopElement.clean();
+ assertEquals("A Message", testJpaControlLoopElement.getDescription());
+
+ JpaControlLoopElement testJpaControlLoopElement2 = new JpaControlLoopElement(testJpaControlLoopElement);
+ assertEquals(testJpaControlLoopElement, testJpaControlLoopElement2);
+ }
+
+ @Test
+ public void testJpaControlLoopElementOrderedState() throws CoderException {
+ ControlLoopElement testControlLoopElement = createControlLoopElementInstance();
+ JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance();
+
+ testJpaControlLoopElement.setOrderedState(null);
+ assertEquals(testControlLoopElement, testJpaControlLoopElement.toAuthorative());
+ testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ ControlLoopElement noOrderedStateCle = new StandardCoder().decode(
+ new File("src/test/resources/json/ControlLoopElementNoOrderedState.json"), ControlLoopElement.class);
+
+ JpaControlLoopElement noOrderedStateJpaCle = new JpaControlLoopElement(noOrderedStateCle);
+ assertNull(noOrderedStateJpaCle.getOrderedState());
+ noOrderedStateCle.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ noOrderedStateJpaCle = new JpaControlLoopElement(noOrderedStateCle);
+ assertEquals(testJpaControlLoopElement, noOrderedStateJpaCle);
+ }
+
+ @Test
+ public void testJpaControlLoopElementValidation() {
+ JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance();
+
+ assertThatThrownBy(() -> {
+ testJpaControlLoopElement.validate(null);
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
+
+ assertTrue(testJpaControlLoopElement.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaControlLoopElementCompareTo() {
+ JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance();
+
+ JpaControlLoopElement otherJpaControlLoopElement = new JpaControlLoopElement(testJpaControlLoopElement);
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ assertEquals(-1, testJpaControlLoopElement.compareTo(null));
+ assertEquals(0, testJpaControlLoopElement.compareTo(testJpaControlLoopElement));
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(new DummyJpaControlLoopElementChild()));
+
+ testJpaControlLoopElement
+ .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ testJpaControlLoopElement.setKey(new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION,
+ "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+
+ testJpaControlLoopElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ testJpaControlLoopElement.setDefinition(new PfConceptKey("cleDef", "0.0.1"));
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+
+ testJpaControlLoopElement.setDescription("Description");
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ testJpaControlLoopElement.setDescription(null);
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+
+ testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+
+ testJpaControlLoopElement.setState(ControlLoopState.PASSIVE);
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ testJpaControlLoopElement.setState(ControlLoopState.UNINITIALISED);
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+
+ testJpaControlLoopElement.setParticipantType(new PfConceptKey("dummy", "0.0.1"));
+ assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+ testJpaControlLoopElement.setParticipantType(new PfConceptKey("participantType", "0.0.1"));
+ assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement));
+
+ assertEquals(testJpaControlLoopElement, new JpaControlLoopElement(testJpaControlLoopElement));
+ }
+
+ @Test
+ public void testJpaControlLoopElementLombok() {
+ assertNotNull(new Participant());
+ JpaControlLoopElement cle0 = new JpaControlLoopElement();
+
+ assertThat(cle0.toString()).contains("JpaControlLoopElement(");
+ assertThat(cle0.hashCode()).isNotZero();
+ assertEquals(true, cle0.equals(cle0));
+ assertEquals(false, cle0.equals(null));
+
+
+ JpaControlLoopElement cle1 = new JpaControlLoopElement();
+
+ cle1.setDefinition(new PfConceptKey("defName", "0.0.1"));
+ cle1.setDescription("Description");
+ cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ cle1.setState(ControlLoopState.UNINITIALISED);
+ cle1.setParticipantId(new PfConceptKey("participant", "0.0.1"));
+
+ assertThat(cle1.toString()).contains("ControlLoopElement(");
+ assertEquals(false, cle1.hashCode() == 0);
+ assertEquals(false, cle1.equals(cle0));
+ assertEquals(false, cle1.equals(null));
+
+ assertNotEquals(cle1, cle0);
+
+ JpaControlLoopElement cle2 = new JpaControlLoopElement();
+ assertEquals(cle2, cle0);
+ }
+
+ private JpaControlLoopElement createJpaControlLoopElementInstance() {
+ ControlLoopElement testCle = createControlLoopElementInstance();
+ JpaControlLoopElement testJpaControlLoopElement = new JpaControlLoopElement();
+ testJpaControlLoopElement.setKey(null);
+ testJpaControlLoopElement.fromAuthorative(testCle);
+ testJpaControlLoopElement.setKey(PfReferenceKey.getNullKey());
+ testJpaControlLoopElement.fromAuthorative(testCle);
+
+ return testJpaControlLoopElement;
+ }
+
+ private ControlLoopElement createControlLoopElementInstance() {
+ ControlLoopElement controlLoopElement = new ControlLoopElement();
+ controlLoopElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ controlLoopElement.setDefinition(new ToscaConceptIdentifier("cleDef", "0.0.1"));
+ controlLoopElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1"));
+
+ return controlLoopElement;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java
new file mode 100644
index 000000000..01062b046
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java
@@ -0,0 +1,296 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.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.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+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;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+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.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Test the {@link JpaControlLoopTest} class.
+ */
+public class JpaControlLoopTest {
+
+ private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+
+ @Test
+ public void testJpaControlLoopConstructor() {
+ assertThatThrownBy(() -> {
+ new JpaControlLoop((JpaControlLoop) null);
+ }).hasMessageMatching("copyConcept is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop((PfConceptKey) null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, null, null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, null, null, new LinkedHashMap<>());
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>());
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, new PfConceptKey(), null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, new PfConceptKey(), null, new LinkedHashMap<>());
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new LinkedHashMap<>());
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), null, null, null);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), null, null, new LinkedHashMap<>());
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, null);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>());
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, null);
+ }).hasMessageMatching("state is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>());
+ }).hasMessageMatching("state is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, null);
+ }).hasMessageMatching("elements is marked .*ull but is null");
+
+ assertNotNull(new JpaControlLoop());
+ assertNotNull(new JpaControlLoop((new PfConceptKey())));
+ assertNotNull(new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED,
+ new LinkedHashMap<>()));
+ }
+
+ @Test
+ public void testJpaControlLoop() {
+ JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance();
+
+ ControlLoop participant = createControlLoopInstance();
+ assertEquals(participant, testJpaControlLoop.toAuthorative());
+
+ assertThatThrownBy(() -> {
+ testJpaControlLoop.fromAuthorative(null);
+ }).hasMessageMatching("controlLoop is marked .*ull but is null");
+
+ assertThatThrownBy(() -> new JpaControlLoop((JpaControlLoop) null)).isInstanceOf(NullPointerException.class);
+
+ JpaControlLoop testJpaControlLoopFa = new JpaControlLoop();
+ testJpaControlLoopFa.setKey(null);
+ testJpaControlLoopFa.fromAuthorative(participant);
+ assertEquals(testJpaControlLoop, testJpaControlLoopFa);
+ testJpaControlLoopFa.setKey(PfConceptKey.getNullKey());
+ testJpaControlLoopFa.fromAuthorative(participant);
+ assertEquals(testJpaControlLoop, testJpaControlLoopFa);
+ testJpaControlLoopFa.setKey(new PfConceptKey("control-loop", "0.0.1"));
+ testJpaControlLoopFa.fromAuthorative(participant);
+ assertEquals(testJpaControlLoop, testJpaControlLoopFa);
+
+ assertEquals("control-loop", testJpaControlLoop.getKey().getName());
+ assertEquals("control-loop", new JpaControlLoop(createControlLoopInstance()).getKey().getName());
+ assertEquals("control-loop",
+ ((PfConceptKey) new JpaControlLoop(createControlLoopInstance()).getKeys().get(0)).getName());
+
+ testJpaControlLoop.clean();
+ assertEquals("control-loop", testJpaControlLoop.getKey().getName());
+
+ testJpaControlLoop.setDescription(" A Message ");
+ testJpaControlLoop.clean();
+ assertEquals("A Message", testJpaControlLoop.getDescription());
+
+ JpaControlLoop testJpaControlLoop2 = new JpaControlLoop(testJpaControlLoop);
+ assertEquals(testJpaControlLoop, testJpaControlLoop2);
+ }
+
+ @Test
+ public void testJpaControlLoopElementOrderedState() throws CoderException {
+ ControlLoop testControlLoop = createControlLoopInstance();
+ JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance();
+
+ testJpaControlLoop.setOrderedState(null);
+ assertEquals(testControlLoop, testJpaControlLoop.toAuthorative());
+ testJpaControlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ ControlLoop noOrderedStateCl = new StandardCoder()
+ .decode(new File("src/test/resources/json/ControlLoopNoOrderedState.json"), ControlLoop.class);
+
+ JpaControlLoop noOrderedStateJpaCl = new JpaControlLoop(noOrderedStateCl);
+ assertNull(noOrderedStateJpaCl.getOrderedState());
+ noOrderedStateCl.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ noOrderedStateJpaCl = new JpaControlLoop(noOrderedStateCl);
+ assertEquals(testJpaControlLoop, noOrderedStateJpaCl);
+
+ ControlLoops controlLoopsWithElements = new StandardCoder()
+ .decode(new File("src/test/resources/providers/TestControlLoops.json"), ControlLoops.class);
+
+ JpaControlLoop jpaControlLoopWithElements =
+ new JpaControlLoop(controlLoopsWithElements.getControlLoopList().get(0));
+ assertEquals(4, jpaControlLoopWithElements.getElements().size());
+ assertEquals(18, jpaControlLoopWithElements.getKeys().size());
+ assertThatCode(() -> jpaControlLoopWithElements.clean()).doesNotThrowAnyException();
+
+ assertEquals(controlLoopsWithElements.getControlLoopList().get(0), jpaControlLoopWithElements.toAuthorative());
+ }
+
+ @Test
+ public void testJpaControlLoopValidation() {
+ JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance();
+
+ assertThatThrownBy(() -> {
+ testJpaControlLoop.validate(null);
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
+
+ assertTrue(testJpaControlLoop.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaControlLoopCompareTo() {
+ JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance();
+
+ JpaControlLoop otherJpaControlLoop = new JpaControlLoop(testJpaControlLoop);
+ assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+ assertEquals(-1, testJpaControlLoop.compareTo(null));
+ assertEquals(0, testJpaControlLoop.compareTo(testJpaControlLoop));
+ assertNotEquals(0, testJpaControlLoop.compareTo(new DummyJpaControlLoopChild()));
+
+ testJpaControlLoop.setKey(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+ testJpaControlLoop.setKey(new PfConceptKey("control-loop", "0.0.1"));
+ assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+
+ testJpaControlLoop.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+ testJpaControlLoop.setDefinition(new PfConceptKey("controlLoopDefinitionName", "0.0.1"));
+ assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+
+ testJpaControlLoop.setState(ControlLoopState.PASSIVE);
+ assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+ testJpaControlLoop.setState(ControlLoopState.UNINITIALISED);
+ assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+
+ testJpaControlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+ testJpaControlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+
+ testJpaControlLoop.setDescription("A description");
+ assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+ testJpaControlLoop.setDescription(null);
+ assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop));
+
+ assertEquals(testJpaControlLoop, new JpaControlLoop(testJpaControlLoop));
+ }
+
+ @Test
+ public void testJpaControlLoopLombok() {
+ assertNotNull(new ControlLoop());
+ JpaControlLoop cl0 = new JpaControlLoop();
+
+ assertThat(cl0.toString()).contains("JpaControlLoop(");
+ assertThat(cl0.hashCode()).isNotZero();
+ assertEquals(true, cl0.equals(cl0));
+ assertEquals(false, cl0.equals(null));
+
+
+ JpaControlLoop cl1 = new JpaControlLoop();
+
+ cl1.setDefinition(new PfConceptKey("defName", "0.0.1"));
+ cl1.setDescription("Description");
+ cl1.setElements(new LinkedHashMap<>());
+ cl1.setKey(new PfConceptKey("participant", "0.0.1"));
+ cl1.setState(ControlLoopState.UNINITIALISED);
+
+ assertThat(cl1.toString()).contains("ControlLoop(");
+ assertEquals(false, cl1.hashCode() == 0);
+ assertEquals(false, cl1.equals(cl0));
+ assertEquals(false, cl1.equals(null));
+
+ assertNotEquals(cl1, cl0);
+
+ JpaControlLoop cl2 = new JpaControlLoop();
+ assertEquals(cl2, cl0);
+ }
+
+ private JpaControlLoop createJpaControlLoopInstance() {
+ ControlLoop testControlLoop = createControlLoopInstance();
+ JpaControlLoop testJpaControlLoop = new JpaControlLoop();
+ testJpaControlLoop.setKey(null);
+ testJpaControlLoop.fromAuthorative(testControlLoop);
+ testJpaControlLoop.setKey(PfConceptKey.getNullKey());
+ testJpaControlLoop.fromAuthorative(testControlLoop);
+
+ return testJpaControlLoop;
+ }
+
+ private ControlLoop createControlLoopInstance() {
+ ControlLoop testControlLoop = new ControlLoop();
+ testControlLoop.setName("control-loop");
+ testControlLoop.setVersion("0.0.1");
+ testControlLoop.setDefinition(new ToscaConceptIdentifier("controlLoopDefinitionName", "0.0.1"));
+ testControlLoop.setElements(new LinkedHashMap<>());
+
+ return testControlLoop;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java
new file mode 100644
index 000000000..7eedd245b
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java
@@ -0,0 +1,193 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Instant;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfTimestampKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Test the {@link JpaParticipantStatistics} class.
+ */
+public class JpaParticipantStatisticsTest {
+
+ private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+
+ @Test
+ public void testJpaParticipantStatisticsConstructor() {
+ assertThatThrownBy(() -> {
+ new JpaParticipantStatistics((JpaParticipantStatistics) null);
+ }).hasMessageMatching("copyConcept is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipantStatistics((PfTimestampKey) null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipantStatistics(null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipantStatistics(null, new PfConceptKey());
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipantStatistics(new PfTimestampKey(), null);
+ }).hasMessageMatching("participantId is marked .*ull but is null");
+
+ assertNotNull(new JpaParticipantStatistics());
+ assertNotNull(new JpaParticipantStatistics((new PfTimestampKey())));
+ assertNotNull(new JpaParticipantStatistics(new PfTimestampKey(), new PfConceptKey()));
+ }
+
+ @Test
+ public void testJpaParticipantStatistics() {
+ JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance();
+
+ ParticipantStatistics cles = createParticipantStatisticsInstance();
+ assertEquals(cles, testJpaParticipantStatistics.toAuthorative());
+
+ assertThatThrownBy(() -> {
+ testJpaParticipantStatistics.fromAuthorative(null);
+ }).hasMessageMatching("participantStatistics is marked .*ull but is null");
+
+ assertThatThrownBy(() -> new JpaParticipantStatistics((JpaParticipantStatistics) null))
+ .isInstanceOf(NullPointerException.class);
+
+ JpaParticipantStatistics testJpaParticipantStatisticsFa = new JpaParticipantStatistics();
+ testJpaParticipantStatisticsFa.setKey(null);
+ testJpaParticipantStatisticsFa.fromAuthorative(cles);
+ assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa);
+ testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey());
+ testJpaParticipantStatisticsFa.fromAuthorative(cles);
+ assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa);
+ testJpaParticipantStatisticsFa
+ .setKey(new PfTimestampKey("participantName", "0.0.1", Instant.ofEpochMilli(123456L)));
+ testJpaParticipantStatisticsFa.fromAuthorative(cles);
+ assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa);
+
+ testJpaParticipantStatisticsFa = new JpaParticipantStatistics(cles);
+ assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa);
+
+ assertEquals(2, testJpaParticipantStatistics.getKeys().size());
+
+ assertEquals("participantName", testJpaParticipantStatistics.getKey().getName());
+
+ testJpaParticipantStatistics.clean();
+ assertEquals("participantName", testJpaParticipantStatistics.getKey().getName());
+
+ JpaParticipantStatistics testJpaParticipantStatistics2 =
+ new JpaParticipantStatistics(testJpaParticipantStatistics);
+ assertEquals(testJpaParticipantStatistics, testJpaParticipantStatistics2);
+ }
+
+ @Test
+ public void testJpaParticipantStatisticsValidation() {
+ JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance();
+
+ assertThatThrownBy(() -> {
+ testJpaParticipantStatistics.validate(null);
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
+
+ BeanValidationResult validationResult = testJpaParticipantStatistics.validate("");
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testJpaParticipantStatisticsConmpareTo() {
+ JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance();
+
+ JpaParticipantStatistics otherJpaParticipantStatistics =
+ new JpaParticipantStatistics(testJpaParticipantStatistics);
+ assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics));
+ assertEquals(-1, testJpaParticipantStatistics.compareTo(null));
+ assertEquals(0, testJpaParticipantStatistics.compareTo(testJpaParticipantStatistics));
+ assertNotEquals(0, testJpaParticipantStatistics.compareTo(new DummyJpaParticipantStatisticsChild()));
+
+ testJpaParticipantStatistics.setState(ParticipantState.UNKNOWN);
+ assertNotEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics));
+ testJpaParticipantStatistics.setState(ParticipantState.PASSIVE);
+ assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics));
+
+ assertEquals(testJpaParticipantStatistics, new JpaParticipantStatistics(testJpaParticipantStatistics));
+ }
+
+ @Test
+ public void testJpaParticipantStatisticsLombok() {
+ assertNotNull(new Participant());
+ JpaParticipantStatistics ps0 = new JpaParticipantStatistics();
+
+ assertThat(ps0.toString()).contains("JpaParticipantStatistics(");
+ assertThat(ps0.hashCode()).isNotZero();
+ assertEquals(true, ps0.equals(ps0));
+ assertEquals(false, ps0.equals(null));
+
+
+ JpaParticipantStatistics ps1 = new JpaParticipantStatistics();
+
+ ps1.setState(ParticipantState.UNKNOWN);
+
+ assertThat(ps1.toString()).contains("JpaParticipantStatistics(");
+ assertEquals(false, ps1.hashCode() == 0);
+ assertEquals(false, ps1.equals(ps0));
+ assertEquals(false, ps1.equals(null));
+
+ assertNotEquals(ps1, ps0);
+
+ JpaParticipantStatistics ps2 = new JpaParticipantStatistics();
+ assertEquals(ps2, ps0);
+ }
+
+ private JpaParticipantStatistics createJpaParticipantStatisticsInstance() {
+ ParticipantStatistics testCles = createParticipantStatisticsInstance();
+ JpaParticipantStatistics testJpaParticipantStatistics = new JpaParticipantStatistics();
+ testJpaParticipantStatistics.setKey(null);
+ testJpaParticipantStatistics.fromAuthorative(testCles);
+ testJpaParticipantStatistics.setKey(PfTimestampKey.getNullKey());
+ testJpaParticipantStatistics.fromAuthorative(testCles);
+
+ return testJpaParticipantStatistics;
+ }
+
+ private ParticipantStatistics createParticipantStatisticsInstance() {
+ ParticipantStatistics participantStatistics = new ParticipantStatistics();
+ participantStatistics.setParticipantId(new ToscaConceptIdentifier("participantName", "0.0.1"));
+ participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L));
+ participantStatistics.setState(ParticipantState.PASSIVE);
+ participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY);
+
+ return participantStatistics;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java
new file mode 100644
index 000000000..5c96df6f1
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java
@@ -0,0 +1,253 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+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.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Test the {@link JpaParticiant} class.
+ */
+public class JpaParticipantTest {
+
+ private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+
+ @Test
+ public void testJpaParticipantConstructor() {
+ assertThatThrownBy(() -> {
+ new JpaParticipant((JpaParticipant) null);
+ }).hasMessageMatching("copyConcept is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant((PfConceptKey) null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, null, null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, null, null, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, null, ParticipantState.ACTIVE, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, new PfConceptKey(), null, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, null);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching(NULL_KEY_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), null, null, null);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), null, null, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, null);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching("definition is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, null);
+ }).hasMessageMatching("participantState is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY);
+ }).hasMessageMatching("participantState is marked .*ull but is null");
+
+ assertThatThrownBy(() -> {
+ new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, null);
+ }).hasMessageMatching("healthStatus is marked .*ull but is null");
+
+ assertNotNull(new JpaParticipant());
+ assertNotNull(new JpaParticipant((new PfConceptKey())));
+ assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE,
+ ParticipantHealthStatus.HEALTHY));
+ }
+
+ @Test
+ public void testJpaParticipant() {
+ JpaParticipant testJpaParticipant = createJpaParticipantInstance();
+
+ Participant participant = createParticipantInstance();
+ assertEquals(participant, testJpaParticipant.toAuthorative());
+
+ assertThatThrownBy(() -> {
+ testJpaParticipant.fromAuthorative(null);
+ }).hasMessageMatching("participant is marked .*ull but is null");
+
+ assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)).isInstanceOf(NullPointerException.class);
+
+ JpaParticipant testJpaParticipantFa = new JpaParticipant();
+ testJpaParticipantFa.setKey(null);
+ testJpaParticipantFa.fromAuthorative(participant);
+ assertEquals(testJpaParticipant, testJpaParticipantFa);
+ testJpaParticipantFa.setKey(PfConceptKey.getNullKey());
+ testJpaParticipantFa.fromAuthorative(participant);
+ assertEquals(testJpaParticipant, testJpaParticipantFa);
+ testJpaParticipantFa.setKey(new PfConceptKey("participant", "0.0.1"));
+ testJpaParticipantFa.fromAuthorative(participant);
+ assertEquals(testJpaParticipant, testJpaParticipantFa);
+
+ assertEquals("participant", testJpaParticipant.getKey().getName());
+ assertEquals("participant", new JpaParticipant(createParticipantInstance()).getKey().getName());
+ assertEquals("participant",
+ ((PfConceptKey) new JpaParticipant(createParticipantInstance()).getKeys().get(0)).getName());
+
+ testJpaParticipant.clean();
+ assertEquals("participant", testJpaParticipant.getKey().getName());
+
+ testJpaParticipant.setDescription(" A Message ");
+ testJpaParticipant.clean();
+ assertEquals("A Message", testJpaParticipant.getDescription());
+
+ JpaParticipant testJpaParticipant2 = new JpaParticipant(testJpaParticipant);
+ assertEquals(testJpaParticipant, testJpaParticipant2);
+ }
+
+ @Test
+ public void testJpaParticipantValidation() {
+ JpaParticipant testJpaParticipant = createJpaParticipantInstance();
+
+ assertThatThrownBy(() -> {
+ testJpaParticipant.validate(null);
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
+
+ assertTrue(testJpaParticipant.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaParticipantCompareTo() {
+ JpaParticipant testJpaParticipant = createJpaParticipantInstance();
+
+ JpaParticipant otherJpaParticipant = new JpaParticipant(testJpaParticipant);
+ assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+ assertEquals(-1, testJpaParticipant.compareTo(null));
+ assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant));
+ assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild()));
+
+ testJpaParticipant.setKey(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+ testJpaParticipant.setKey(new PfConceptKey("participant", "0.0.1"));
+ assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+
+ testJpaParticipant.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+ testJpaParticipant.setDefinition(new PfConceptKey("participantDefinitionName", "0.0.1"));
+ assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+
+ testJpaParticipant.setParticipantState(ParticipantState.PASSIVE);
+ assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+ testJpaParticipant.setParticipantState(ParticipantState.UNKNOWN);
+ assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+
+ testJpaParticipant.setHealthStatus(ParticipantHealthStatus.NOT_HEALTHY);
+ assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+ testJpaParticipant.setHealthStatus(ParticipantHealthStatus.UNKNOWN);
+ assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
+
+ assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
+ }
+
+ @Test
+ public void testJpaParticipantLombok() {
+ assertNotNull(new Participant());
+ JpaParticipant p0 = new JpaParticipant();
+
+ assertThat(p0.toString()).contains("JpaParticipant(");
+ assertThat(p0.hashCode()).isNotZero();
+ assertEquals(true, p0.equals(p0));
+ assertEquals(false, p0.equals(null));
+
+
+ JpaParticipant p1 = new JpaParticipant();
+
+ p1.setDefinition(new PfConceptKey("defName", "0.0.1"));
+ p1.setDescription("Description");
+ p1.setHealthStatus(ParticipantHealthStatus.HEALTHY);
+ p1.setKey(new PfConceptKey("participant", "0.0.1"));
+ p1.setParticipantState(ParticipantState.ACTIVE);
+
+ assertThat(p1.toString()).contains("Participant(");
+ assertEquals(false, p1.hashCode() == 0);
+ assertEquals(false, p1.equals(p0));
+ assertEquals(false, p1.equals(null));
+
+ assertNotEquals(p1, p0);
+
+ JpaParticipant p2 = new JpaParticipant();
+ assertEquals(p2, p0);
+ }
+
+ private JpaParticipant createJpaParticipantInstance() {
+ Participant testParticipant = createParticipantInstance();
+ JpaParticipant testJpaParticipant = new JpaParticipant();
+ testJpaParticipant.setKey(null);
+ testJpaParticipant.fromAuthorative(testParticipant);
+ testJpaParticipant.setKey(PfConceptKey.getNullKey());
+ testJpaParticipant.fromAuthorative(testParticipant);
+
+ return testJpaParticipant;
+ }
+
+ private Participant createParticipantInstance() {
+ Participant testParticipant = new Participant();
+ testParticipant.setName("participant");
+ testParticipant.setVersion("0.0.1");
+ testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1"));
+
+ return testParticipant;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java
new file mode 100644
index 000000000..9e21b216b
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ToStringTester;
+
+/**
+ * Class to perform unit tests of all pojos.
+ */
+public class PojosTest {
+
+ @Test
+ public void testPojos() {
+ List<PojoClass> pojoClasses =
+ PojoClassFactory.getPojoClasses(PojosTest.class.getPackageName());
+
+ // @formatter:off
+ final Validator validator = ValidatorBuilder
+ .create()
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new EqualsAndHashCodeMatchRule())
+ .with(new NoPublicFieldsExceptStaticFinalRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .with(new ToStringTester())
+ .build();
+
+ validator.validate(pojoClasses);
+ // @formatter:on
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java
new file mode 100644
index 000000000..f5d094f9e
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.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.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.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ClElementStatisticsProviderTest {
+ private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
+ private static final Coder CODER = new StandardCoder();
+ private static final String CL_ELEMENT_STATS_JSON =
+ "src/test/resources/providers/TestClElementStatistics.json";
+
+ private static AtomicInteger dbNameCounter = new AtomicInteger();
+
+ private PolicyModelsProviderParameters parameters;
+ private ClElementStatisticsProvider clElementStatisticsProvider;
+ private ClElementStatisticsList inputClElementStats;
+ private String originalJson = ResourceUtils.getResourceAsString(CL_ELEMENT_STATS_JSON);
+
+ /**
+ * Set up test ClElement statistics provider.
+ */
+ @Before
+ public void setupDao() throws Exception {
+
+ parameters = new PolicyModelsProviderParameters();
+ parameters.setDatabaseDriver("org.h2.Driver");
+ parameters.setName("PolicyProviderParameterGroup");
+ parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
+ parameters.setDatabaseUrl("jdbc:h2:mem:clElementTestDb" + dbNameCounter.getAndIncrement());
+ parameters.setDatabaseUser("policy");
+ parameters.setDatabasePassword("P01icY");
+ parameters.setPersistenceUnit("ToscaConceptTest");
+
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters);
+ inputClElementStats = CODER.decode(originalJson, ClElementStatisticsList.class);
+ }
+
+ @After
+ public void teardown() {
+ clElementStatisticsProvider.close();
+ }
+
+ @Test
+ public void testClElementStatisticsCreate() throws Exception {
+ assertThatThrownBy(() -> {
+ clElementStatisticsProvider.createClElementStatistics(null);
+ }).hasMessageMatching(LIST_IS_NULL);
+
+ ClElementStatisticsList createdClElementStats = new ClElementStatisticsList();
+ createdClElementStats.setClElementStatistics(clElementStatisticsProvider
+ .createClElementStatistics(inputClElementStats.getClElementStatistics()));
+
+ assertEquals(inputClElementStats.toString().replaceAll("\\s+", ""),
+ createdClElementStats.toString().replaceAll("\\s+", ""));
+ }
+
+ @Test
+ public void testGetClElementStatistics() throws Exception {
+
+ List<ClElementStatistics> getResponse;
+
+ //Return empty list when no data present in db
+ getResponse = clElementStatisticsProvider.getClElementStatistics(null, null, null,
+ null);
+ assertThat(getResponse).isEmpty();
+
+ clElementStatisticsProvider.createClElementStatistics(inputClElementStats
+ .getClElementStatistics());
+ ToscaConceptIdentifier identifier = inputClElementStats.getClElementStatistics().get(0)
+ .getParticipantId();
+ Instant instant = inputClElementStats.getClElementStatistics().get(0).getTimeStamp();
+ String id = inputClElementStats.getClElementStatistics().get(0).getId().toString();
+ assertEquals(1, clElementStatisticsProvider.getClElementStatistics(identifier.getName(),
+ identifier.getVersion(), id, instant).size());
+
+ assertEquals(1, clElementStatisticsProvider.getFilteredClElementStatistics("name2",
+ "1.0.1", null, null, null,
+ "DESC", 1).size());
+ }
+}
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
new file mode 100644
index 000000000..96b63a23d
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java
@@ -0,0 +1,160 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider;
+
+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.assertNull;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+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.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.ToscaTypedEntityFilter;
+
+public class ControlLoopProviderTest {
+
+ private static final String LIST_IS_NULL = "controlLoops is marked .*ull but is null";
+ 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 AtomicInteger dbNameCounter = new AtomicInteger();
+
+ private PolicyModelsProviderParameters parameters;
+ private ControlLoopProvider controlLoopProvider;
+ private ControlLoops inputControlLoops;
+ private ControlLoops updateControlLoops;
+ private String originalJson = ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON);
+ private String updateClJson = ResourceUtils.getResourceAsString(UPDATE_CL_JSON);
+
+ /**
+ * Set up test control loop provider.
+ */
+ @Before
+ public void setupDao() throws Exception {
+
+ parameters = new PolicyModelsProviderParameters();
+ parameters.setDatabaseDriver("org.h2.Driver");
+ parameters.setName("PolicyProviderParameterGroup");
+ parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
+ parameters.setDatabaseUrl("jdbc:h2:mem:controlLoopProviderTestDb" + dbNameCounter.getAndDecrement());
+ parameters.setDatabaseUser("policy");
+ parameters.setDatabasePassword("P01icY");
+ parameters.setPersistenceUnit("ToscaConceptTest");
+
+ controlLoopProvider = new ControlLoopProvider(parameters);
+
+ inputControlLoops = CODER.decode(originalJson, ControlLoops.class);
+ updateControlLoops = CODER.decode(updateClJson, ControlLoops.class);
+ }
+
+ @After
+ public void teardown() {
+ controlLoopProvider.close();
+ }
+
+ @Test
+ public void testControlLoopCreate() throws Exception {
+ assertThatThrownBy(() -> {
+ controlLoopProvider.createControlLoops(null);
+ }).hasMessageMatching(LIST_IS_NULL);
+
+ ControlLoops createdControlLoops = new ControlLoops();
+ createdControlLoops
+ .setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList()));
+
+ assertEquals(inputControlLoops, createdControlLoops);
+ }
+
+ @Test
+ public void testGetControlLoops() throws Exception {
+
+ List<ControlLoop> getResponse;
+
+ // Return empty list when no data present in db
+ getResponse = controlLoopProvider.getControlLoops(null, null);
+ assertThat(getResponse).isEmpty();
+
+ controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList());
+ String name = inputControlLoops.getControlLoopList().get(0).getName();
+ String version = inputControlLoops.getControlLoopList().get(0).getVersion();
+ assertEquals(1, controlLoopProvider.getControlLoops(name, version).size());
+
+ ControlLoop cl = new ControlLoop();
+ cl = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier("PMSHInstance1", "1.0.1"));
+ assertEquals(inputControlLoops.getControlLoopList().get(1), cl);
+
+ assertNull(controlLoopProvider.getControlLoop(new ToscaConceptIdentifier("invalid_name", "1.0.1")));
+
+ assertThatThrownBy(() -> {
+ controlLoopProvider.getFilteredControlLoops(null);
+ }).hasMessageMatching("filter is marked .*ull but is null");
+
+ final ToscaTypedEntityFilter<ControlLoop> filter = ToscaTypedEntityFilter.<ControlLoop>builder()
+ .type("org.onap.domain.pmsh.PMSHControlLoopDefinition").build();
+ assertEquals(2, controlLoopProvider.getFilteredControlLoops(filter).size());
+ }
+
+
+ @Test
+ public void testUpdateControlLoops() throws Exception {
+ assertThatThrownBy(() -> {
+ controlLoopProvider.updateControlLoops(null);
+ }).hasMessageMatching("controlLoops is marked .*ull but is null");
+
+ ControlLoops existingControlLoops = new ControlLoops();
+ existingControlLoops
+ .setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList()));
+ ControlLoop updateResponse = new ControlLoop();
+ updateResponse = controlLoopProvider.updateControlLoop(updateControlLoops.getControlLoopList().get(0));
+
+ assertEquals(ControlLoopOrderedState.RUNNING, updateResponse.getOrderedState());
+ }
+
+ @Test
+ public void testDeleteControlLoop() throws Exception {
+ assertThatThrownBy(() -> {
+ controlLoopProvider.deleteControlLoop("Invalid_name", "1.0.1");
+ }).hasMessageMatching(".*.failed, control loop does not exist");
+
+ ControlLoop deletedCl;
+ List<ControlLoop> clList = controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList());
+ String name = inputControlLoops.getControlLoopList().get(0).getName();
+ String version = inputControlLoops.getControlLoopList().get(0).getVersion();
+
+ deletedCl = controlLoopProvider.deleteControlLoop(name, version);
+ assertEquals(clList.get(0), deletedCl);
+
+ }
+}
+
+
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java
new file mode 100644
index 000000000..7a86a49dc
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java
@@ -0,0 +1,154 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+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.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
+
+public class ParticipantProviderTest {
+
+ private static final Coder CODER = new StandardCoder();
+ private static final String PARTICIPANT_JSON =
+ "src/test/resources/providers/TestParticipant.json";
+ private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
+
+ private static AtomicInteger dbNameCounter = new AtomicInteger();
+
+ private PolicyModelsProviderParameters parameters;
+ private ParticipantProvider participantProvider;
+ private List<Participant> inputParticipants = new ArrayList<>();
+ private Participant updateParticipants;
+ private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
+
+ /**
+ * Set up test Participant provider.
+ */
+ @Before
+ public void setupDao() throws Exception {
+
+ parameters = new PolicyModelsProviderParameters();
+ parameters.setDatabaseDriver("org.h2.Driver");
+ parameters.setName("PolicyProviderParameterGroup");
+ parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
+ parameters.setDatabaseUrl("jdbc:h2:mem:participantProviderTestDb" + dbNameCounter.getAndIncrement());
+ parameters.setDatabaseUser("policy");
+ parameters.setDatabasePassword("P01icY");
+ parameters.setPersistenceUnit("ToscaConceptTest");
+
+ participantProvider = new ParticipantProvider(parameters);
+ inputParticipants.add(CODER.decode(originalJson, Participant.class));
+
+ }
+
+ @After
+ public void teardown() {
+ participantProvider.close();
+ }
+
+ @Test
+ public void testParticipantCreate() throws Exception {
+ assertThatThrownBy(() -> {
+ participantProvider.createParticipants(null);
+ }).hasMessageMatching(LIST_IS_NULL);
+
+ List<Participant> createdParticipants = new ArrayList<>();
+ createdParticipants.addAll(participantProvider
+ .createParticipants(inputParticipants));
+
+ assertEquals(createdParticipants.get(0),
+ inputParticipants.get(0));
+ }
+
+
+ @Test
+ public void testGetControlLoops() throws Exception {
+
+ List<Participant> getResponse;
+
+ //Return empty list when no data present in db
+ getResponse = participantProvider.getParticipants(null, null);
+ assertThat(getResponse).isEmpty();
+
+ participantProvider.createParticipants(inputParticipants);
+ String name = inputParticipants.get(0).getName();
+ String version = inputParticipants.get(0).getVersion();
+ assertEquals(1, participantProvider.getParticipants(name, version).size());
+
+ assertThat(participantProvider.getParticipants("invalid_name",
+ "1.0.1")).isEmpty();
+
+ assertThatThrownBy(() -> {
+ participantProvider.getFilteredParticipants(null);
+ }).hasMessageMatching("filter is marked .*ull but is null");
+
+ final ToscaTypedEntityFilter<Participant> filter = ToscaTypedEntityFilter.<Participant>builder()
+ .type("org.onap.domain.pmsh.PMSHControlLoopDefinition").build();
+ assertEquals(1, participantProvider.getFilteredParticipants(filter).size());
+ }
+
+ @Test
+ public void testUpdateParticipant() throws Exception {
+ assertThatThrownBy(() -> {
+ participantProvider.updateParticipants(null);
+ }).hasMessageMatching("participants is marked .*ull but is null");
+
+ participantProvider.createParticipants(inputParticipants);
+ updateParticipants = inputParticipants.get(0);
+ updateParticipants.setParticipantState(ParticipantState.ACTIVE);
+ List<Participant> participantList = new ArrayList<>();
+ participantList.add(updateParticipants);
+ List<Participant> updateResponse = new ArrayList<>();
+ updateResponse = participantProvider.updateParticipants(participantList);
+
+ assertEquals(ParticipantState.ACTIVE, updateResponse.get(0).getParticipantState());
+ }
+
+ @Test
+ public void testDeleteParticipant() throws Exception {
+ assertThatThrownBy(() -> {
+ participantProvider.deleteParticipant("Invalid_name", "1.0.1");
+ }).hasMessageMatching(".*.failed, participant does not exist");
+
+ Participant deletedParticipant;
+ List<Participant> participantList = participantProvider.createParticipants(inputParticipants);
+ String name = inputParticipants.get(0).getName();
+ String version = inputParticipants.get(0).getVersion();
+
+ deletedParticipant = participantProvider.deleteParticipant(name, version);
+ assertEquals(participantList.get(0), deletedParticipant);
+
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java
new file mode 100644
index 000000000..d4bc9777a
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
+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.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ParticipantStatisticsProviderTest {
+
+ private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
+ private static final Coder CODER = new StandardCoder();
+ private static final String PARTICIPANT_STATS_JSON = "src/test/resources/providers/TestParticipantStatistics.json";
+
+ private static AtomicInteger dbNameCounter = new AtomicInteger();
+
+ private PolicyModelsProviderParameters parameters;
+ private ParticipantStatisticsProvider participantStatisticsProvider;
+ private ParticipantStatisticsList inputParticipantStatistics;
+ private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON);
+
+ /**
+ * Set up test Participant statistics provider.
+ */
+ @Before
+ public void setupDao() throws Exception {
+
+ parameters = new PolicyModelsProviderParameters();
+ parameters.setDatabaseDriver("org.h2.Driver");
+ parameters.setName("PolicyProviderParameterGroup");
+ parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
+ parameters.setDatabaseUrl("jdbc:h2:mem:participantStatisticsProviderTestDb" + dbNameCounter.getAndIncrement());
+ parameters.setDatabaseUser("policy");
+ parameters.setDatabasePassword("P01icY");
+ parameters.setPersistenceUnit("ToscaConceptTest");
+
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters);
+ inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class);
+ }
+
+ @After
+ public void teardown() {
+ participantStatisticsProvider.close();
+ }
+
+ @Test
+ public void testParticipantStatisticsCreate() throws Exception {
+ assertThatThrownBy(() -> {
+ participantStatisticsProvider.createParticipantStatistics(null);
+ }).hasMessageMatching(LIST_IS_NULL);
+
+ ParticipantStatisticsList createdStatsList = new ParticipantStatisticsList();
+ createdStatsList.setStatisticsList(participantStatisticsProvider
+ .createParticipantStatistics(inputParticipantStatistics.getStatisticsList()));
+
+ assertEquals(inputParticipantStatistics.toString().replaceAll("\\s+", ""),
+ createdStatsList.toString().replaceAll("\\s+", ""));
+ }
+
+ @Test
+ public void testGetControlLoops() throws Exception {
+ List<ParticipantStatistics> getResponse;
+
+ // Return empty list when no data present in db
+ getResponse = participantStatisticsProvider.getParticipantStatistics(null, null, null);
+ assertThat(getResponse).isEmpty();
+
+ participantStatisticsProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
+ ToscaConceptIdentifier identifier = inputParticipantStatistics.getStatisticsList().get(0).getParticipantId();
+ Instant instant = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp();
+ assertEquals(1, participantStatisticsProvider
+ .getParticipantStatistics(identifier.getName(), identifier.getVersion(), instant).size());
+
+ assertEquals(1, participantStatisticsProvider
+ .getFilteredParticipantStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size());
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java
new file mode 100644
index 000000000..d1e3dcfcc
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+
+public class ControlLoopNotificationTest {
+
+ @Test
+ public void testControlLoopNotification() {
+ ControlLoopNotification cln0 = new ControlLoopNotification();
+
+ List<ControlLoopStatus> addedList = new ArrayList<>();
+ addedList.add(new ControlLoopStatus());
+
+ List<ControlLoopStatus> deletedList = new ArrayList<>();
+ deletedList.add(new ControlLoopStatus());
+
+ assertEquals(true, cln0.isEmpty());
+
+ cln0.setAdded(addedList);
+ assertEquals(false, cln0.isEmpty());
+ cln0.setAdded(null);
+ assertEquals(true, cln0.isEmpty());
+
+ cln0.setDeleted(deletedList);
+ assertEquals(false, cln0.isEmpty());
+ cln0.setDeleted(null);
+ assertEquals(true, cln0.isEmpty());
+
+ cln0.setAdded(addedList);
+ cln0.setDeleted(deletedList);
+ assertEquals(false, cln0.isEmpty());
+ cln0.setAdded(null);
+ cln0.setDeleted(null);
+ assertEquals(true, cln0.isEmpty());
+ }
+
+ @Test
+ public void testControlLoopNotificationLombok() {
+ assertNotNull(new ControlLoopNotification());
+ assertNotNull(new ControlLoopNotification(new ArrayList<>(), new ArrayList<>()));
+
+ ControlLoopNotification cln0 = new ControlLoopNotification();
+
+ assertThat(cln0.toString()).contains("ControlLoopNotification(");
+ assertEquals(false, cln0.hashCode() == 0);
+ assertEquals(true, cln0.equals(cln0));
+ assertEquals(false, cln0.equals(null));
+
+
+ ControlLoopNotification cln1 = new ControlLoopNotification();
+
+ assertThat(cln1.toString()).contains("ControlLoopNotification(");
+ assertEquals(false, cln1.hashCode() == 0);
+ assertEquals(true, cln1.equals(cln0));
+ assertEquals(false, cln1.equals(null));
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java
new file mode 100644
index 000000000..d1ddbf4e6
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ControlLoopStatusTest {
+
+ @Test
+ public void testControlLoopStatusLombok() {
+ assertNotNull(new ControlLoopStatus());
+ assertNotNull(new ControlLoopStatus(UUID.randomUUID(), new ToscaConceptIdentifier()));
+
+ ControlLoopStatus cln0 = new ControlLoopStatus();
+
+ assertThat(cln0.toString()).contains("ControlLoopStatus(");
+ assertEquals(false, cln0.hashCode() == 0);
+ assertEquals(true, cln0.equals(cln0));
+ assertEquals(false, cln0.equals(null));
+
+ ControlLoopStatus cln1 = new ControlLoopStatus();
+ assertEquals(true, cln1.equals(cln0));
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java
new file mode 100644
index 000000000..6ea07be76
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ToStringTester;
+
+/**
+ * Class to perform unit tests of all pojos.
+ */
+public class NotificationPojosTest {
+
+ @Test
+ public void testPojos() {
+ List<PojoClass> pojoClasses =
+ PojoClassFactory.getPojoClasses(NotificationPojosTest.class.getPackageName());
+
+ // @formatter:off
+ final Validator validator = ValidatorBuilder
+ .create()
+ .with(new ToStringTester())
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+
+ validator.validate(pojoClasses);
+ // @formatter:on
+ }
+}
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/ParticipantControlLoopStateChangeTest.java
new file mode 100644
index 000000000..06d6ecf77
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Test the copy constructor and other methods.
+ */
+public class ParticipantControlLoopStateChangeTest {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class);
+
+ ParticipantControlLoopStateChange orig = new ParticipantControlLoopStateChange();
+
+ // verify with null values
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantControlLoopStateChange(orig).toString()));
+
+ // verify with all values
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ id.setName("id");
+ id.setVersion("1.2.3");
+ orig.setControlLoopId(id);
+ orig.setParticipantId(id);
+ orig.setMessageId(UUID.randomUUID());
+ orig.setOrderedState(ControlLoopOrderedState.RUNNING);
+ orig.setTimestamp(Instant.ofEpochMilli(3000));
+
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantControlLoopStateChange(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/ParticipantControlLoopUpdateTest.java
new file mode 100644
index 000000000..4397bf158
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.UUID;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+/**
+ * Test the copy constructor.
+ */
+public class ParticipantControlLoopUpdateTest {
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new ParticipantControlLoopUpdate(null)).isInstanceOf(NullPointerException.class);
+
+ ParticipantControlLoopUpdate orig = new ParticipantControlLoopUpdate();
+ // verify with all values
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ id.setName("id");
+ id.setVersion("1.2.3");
+ orig.setControlLoopId(id);
+ orig.setParticipantId(id);
+ orig.setMessageId(UUID.randomUUID());
+ orig.setTimestamp(Instant.ofEpochMilli(3000));
+
+ 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);
+ orig.setControlLoop(controlLoop);
+
+ ParticipantControlLoopUpdate other = new ParticipantControlLoopUpdate(orig);
+
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
+
+ // ensure list and items are not the same object
+ assertNotSame(other.getControlLoop(), controlLoop);
+ assertNotSame(other.getControlLoopDefinition(), toscaServiceTemplate);
+ }
+}
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/ParticipantHealthCheckTest.java
new file mode 100644
index 000000000..1cc356627
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.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.
+ */
+public class ParticipantHealthCheckTest {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class);
+
+ ParticipantHealthCheck orig = new ParticipantHealthCheck();
+
+ // verify with null values
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantHealthCheck(orig).toString()));
+
+ // verify with all values
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ id.setName("id");
+ id.setVersion("1.2.3");
+ orig.setControlLoopId(id);
+ orig.setParticipantId(id);
+ orig.setMessageId(UUID.randomUUID());
+ orig.setState(ParticipantState.ACTIVE);
+ orig.setTimestamp(Instant.ofEpochMilli(3000));
+
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantHealthCheck(orig).toString()));
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java
new file mode 100644
index 000000000..d27d3a22c
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ParticipantMessageTest {
+ private ParticipantMessage message;
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new ParticipantMessage((ParticipantMessage) null))
+ .isInstanceOf(NullPointerException.class);
+
+ // verify with null values
+ message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+ ParticipantMessage newmsg = new ParticipantMessage(message);
+ newmsg.setMessageId(message.getMessageId());
+ newmsg.setTimestamp(message.getTimestamp());
+ assertEquals(message.toString(), newmsg.toString());
+
+ // verify with all values
+ message = makeMessage();
+ newmsg = new ParticipantMessage(message);
+ newmsg.setMessageId(message.getMessageId());
+ newmsg.setTimestamp(message.getTimestamp());
+ assertEquals(message.toString(), newmsg.toString());
+ }
+
+ @Test
+ public void testAppliesTo_NullParticipantId() {
+ message = makeMessage();
+
+ 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
+ public void testAppliesTo_ParticipantIdMatches() {
+ message = makeMessage();
+
+ // ParticipantId matches
+ 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 does not match
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ id.setName("id1111");
+ id.setVersion("3.2.1");
+ assertFalse(message.appliesTo(id, id));
+ message.setParticipantType(null);
+ assertTrue(message.appliesTo(id, id));
+ }
+
+ private ParticipantMessage makeMessage() {
+ ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+
+ 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));
+
+ return msg;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java
new file mode 100644
index 000000000..dfbc25d1b
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
+
+/**
+ * Utility class for tests of ParticipantMessage subclasses.
+ */
+public class ParticipantMessageUtils {
+
+ private ParticipantMessageUtils() {
+
+ }
+
+ public static String removeVariableFields(String text) {
+ return text.replaceAll("messageId=[^,]*", "messageId=xxx").replaceAll("timestamp=[^,]*", "timestamp=nnn");
+ }
+}
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
new file mode 100644
index 000000000..301f9acc0
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ToStringTester;
+
+/**
+ * Class to perform unit tests of all pojos.
+ */
+public class ParticipantPojosTest {
+
+ @Test
+ public void testPojos() {
+ List<PojoClass> pojoClasses =
+ PojoClassFactory.getPojoClasses(ParticipantPojosTest.class.getPackageName());
+
+ pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessage.class));
+ pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class));
+
+ // @formatter:off
+ final Validator validator = ValidatorBuilder
+ .create()
+ .with(new ToStringTester())
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+
+ validator.validate(pojoClasses);
+ // @formatter:on
+ }
+}
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/ParticipantStateChangeTest.java
new file mode 100644
index 000000000..235532681
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.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.
+ */
+public class ParticipantStateChangeTest {
+
+ @Test
+ public 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()));
+
+ // verify with all values
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ id.setName("id");
+ id.setVersion("1.2.3");
+ orig.setControlLoopId(id);
+ orig.setParticipantId(id);
+ orig.setMessageId(UUID.randomUUID());
+ orig.setState(ParticipantState.ACTIVE);
+ orig.setTimestamp(Instant.ofEpochMilli(3000));
+
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantStateChange(orig).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
new file mode 100644
index 000000000..9b5722bce
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class ParticipantStatusTest {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class);
+
+ final ParticipantStatus orig = new ParticipantStatus();
+
+ // verify with null values
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantStatus(orig).toString()));
+
+ // verify with all values
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ id.setName("id");
+ id.setVersion("1.2.3");
+ orig.setControlLoopId(id);
+ orig.setParticipantId(id);
+ orig.setMessageId(UUID.randomUUID());
+ orig.setState(ParticipantState.ACTIVE);
+ orig.setTimestamp(Instant.ofEpochMilli(3000));
+
+ final ParticipantResponseDetails resp = new ParticipantResponseDetails();
+ resp.setResponseMessage("my-response");
+ orig.setResponse(resp);
+
+ assertEquals(removeVariableFields(orig.toString()),
+ removeVariableFields(new ParticipantStatus(orig).toString()));
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java
new file mode 100644
index 000000000..299a580d3
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.rest;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ToStringTester;
+
+/**
+ * Class to perform unit tests of all pojos.
+ */
+public class MessagesRestPojosTest {
+
+ @Test
+ public void testPojos() {
+ List<PojoClass> pojoClasses =
+ PojoClassFactory.getPojoClassesRecursively(MessagesRestPojosTest.class.getPackageName(), null);
+
+
+ // @formatter:off
+ final Validator validator = ValidatorBuilder
+ .create()
+ .with(new ToStringTester())
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+
+ validator.validate(pojoClasses);
+ // @formatter:on
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java
new file mode 100644
index 000000000..6bda3b736
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import org.junit.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+
+public class InstantiationCommandTest {
+ @Test
+ public void testInstantiationCommandLombok() {
+ assertNotNull(new InstantiationCommand());
+ InstantiationCommand ic0 = new InstantiationCommand();
+
+ assertThat(ic0.toString()).contains("InstantiationCommand(");
+ assertEquals(false, ic0.hashCode() == 0);
+ assertEquals(true, ic0.equals(ic0));
+ assertEquals(false, ic0.equals(null));
+
+
+ InstantiationCommand ic1 = new InstantiationCommand();
+
+ ic1.setControlLoopIdentifierList(new ArrayList<>());
+ ic1.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ assertThat(ic1.toString()).contains("InstantiationCommand(");
+ assertEquals(false, ic1.hashCode() == 0);
+ assertEquals(false, ic1.equals(ic0));
+ assertEquals(false, ic1.equals(null));
+
+ assertNotEquals(ic1, ic0);
+
+ InstantiationCommand ic2 = new InstantiationCommand();
+
+ assertEquals(ic2, ic0);
+ }
+}