From 43098043c4ef31d9d5dead66568d7d9482a6b165 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 25 Jan 2022 19:55:43 +0000 Subject: Rename TOSCA Control Loop to ACM This commit renames the TOSCA Control Loop functionality in CLAMP to Automation Composition Management. This review is a direct renaming review and, as everything is renamed together it is large. Issue-ID: POLICY-3939 Change-Id: I28f0a6dd889bf3570a4c1365ae9e71fc58db6d6c Signed-off-by: liamfallon --- .../concepts/ClElementStatisticsTest.java | 67 ----- .../concepts/ControlLoopConceptPojosTest.java | 62 ---- .../concepts/ControlLoopElementTest.java | 103 ------- .../controlloop/concepts/ControlLoopTest.java | 160 ----------- .../concepts/ParticipantStatisticsTest.java | 65 ----- .../controlloop/concepts/ParticipantTest.java | 84 ------ .../controlloop/concepts/ParticipantUtilsTest.java | 84 ------ .../concepts/DummyJpaClElementStatisticsChild.java | 28 -- .../concepts/DummyJpaControlLoopChild.java | 28 -- .../concepts/DummyJpaControlLoopElementChild.java | 28 -- .../concepts/DummyJpaParticipantChild.java | 28 -- .../DummyJpaParticipantStatisticsChild.java | 28 -- .../concepts/JpaClElementStatisticsTest.java | 189 ------------- .../concepts/JpaControlLoopElementTest.java | 300 -------------------- .../persistence/concepts/JpaControlLoopTest.java | 301 -------------------- .../concepts/JpaParticipantStatisticsTest.java | 193 ------------- .../persistence/concepts/JpaParticipantTest.java | 254 ----------------- .../persistence/concepts/PojosTest.java | 62 ---- .../provider/ClElementStatisticsProviderTest.java | 116 -------- .../provider/ControlLoopProviderTest.java | 290 ------------------- .../provider/ParticipantProviderTest.java | 149 ---------- .../ParticipantStatisticsProviderTest.java | 107 ------- .../provider/ServiceTemplateProviderTest.java | 169 ----------- .../repository/FilterRepositoryImplTest.java | 106 ------- .../notification/ControlLoopNotificationTest.java | 83 ------ .../dmaap/notification/ControlLoopStatusTest.java | 48 ---- .../dmaap/notification/NotificationPojosTest.java | 58 ---- .../dmaap/participant/ControlLoopAckTest.java | 68 ----- .../participant/ControlLoopStateChangeTest.java | 65 ----- .../dmaap/participant/ControlLoopUpdateTest.java | 82 ------ .../participant/ParticipantAckMessageTest.java | 105 ------- .../participant/ParticipantDeregisterAckTest.java | 59 ---- .../participant/ParticipantDeregisterTest.java | 61 ---- .../dmaap/participant/ParticipantMessageTest.java | 107 ------- .../dmaap/participant/ParticipantMessageUtils.java | 55 ---- .../dmaap/participant/ParticipantPojosTest.java | 65 ----- .../participant/ParticipantRegisterAckTest.java | 59 ---- .../dmaap/participant/ParticipantRegisterTest.java | 61 ---- .../participant/ParticipantStatusReqTest.java | 56 ---- .../dmaap/participant/ParticipantStatusTest.java | 129 --------- .../participant/ParticipantUpdateAckTest.java | 59 ---- .../dmaap/participant/ParticipantUpdateTest.java | 101 ------- .../messages/rest/MessagesRestPojosTest.java | 59 ---- .../instantiation/InstantiationCommandTest.java | 60 ---- .../controlloop/models/rest/RestUtilsTest.java | 54 ---- .../acm/concepts/AcElementStatisticsTest.java | 67 +++++ .../AutomationCompositionConceptPojosTest.java | 62 ++++ .../concepts/AutomationCompositionElementTest.java | 103 +++++++ .../acm/concepts/AutomationCompositionTest.java | 160 +++++++++++ .../acm/concepts/ParticipantStatisticsTest.java | 65 +++++ .../clamp/models/acm/concepts/ParticipantTest.java | 84 ++++++ .../models/acm/concepts/ParticipantUtilsTest.java | 91 ++++++ .../AutomationCompositionNotificationTest.java | 83 ++++++ .../AutomationCompositionStatusTest.java | 48 ++++ .../dmaap/notification/NotificationPojosTest.java | 58 ++++ .../participant/AutomationCompositionAckTest.java | 68 +++++ .../AutomationCompositionStateChangeTest.java | 65 +++++ .../AutomationCompositionUpdateTest.java | 82 ++++++ .../participant/ParticipantAckMessageTest.java | 105 +++++++ .../participant/ParticipantDeregisterAckTest.java | 59 ++++ .../participant/ParticipantDeregisterTest.java | 61 ++++ .../dmaap/participant/ParticipantMessageTest.java | 107 +++++++ .../dmaap/participant/ParticipantMessageUtils.java | 55 ++++ .../dmaap/participant/ParticipantPojosTest.java | 65 +++++ .../participant/ParticipantRegisterAckTest.java | 59 ++++ .../dmaap/participant/ParticipantRegisterTest.java | 61 ++++ .../participant/ParticipantStatusReqTest.java | 56 ++++ .../dmaap/participant/ParticipantStatusTest.java | 129 +++++++++ .../participant/ParticipantUpdateAckTest.java | 59 ++++ .../dmaap/participant/ParticipantUpdateTest.java | 101 +++++++ .../acm/messages/rest/MessagesRestPojosTest.java | 59 ++++ .../instantiation/InstantiationCommandTest.java | 60 ++++ .../concepts/DummyJpaAcElementStatisticsChild.java | 28 ++ .../DummyJpaAutomationCompositionChild.java | 28 ++ .../DummyJpaAutomationCompositionElementChild.java | 28 ++ .../concepts/DummyJpaParticipantChild.java | 28 ++ .../DummyJpaParticipantStatisticsChild.java | 28 ++ .../concepts/JpaAcElementStatisticsTest.java | 189 +++++++++++++ .../JpaAutomationCompositionElementTest.java | 315 +++++++++++++++++++++ .../concepts/JpaAutomationCompositionTest.java | 310 ++++++++++++++++++++ .../concepts/JpaParticipantStatisticsTest.java | 193 +++++++++++++ .../persistence/concepts/JpaParticipantTest.java | 254 +++++++++++++++++ .../models/acm/persistence/concepts/PojosTest.java | 62 ++++ .../provider/AcElementStatisticsProviderTest.java | 116 ++++++++ .../AutomationCompositionProviderTest.java | 305 ++++++++++++++++++++ .../provider/ParticipantProviderTest.java | 149 ++++++++++ .../ParticipantStatisticsProviderTest.java | 107 +++++++ .../provider/ServiceTemplateProviderTest.java | 169 +++++++++++ .../repository/FilterRepositoryImplTest.java | 109 +++++++ .../clamp/models/acm/rest/RestUtilsTest.java | 54 ++++ .../clamp/models/acm/utils/AcmUtilsTest.java | 149 ++++++++++ 91 files changed, 4693 insertions(+), 4495 deletions(-) delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java (limited to 'models/src/test/java/org/onap') 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 deleted file mode 100644 index 3bb0050c8..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ClElementStatisticsTest { - @Test - 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 deleted file mode 100644 index daade4d52..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class ControlLoopConceptPojosTest { - - @Test - void testPojos() { - List 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 deleted file mode 100644 index ed579febb..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============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.assertTrue; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopElementTest { - @Test - void testControlLoopElement() { - var cle0 = new ControlLoopElement(); - var cle1 = new ControlLoopElement(cle0); - assertEquals(cle0, cle1); - - 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); - - var cle2 = new ControlLoopElement(cle1); - assertEquals(cle1, cle2); - } - - @Test - void testControlLoopState() { - var cle0 = new ControlLoopElement(); - - assertTrue( - cle0.getOrderedState() - .equalsControlLoopState(ControlLoopState.UNINITIALISED)); - - assertTrue( - cle0.getOrderedState().asState() - .equalsControlLoopOrderedState(ControlLoopOrderedState.UNINITIALISED)); - } - - @Test - void testControlLoopElementLombok() { - assertNotNull(new ControlLoopElement()); - var cle0 = new ControlLoopElement(); - - assertThat(cle0.toString()).contains("ControlLoopElement("); - assertThat(cle0.hashCode()).isNotZero(); - assertEquals(true, cle0.equals(cle0)); - assertEquals(false, cle0.equals(null)); - - var 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); - - var 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 deleted file mode 100644 index d9c518b53..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * ============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.time.Instant; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopTest { - @Test - void testControlLoop() { - var cl0 = new ControlLoop(); - cl0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); - assertEquals("dfName", cl0.getType()); - assertEquals("1.2.3", cl0.getTypeVersion()); - - var cl1 = new ControlLoop(cl0); - assertEquals(cl0, cl1); - - assertEquals(0, cl0.compareTo(cl1)); - } - - @Test - void testControlLoopLombok() { - assertNotNull(new ControlLoop()); - var 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)); - - var 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); - - var 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()); - - } - - @Test - void testControlLoopElementStatisticsList() { - var cl = new ControlLoop(); - List emptylist = cl.getControlLoopElementStatisticsList(cl); - assertEquals(List.of(), emptylist); - - var cl1 = getControlLoopTest(); - List list = cl1.getControlLoopElementStatisticsList(cl1); - assertNotNull(list); - assertEquals(2, list.size()); - assertEquals(ControlLoopState.UNINITIALISED, list.get(0).getControlLoopState()); - } - - private ControlLoop getControlLoopTest() { - var cl = new ControlLoop(); - cl.setDefinition(new ToscaConceptIdentifier("defName", "1.2.3")); - cl.setDescription("Description"); - cl.setElements(new LinkedHashMap<>()); - cl.setName("Name"); - cl.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - cl.setState(ControlLoopState.UNINITIALISED); - cl.setVersion("0.0.1"); - - var uuid = UUID.randomUUID(); - var id = new ToscaConceptIdentifier( - "org.onap.policy.controlloop.PolicyControlLoopParticipant", "1.0.1"); - var clElement = getControlLoopElementTest(uuid, id); - - var uuid2 = UUID.randomUUID(); - var id2 = new ToscaConceptIdentifier( - "org.onap.policy.controlloop.PolicyControlLoopParticipantIntermediary", "0.0.1"); - var clElement2 = getControlLoopElementTest(uuid2, id2); - - cl.getElements().put(uuid, clElement); - cl.getElements().put(uuid2, clElement2); - return cl; - } - - private ControlLoopElement getControlLoopElementTest(UUID uuid, ToscaConceptIdentifier id) { - var clElement = new ControlLoopElement(); - clElement.setId(uuid); - clElement.setParticipantId(id); - clElement.setDefinition(id); - clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - - var clElementStatistics = new ClElementStatistics(); - clElementStatistics.setParticipantId(id); - clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED); - clElementStatistics.setTimeStamp(Instant.now()); - - clElement.setClElementStatistics(clElementStatistics); - - return clElement; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java deleted file mode 100644 index f55f624bf..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantStatisticsTest { - @Test - 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 deleted file mode 100644 index 5c429b96c..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantTest { - @Test - 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 - 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/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java deleted file mode 100644 index 3fb8b6d7f..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============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 java.util.Map; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -class ParticipantUtilsTest { - - private static final Coder CODER = new StandardCoder(); - private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml"; - private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; - private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement"; - private static final String POLICY_CONTROL_LOOP_ELEMENT = - "org.onap.policy.clamp.controlloop.PolicyControlLoopElement"; - private static final String PARTICIPANT_CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.Participant"; - private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); - - @Test - void testFindParticipantType() throws CoderException { - var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1"); - var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier))); - assertThat(result).isEqualTo(identifier); - } - - @Test - void testFindStartPhase() { - var identifier = 13; - var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier)); - assertThat(result).isEqualTo(identifier); - } - - @Test - void testGetFirstStartPhase() throws CoderException { - var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); - var controlLoops = CODER.decode(ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON), ControlLoops.class); - var result = ParticipantUtils.getFirstStartPhase(controlLoops.getControlLoopList().get(0), serviceTemplate); - assertThat(result).isZero(); - } - - @Test - void testCheckIfNodeTemplateIsControlLoopElement() throws CoderException { - var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); - var nodeTemplate = new ToscaNodeTemplate(); - nodeTemplate.setType(CONTROL_LOOP_ELEMENT); - assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue(); - - nodeTemplate.setType(POLICY_CONTROL_LOOP_ELEMENT); - assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue(); - - nodeTemplate.setType(PARTICIPANT_CONTROL_LOOP_ELEMENT); - assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isFalse(); - } -} 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 deleted file mode 100644 index 94b0b13c7..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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. - */ -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 deleted file mode 100644 index 10150cf59..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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. - */ -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 deleted file mode 100644 index 4bacb9255..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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. - */ -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 deleted file mode 100644 index 68dcc319b..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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. - */ -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 deleted file mode 100644 index 2c1f04ea1..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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. - */ -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 deleted file mode 100644 index 0e6fb8383..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/*- - * ============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.jupiter.api.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. - */ -class JpaClElementStatisticsTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - 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 - 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 - void testJpaClElementStatisticsValidation() { - JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); - - assertThatThrownBy(() -> { - testJpaClElementStatistics.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaClElementStatistics.validate("").isValid()); - } - - @Test - 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 - 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 deleted file mode 100644 index 63c5ea3ab..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java +++ /dev/null @@ -1,300 +0,0 @@ -/*- - * ============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.jupiter.api.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. - */ -class JpaControlLoopElementTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - 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 - 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 - 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 - void testJpaControlLoopElementValidation() { - JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); - - assertThatThrownBy(() -> { - testJpaControlLoopElement.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaControlLoopElement.validate("").isValid()); - } - - @Test - 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 - 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 deleted file mode 100644 index d705c49b5..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java +++ /dev/null @@ -1,301 +0,0 @@ -/*- - * ============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.jupiter.api.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. - */ -class JpaControlLoopTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - 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 - 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 - 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 - void testJpaControlLoopValidation() { - JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); - - assertThatThrownBy(() -> { - testJpaControlLoop.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaControlLoop.validate("").isValid()); - } - - @Test - 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)); - - testJpaControlLoop.setPrimed(true); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setPrimed(false); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - assertEquals(testJpaControlLoop, new JpaControlLoop(testJpaControlLoop)); - } - - @Test - 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 deleted file mode 100644 index aff365515..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/*- - * ============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.jupiter.api.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. - */ -class JpaParticipantStatisticsTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - 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 - 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 - 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 - 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 - 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 deleted file mode 100644 index 087292354..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * ============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.jupiter.api.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. - */ -class JpaParticipantTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - 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 - 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 - void testJpaParticipantValidation() { - JpaParticipant testJpaParticipant = createJpaParticipantInstance(); - - assertThatThrownBy(() -> { - testJpaParticipant.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaParticipant.validate("").isValid()); - } - - @Test - 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 - 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")); - testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "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 deleted file mode 100644 index c877f9696..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class PojosTest { - - @Test - void testPojos() { - List 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 deleted file mode 100644 index 82ce8d789..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * ============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.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ClElementStatisticsRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -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 ClElementStatisticsProvider clElementStatisticsProvider; - private ClElementStatisticsList inputClElementStats; - private String originalJson = ResourceUtils.getResourceAsString(CL_ELEMENT_STATS_JSON); - - /** - * Set up test ClElement statistics provider. - * - * @throws Exception on errors - */ - @BeforeEach - void beforeSetupDao() throws Exception { - - inputClElementStats = CODER.decode(originalJson, ClElementStatisticsList.class); - var clElementStatisticsRepository = mock(ClElementStatisticsRepository.class); - - var jpaClElementStatisticsList = - ProviderUtils.getJpaAndValidateList(inputClElementStats.getClElementStatistics(), - JpaClElementStatistics::new, "control loop element statistics"); - - for (var clElementStat : jpaClElementStatisticsList) { - when(clElementStatisticsRepository.getById(eq(clElementStat.getKey()))).thenReturn(clElementStat); - when(clElementStatisticsRepository.findAllById(eq(List.of(clElementStat.getKey())))) - .thenReturn(List.of(clElementStat)); - } - - when(clElementStatisticsRepository.saveAll(anyList())).thenReturn(jpaClElementStatisticsList); - - when(clElementStatisticsRepository.getFiltered(eq(JpaClElementStatistics.class), any())) - .thenReturn(List.of(jpaClElementStatisticsList.get(0))); - - clElementStatisticsProvider = new ClElementStatisticsProvider(clElementStatisticsRepository); - } - - @Test - 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 - void testGetClElementStatistics() throws Exception { - - List 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 deleted file mode 100644 index 4b8617b3d..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java +++ /dev/null @@ -1,290 +0,0 @@ -/*- - * ============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.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.Optional; -import javax.persistence.EntityNotFoundException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ControlLoopRepository; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaNodeTemplateRepository; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaNodeTemplatesRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; - -class ControlLoopProviderTest { - - private static final String LIST_IS_NULL = "controlLoops is marked .*ull but is null"; - private static final String OBJECT_IS_NULL = "controlLoop is marked non-null but is null"; - - private static final String ID_NAME = "PMSHInstance1"; - private static final String ID_VERSION = "1.0.1"; - private static final String ID_NAME_NOT_EXTST = "not_exist"; - private static final String ID_NAME_NOT_VALID = "not_valid"; - - private static final Coder CODER = new StandardCoder(); - private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; - private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml"; - - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - - private ControlLoops inputControlLoops; - private List inputControlLoopsJpa; - private String originalJson = ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - inputControlLoops = CODER.decode(originalJson, ControlLoops.class); - inputControlLoopsJpa = ProviderUtils.getJpaAndValidateList(inputControlLoops.getControlLoopList(), - JpaControlLoop::new, "control loops"); - } - - @Test - void testControlLoopsSave() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoops(null); - }).hasMessageMatching(LIST_IS_NULL); - - when(controlLoopRepository.saveAll(inputControlLoopsJpa)).thenReturn(inputControlLoopsJpa); - - var createdControlLoops = new ControlLoops(); - createdControlLoops - .setControlLoopList(controlLoopProvider.saveControlLoops(inputControlLoops.getControlLoopList())); - - assertEquals(inputControlLoops, createdControlLoops); - - when(controlLoopRepository.saveAll(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoops(inputControlLoops.getControlLoopList()); - }).hasMessageMatching("Error in save ControlLoops"); - } - - @Test - void testControlLoopSave() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoop(null); - }).hasMessageMatching(OBJECT_IS_NULL); - - when(controlLoopRepository.save(inputControlLoopsJpa.get(0))).thenReturn(inputControlLoopsJpa.get(0)); - - var createdControlLoop = controlLoopProvider.saveControlLoop(inputControlLoops.getControlLoopList().get(0)); - - assertEquals(inputControlLoops.getControlLoopList().get(0), createdControlLoop); - - when(controlLoopRepository.save(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoop(inputControlLoops.getControlLoopList().get(0)); - }).hasMessageMatching("Error in save controlLoop"); - } - - @Test - void testGetControlLoops() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - // Return empty list when no data present in db - List getResponse = controlLoopProvider.getControlLoops(); - assertThat(getResponse).isEmpty(); - - controlLoopProvider.saveControlLoops(inputControlLoops.getControlLoopList()); - - var controlLoop0 = inputControlLoops.getControlLoopList().get(1); - var name = controlLoop0.getName(); - var version = controlLoop0.getVersion(); - var controlLoop1 = inputControlLoops.getControlLoopList().get(1); - - when(controlLoopRepository.getFiltered(eq(JpaControlLoop.class), any(), any())) - .thenReturn(List.of(new JpaControlLoop(controlLoop0), new JpaControlLoop(controlLoop1))); - when(controlLoopRepository.findById(controlLoop0.getKey().asIdentifier().asConceptKey())) - .thenReturn(Optional.of(new JpaControlLoop(controlLoop0))); - when(controlLoopRepository.getById(controlLoop0.getKey().asIdentifier().asConceptKey())) - .thenReturn(new JpaControlLoop(controlLoop0)); - when(controlLoopRepository.getFiltered(JpaControlLoop.class, name, version)) - .thenReturn(List.of(new JpaControlLoop(controlLoop0))); - when(controlLoopRepository.findById(controlLoop1.getKey().asIdentifier().asConceptKey())) - .thenReturn(Optional.of(new JpaControlLoop(controlLoop1))); - - assertEquals(1, controlLoopProvider.getControlLoops(name, version).size()); - - var cl = controlLoopProvider.findControlLoop(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)).get(); - assertEquals(inputControlLoops.getControlLoopList().get(1), cl); - - cl = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)); - assertEquals(inputControlLoops.getControlLoopList().get(1), cl); - - when(controlLoopRepository.getById(any())).thenThrow(EntityNotFoundException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.getControlLoop(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)); - }).hasMessageMatching("ControlLoop not found"); - - cl = controlLoopProvider.findControlLoop(ID_NAME, ID_VERSION).get(); - assertEquals(inputControlLoops.getControlLoopList().get(1), cl); - - assertThat(controlLoopProvider.findControlLoop(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))) - .isEmpty(); - - when(controlLoopRepository.findById(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.findControlLoop(ID_NAME_NOT_VALID, ID_VERSION); - }).hasMessageMatching("Not valid parameter"); - } - - @Test - void testDeleteControlLoop() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - assertThatThrownBy(() -> { - controlLoopProvider.deleteControlLoop(ID_NAME_NOT_EXTST, ID_VERSION); - }).hasMessageMatching(".*.failed, control loop does not exist"); - - var controlLoop = inputControlLoops.getControlLoopList().get(0); - var name = controlLoop.getName(); - var version = controlLoop.getVersion(); - - when(controlLoopRepository.findById(new PfConceptKey(name, version))) - .thenReturn(Optional.of(inputControlLoopsJpa.get(0))); - - ControlLoop deletedCl = controlLoopProvider.deleteControlLoop(name, version); - assertEquals(controlLoop, deletedCl); - } - - @Test - void testDeleteAllInstanceProperties() throws Exception { - var controlLoopProvider = new ControlLoopProvider(mock(ControlLoopRepository.class), - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - var toscaServiceTemplate = testControlLoopRead(); - controlLoopProvider.deleteInstanceProperties(controlLoopProvider.saveInstanceProperties(toscaServiceTemplate), - controlLoopProvider.getAllNodeTemplates()); - assertThat(controlLoopProvider.getControlLoops()).isEmpty(); - } - - @Test - void testSaveAndDeleteInstanceProperties() throws Exception { - var toscaNodeTemplatesRepository = mock(ToscaNodeTemplatesRepository.class); - var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); - var controlLoopProvider = new ControlLoopProvider(mock(ControlLoopRepository.class), - toscaNodeTemplateRepository, toscaNodeTemplatesRepository); - var toscaServiceTest = testControlLoopRead(); - - controlLoopProvider.saveInstanceProperties(toscaServiceTest); - verify(toscaNodeTemplatesRepository).save(any()); - - var name = "org.onap.policy.controlloop.PolicyControlLoopParticipant"; - var version = "2.3.1"; - var elem = toscaServiceTest.getToscaTopologyTemplate().getNodeTemplates().get(name); - when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version)) - .thenReturn(List.of(new JpaToscaNodeTemplate(elem))); - - var filtered = controlLoopProvider.getNodeTemplates(name, version); - verify(toscaNodeTemplateRepository).getFiltered(JpaToscaNodeTemplate.class, name, version); - - controlLoopProvider.deleteInstanceProperties(controlLoopProvider.saveInstanceProperties(toscaServiceTest), - filtered); - - verify(toscaNodeTemplateRepository).delete(any()); - } - - @Test - void testGetNodeTemplates() throws Exception { - var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); - var controlLoopProvider = new ControlLoopProvider(mock(ControlLoopRepository.class), - toscaNodeTemplateRepository, mock(ToscaNodeTemplatesRepository.class)); - - var toscaNodeTemplate0 = new JpaToscaNodeTemplate(new PfConceptKey(ID_NAME, ID_VERSION)); - var toscaNodeTemplate1 = new JpaToscaNodeTemplate(new PfConceptKey("PMSHInstance2", ID_VERSION)); - - when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, null, null)) - .thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); - when(toscaNodeTemplateRepository.findAll()).thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); - when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, ID_NAME, ID_VERSION)) - .thenReturn(List.of(toscaNodeTemplate0)); - - // Getting all nodes - var listNodes = controlLoopProvider.getAllNodeTemplates(); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(2); - - listNodes = controlLoopProvider.getNodeTemplates(ID_NAME, ID_VERSION); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(1); - - listNodes = controlLoopProvider.getAllNodeTemplates(); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(2); - - var nodeTemplateFilter = - ToscaTypedEntityFilter.builder().name(ID_NAME).version(ID_VERSION).build(); - - listNodes = controlLoopProvider.getFilteredNodeTemplates(nodeTemplateFilter); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(1); - - assertThatThrownBy(() -> { - controlLoopProvider.getFilteredNodeTemplates(null); - }).hasMessageMatching("filter is marked non-null but is null"); - } - - private static ToscaServiceTemplate testControlLoopRead() { - return testControlLoopYamlSerialization(TOSCA_TEMPLATE_YAML); - } - - private static ToscaServiceTemplate testControlLoopYamlSerialization(String controlLoopFilePath) { - var controlLoopString = ResourceUtils.getResourceAsString(controlLoopFilePath); - return yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class); - } -} 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 deleted file mode 100644 index 9b48735f6..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============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.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ParticipantRepository; -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.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; - -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 List inputParticipants = new ArrayList<>(); - private List jpaParticipantList; - private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - inputParticipants.add(CODER.decode(originalJson, Participant.class)); - jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant"); - } - - @Test - void testParticipantSave() throws Exception { - var participantRepository = mock(ParticipantRepository.class); - for (var participant : jpaParticipantList) { - when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion()))) - .thenReturn(participant); - } - var participantProvider = new ParticipantProvider(participantRepository); - - assertThatThrownBy(() -> { - participantProvider.saveParticipant(null); - }).hasMessageMatching(LIST_IS_NULL); - - when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0)); - - Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0)); - assertEquals(savedParticipant, inputParticipants.get(0)); - - when(participantRepository.save(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - participantProvider.saveParticipant(inputParticipants.get(0)); - }).hasMessageMatching("Error in save Participant"); - } - - @Test - void testGetControlLoops() throws Exception { - var participantRepository = mock(ParticipantRepository.class); - var participantProvider = new ParticipantProvider(participantRepository); - - // Return empty list when no data present in db - List getResponse = participantProvider.getParticipants(null, null); - assertThat(getResponse).isEmpty(); - - String name = inputParticipants.get(0).getName(); - String version = inputParticipants.get(0).getVersion(); - when(participantRepository.getFiltered(any(), eq(name), eq(version))) - .thenReturn(List.of(jpaParticipantList.get(0))); - assertEquals(1, participantProvider.getParticipants(name, version).size()); - - assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty(); - - assertThat(participantProvider.findParticipant("invalid_name", "1.0.1")).isEmpty(); - - when(participantRepository.findAll()).thenReturn(jpaParticipantList); - assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size()); - - when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - participantProvider.findParticipant("notValid", "notValid"); - }).hasMessageMatching("Error in find Participant"); - - assertThatThrownBy(() -> { - participantProvider.getFilteredParticipants(null); - }).hasMessageMatching("filter is marked .*ull but is null"); - - when(participantRepository.getFiltered(eq(JpaParticipant.class), eq(null), eq(null))) - .thenReturn(jpaParticipantList); - - final ToscaTypedEntityFilter filter = ToscaTypedEntityFilter.builder() - .type("org.onap.domain.pmsh.PMSHControlLoopDefinition").build(); - assertEquals(1, participantProvider.getFilteredParticipants(filter).size()); - - } - - @Test - void testDeleteParticipant() throws Exception { - var participantRepository = mock(ParticipantRepository.class); - var participantProvider = new ParticipantProvider(participantRepository); - - assertThatThrownBy(() -> { - participantProvider.deleteParticipant("Invalid_name", "1.0.1"); - }).hasMessageMatching(".*.failed, participant does not exist"); - - String name = inputParticipants.get(0).getName(); - String version = inputParticipants.get(0).getVersion(); - - when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0))); - - Participant deletedParticipant = participantProvider.deleteParticipant(name, version); - assertEquals(inputParticipants.get(0), deletedParticipant); - - when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); - assertThatThrownBy(() -> { - participantProvider.deleteParticipant(name, version); - }).hasMessageMatching("Error in delete Participant"); - } -} 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 deleted file mode 100644 index 16f4958a9..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.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.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ParticipantStatisticsRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -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 ParticipantStatisticsProvider participantStatisticsProvider; - private ParticipantStatisticsList inputParticipantStatistics; - private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - var participantStatisticsRepository = mock(ParticipantStatisticsRepository.class); - participantStatisticsProvider = new ParticipantStatisticsProvider(participantStatisticsRepository); - inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class); - - var jpaParticipantStatisticsList = - ProviderUtils.getJpaAndValidateList(inputParticipantStatistics.getStatisticsList(), - JpaParticipantStatistics::new, "Participant Statistics"); - - for (var participantStat : jpaParticipantStatisticsList) { - when(participantStatisticsRepository.getById(eq(participantStat.getKey()))).thenReturn(participantStat); - when(participantStatisticsRepository.findAllById(eq(List.of(participantStat.getKey())))) - .thenReturn(List.of(participantStat)); - } - - when(participantStatisticsRepository.getFiltered(eq(JpaParticipantStatistics.class), any())) - .thenReturn(List.of(jpaParticipantStatisticsList.get(0))); - - when(participantStatisticsRepository.saveAll(anyList())).thenReturn(jpaParticipantStatisticsList); - } - - @Test - 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 - void testGetControlLoops() throws Exception { - // Return empty list when no data present in db - List 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/controlloop/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java deleted file mode 100644 index 523a4fb88..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/*- - * ============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.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaServiceTemplateRepository; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; - -class ServiceTemplateProviderTest { - - private static final String TOSCA_SERVICE_TEMPLATE_YAML = - "src/test/resources/providers/tosca-for-smoke-testing.yaml"; - - private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); - - private static ToscaServiceTemplate inputServiceTemplate; - - @BeforeAll - static void loadServiceTemplate() { - inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); - } - - @Test - void testGetCommonOrInstancePropertiesFromNodeTypes() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - - var result = serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); - assertNotNull(result); - assertThat(result).hasSize(8); - } - - @Test - void testGetDerivedCommonOrInstanceNodeTemplates() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - - var commonOrInstanceNodeTypeProps = - serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); - - var result = serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates( - inputServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(), commonOrInstanceNodeTypeProps); - - assertNotNull(result); - assertThat(result).hasSize(8); - } - - @Test - void testCreateServiceTemplate() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - when(serviceTemplateRepository.save(jpaServiceTemplate)).thenReturn(jpaServiceTemplate); - - var result = serviceTemplateProvider.createServiceTemplate(inputServiceTemplate); - - assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - @Test - void testDeleteServiceTemplate() throws PfModelException { - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository - .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) - .thenReturn(Optional.of(jpaServiceTemplate)); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - var result = serviceTemplateProvider.deleteServiceTemplate(inputServiceTemplate.getName(), - inputServiceTemplate.getVersion()); - - assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - @Test - void testGetServiceTemplateListEmpty() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository.findById(any())).thenReturn(Optional.empty()); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - assertThatThrownBy(() -> serviceTemplateProvider.getToscaServiceTemplate("Name", "1.0.0")) - .hasMessage("Control Loop definitions not found"); - } - - @Test - void testGetServiceTemplateList() throws PfModelException { - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository - .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) - .thenReturn(Optional.of(jpaServiceTemplate)); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - var result = serviceTemplateProvider.getToscaServiceTemplate(inputServiceTemplate.getName(), - inputServiceTemplate.getVersion()); - - assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - @Test - void testGetServiceTemplate() throws PfModelException { - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, inputServiceTemplate.getName(), - inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate)); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - var result = serviceTemplateProvider.getServiceTemplateList(inputServiceTemplate.getName(), - inputServiceTemplate.getVersion()); - - assertThat(result).hasSize(1); - assertThat(result.get(0)).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - /** - * Get ToscaServiceTemplate from resource. - * - * @param path path of the resource - */ - public static ToscaServiceTemplate getToscaServiceTemplate(String path) { - - try { - return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); - } catch (CoderException e) { - fail("Cannot read or decode " + path); - return null; - } - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java deleted file mode 100644 index 8b5357457..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.repository; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ProviderUtils; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.dao.PfDao; -import org.onap.policy.models.dao.PfFilterParameters; -import org.onap.policy.models.provider.PolicyModelsProviderParameters; -import org.onap.policy.models.provider.impl.ModelsProvider; - -class FilterRepositoryImplTest { - private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; - private static final Coder CODER = new StandardCoder(); - private static final AtomicInteger dbNameCounter = new AtomicInteger(); - private static final String originalJson = ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON); - private static List jpaControlLoops; - private PfDao pfDao; - - @BeforeEach - void beforeSetupDao() throws Exception { - var 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"); - - pfDao = ModelsProvider.init(parameters); - var inputControlLoops = CODER.decode(originalJson, ControlLoops.class); - jpaControlLoops = ProviderUtils.getJpaAndValidateList(inputControlLoops.getControlLoopList(), - JpaControlLoop::new, "ControlLoops"); - - pfDao.createCollection(jpaControlLoops); - } - - @Test - void testGetPfDao() { - assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull(); - } - - @Test - void testGetFilteredParams() { - var filterRepositoryImpl = new FilterRepositoryImpl() { - @Override - protected PfDao getPfDao() { - return pfDao; - } - }; - var result = filterRepositoryImpl.getFiltered(JpaControlLoop.class, null, null); - assertThat(result).hasSize(2); - - result = filterRepositoryImpl.getFiltered(JpaControlLoop.class, jpaControlLoops.get(0).getName(), null); - assertThat(result).hasSize(1); - } - - @Test - void testGetFiltered() { - var filterRepositoryImpl = new FilterRepositoryImpl() { - @Override - protected PfDao getPfDao() { - return pfDao; - } - }; - - // @formatter:off - PfFilterParameters filterParams = PfFilterParameters - .builder() - .name(jpaControlLoops.get(0).getName()) - .build(); - // @formatter:on - - var result = filterRepositoryImpl.getFiltered(JpaControlLoop.class, filterParams); - assertThat(result).hasSize(1); - } -} 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 deleted file mode 100644 index bf2e2fa0a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============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.jupiter.api.Test; - -class ControlLoopNotificationTest { - - @Test - void testControlLoopNotification() { - ControlLoopNotification cln0 = new ControlLoopNotification(); - - List addedList = new ArrayList<>(); - addedList.add(new ControlLoopStatus()); - - List 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 - 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 deleted file mode 100644 index cca5e8554..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopStatusTest { - - @Test - 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 deleted file mode 100644 index 1a89a1b3e..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class NotificationPojosTest { - - @Test - void testPojos() { - List 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/ControlLoopAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java deleted file mode 100644 index f312c4863..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementAck; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ControlLoopAck((ControlLoopAck) null)) - .isInstanceOf(NullPointerException.class); - - final var orig = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_UPDATE); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopAck(orig).toString())); - - // verify with all values - var id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setParticipantType(id); - var clElementResult = new ControlLoopElementAck(ControlLoopState.UNINITIALISED, - true, "ControlLoopElement result"); - final var controlLoopResultMap = Map.of(UUID.randomUUID(), clElementResult); - orig.setControlLoopResultMap(controlLoopResultMap); - - orig.setResponseTo(UUID.randomUUID()); - orig.setResult(true); - orig.setMessage("Successfully processed ControlLoopUpdate message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopAck(orig).toString())); - - assertSerializable(orig, ControlLoopAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java deleted file mode 100644 index 1bf155e9a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the copy constructor and other methods. - */ -class ControlLoopStateChangeTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ControlLoopStateChange(null)).isInstanceOf(NullPointerException.class); - - ControlLoopStateChange orig = new ControlLoopStateChange(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopStateChange(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setMessageId(UUID.randomUUID()); - orig.setOrderedState(ControlLoopOrderedState.RUNNING); - orig.setCurrentState(ControlLoopState.PASSIVE); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopStateChange(orig).toString())); - - assertSerializable(orig, ControlLoopStateChange.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java deleted file mode 100644 index ce56d582a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.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.ParticipantUpdates; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; - -/** - * Test the copy constructor. - */ -class ControlLoopUpdateTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ControlLoopUpdate(null)).isInstanceOf(NullPointerException.class); - - ControlLoopUpdate orig = new ControlLoopUpdate(); - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(null); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ControlLoopElement clElement = new ControlLoopElement(); - clElement.setId(UUID.randomUUID()); - clElement.setDefinition(id); - clElement.setDescription("Description"); - clElement.setOrderedState(ControlLoopOrderedState.PASSIVE); - clElement.setState(ControlLoopState.PASSIVE); - clElement.setParticipantId(id); - clElement.setParticipantType(id); - - ToscaProperty property = new ToscaProperty(); - property.setName("test"); - property.setType("testType"); - Map propertiesMap = Map.of("Prop1", property); - clElement.setPropertiesMap(propertiesMap); - - ParticipantUpdates participantUpdates = new ParticipantUpdates(); - participantUpdates.setParticipantId(id); - participantUpdates.setControlLoopElementList(List.of(clElement)); - orig.setParticipantUpdatesList(List.of(participantUpdates)); - - ControlLoopUpdate other = new ControlLoopUpdate(orig); - - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - assertSerializable(orig, ControlLoopUpdate.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java deleted file mode 100644 index df82ab071..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============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 static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantAckMessageTest { - private ParticipantAckMessage message; - - private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); - private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); - private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); - private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantAckMessage((ParticipantAckMessage) null)) - .isInstanceOf(NullPointerException.class); - - // verify with null values - message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); - ParticipantAckMessage newmsg = new ParticipantAckMessage(message); - newmsg.setResponseTo(message.getResponseTo()); - assertEquals(message.toString(), newmsg.toString()); - - // verify with all values - message = makeMessage(); - newmsg = new ParticipantAckMessage(message); - newmsg.setResponseTo(message.getResponseTo()); - assertEquals(message.toString(), newmsg.toString()); - - assertSerializable(message, ParticipantAckMessage.class); - } - - @Test - void testAppliesTo_NullParticipantId() { - message = makeMessage(); - - assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); - } - - @Test - void testAppliesTo_ParticipantIdMatches() { - message = makeMessage(); - - // ParticipantId matches - assertTrue(message.appliesTo(PTYPE_456, ID_123)); - assertFalse(message.appliesTo(PTYPE_456, ID_124)); - assertFalse(message.appliesTo(PTYPE_457, ID_123)); - } - - @Test - 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 ParticipantAckMessage makeMessage() { - ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); - - msg.setParticipantType(PTYPE_456); - msg.setParticipantId(ID_123); - msg.setMessage("Successfull Ack"); - msg.setResult(true); - msg.setResponseTo(UUID.randomUUID()); - - return msg; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java deleted file mode 100644 index f1ae5f709..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantDeregisterAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantDeregisterAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantDeregisterAck orig = new ParticipantDeregisterAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregisterAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregisterAck(orig).toString())); - - assertSerializable(orig, ParticipantDeregisterAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java deleted file mode 100644 index 89546890a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantDeregisterTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantDeregister(null)).isInstanceOf(NullPointerException.class); - - final ParticipantDeregister orig = new ParticipantDeregister(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregister(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.setParticipantType(id); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregister(orig).toString())); - - assertSerializable(orig, ParticipantDeregister.class); - } -} 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 deleted file mode 100644 index 58d3afebc..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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 static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantMessageTest { - private ParticipantMessage message; - - private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); - private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); - private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); - private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); - - @Test - void testCopyConstructor() throws CoderException { - 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()); - - assertSerializable(message, ParticipantMessage.class); - } - - @Test - void testAppliesTo_NullParticipantId() { - message = makeMessage(); - - assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); - } - - @Test - void testAppliesTo_ParticipantIdMatches() { - message = makeMessage(); - - // ParticipantId matches - assertTrue(message.appliesTo(PTYPE_456, ID_123)); - assertFalse(message.appliesTo(PTYPE_456, ID_124)); - assertFalse(message.appliesTo(PTYPE_457, ID_123)); - } - - @Test - 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(PTYPE_456); - msg.setParticipantId(ID_123); - 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 deleted file mode 100644 index 78c278f98..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============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.junit.Assert.assertEquals; - -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; - -/** - * 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"); - } - - /** - * Check if object is Serializable. - * - * @param object the Object - * @param clazz the class of the Object - * @throws CoderException if object is not Serializable - */ - public static void assertSerializable(Object object, Class clazz) throws CoderException { - var standardCoder = new StandardCoder(); - var json = standardCoder.encode(object); - var other = standardCoder.decode(json, clazz); - - assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString())); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java deleted file mode 100644 index e67fbc143..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class ParticipantPojosTest { - - @Test - void testPojos() { - List pojoClasses = - PojoClassFactory.getPojoClasses(ParticipantPojosTest.class.getPackageName()); - - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessage.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAck.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAckTest.class)); - - // @formatter:off - final Validator validator = ValidatorBuilder - .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/ParticipantRegisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java deleted file mode 100644 index 886933aba..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantRegisterAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantRegisterAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantRegisterAck orig = new ParticipantRegisterAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegisterAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_REGISTER_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegisterAck(orig).toString())); - - assertSerializable(orig, ParticipantRegisterAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java deleted file mode 100644 index e86d9e885..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantRegisterTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantRegister(null)).isInstanceOf(NullPointerException.class); - - final ParticipantRegister orig = new ParticipantRegister(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegister(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.setParticipantType(id); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegister(orig).toString())); - - assertSerializable(orig, ParticipantRegister.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java deleted file mode 100644 index 98c127107..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the copy constructor. - */ -class ParticipantStatusReqTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class); - - ParticipantStatusReq orig = new ParticipantStatusReq(); - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setParticipantId(id); - orig.setControlLoopId(null); - orig.setParticipantType(null); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ParticipantStatusReq other = new ParticipantStatusReq(orig); - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - - assertSerializable(orig, ParticipantStatusReq.class); - } -} 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 deleted file mode 100644 index b2bce05cc..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; - -class ParticipantStatusTest { - - @Test - void testCopyConstructor() throws CoderException { - 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", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4"); - orig.setParticipantType(type); - orig.setMessageId(UUID.randomUUID()); - orig.setState(ParticipantState.ACTIVE); - orig.setHealthStatus(ParticipantHealthStatus.HEALTHY); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ControlLoopInfo clInfo = getControlLoopInfo(id); - orig.setControlLoopInfoList(List.of(clInfo)); - - ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); - participantDefinitionUpdate.setParticipantId(id); - participantDefinitionUpdate.setParticipantType(type); - ControlLoopElementDefinition clDefinition = getClElementDefinition(id); - participantDefinitionUpdate.setControlLoopElementDefinitionList(List.of(clDefinition)); - orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantStatus(orig).toString())); - - assertSerializable(orig, ParticipantStatus.class); - } - - private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) { - ControlLoopInfo clInfo = new ControlLoopInfo(); - clInfo.setState(ControlLoopState.PASSIVE2RUNNING); - clInfo.setControlLoopId(id); - - ControlLoopStatistics clStatistics = new ControlLoopStatistics(); - clStatistics.setControlLoopId(id); - clStatistics.setAverageExecutionTime(12345); - clStatistics.setEventCount(12345); - clStatistics.setLastEnterTime(12345); - clStatistics.setLastExecutionTime(12345); - clStatistics.setLastStart(12345); - clStatistics.setTimeStamp(Instant.ofEpochMilli(3000)); - clStatistics.setUpTime(12345); - ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList(); - ClElementStatistics clElementStatistics = new ClElementStatistics(); - clElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - clElementStatistics.setTimeStamp(Instant.now()); - clElementStatisticsList.setClElementStatistics(List.of(clElementStatistics)); - clStatistics.setClElementStatisticsList(clElementStatisticsList); - - clInfo.setControlLoopStatistics(clStatistics); - return clInfo; - } - - private ControlLoopElementDefinition getClElementDefinition(ToscaConceptIdentifier id) { - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(id); - clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate); - - ToscaProperty property = new ToscaProperty(); - property.setName("test"); - property.setType("testType"); - Map commonPropertiesMap = Map.of("Prop1", property); - clDefinition.setCommonPropertiesMap(commonPropertiesMap); - return clDefinition; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java deleted file mode 100644 index d2a191018..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantUpdateAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantUpdateAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantUpdateAck orig = new ParticipantUpdateAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantUpdateAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantUpdateAck(orig).toString())); - - assertSerializable(orig, ParticipantUpdateAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java deleted file mode 100644 index d7023d0c1..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * ============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.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -/** - * Test the copy constructor. - */ -class ParticipantUpdateTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class); - - ParticipantUpdate orig = new ParticipantUpdate(); - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setParticipantType(id); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); - toscaServiceTemplate.setName("serviceTemplate"); - toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); - toscaServiceTemplate.setDescription("Description of serviceTemplate"); - toscaServiceTemplate.setVersion("1.2.3"); - - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); - participantDefinitionUpdate.setParticipantType(id); - ControlLoopElementDefinition clDefinition = getClElementDefinition(id); - participantDefinitionUpdate.setControlLoopElementDefinitionList(List.of(clDefinition)); - orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); - - ParticipantUpdate other = new ParticipantUpdate(orig); - - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - - assertSerializable(orig, ParticipantUpdate.class); - } - - private ControlLoopElementDefinition getClElementDefinition(ToscaConceptIdentifier id) { - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(id); - clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate); - - ToscaProperty property = new ToscaProperty(); - property.setName("test"); - property.setType("testType"); - Map commonPropertiesMap = Map.of("Prop1", property); - clDefinition.setCommonPropertiesMap(commonPropertiesMap); - return clDefinition; - } -} 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 deleted file mode 100644 index 435cce8ef..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class MessagesRestPojosTest { - - @Test - void testPojos() { - List 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 deleted file mode 100644 index c9902753f..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============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.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; - -class InstantiationCommandTest { - @Test - 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); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java deleted file mode 100644 index 4dedae200..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============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.rest; - -import static org.assertj.core.api.Assertions.assertThat; - -import javax.ws.rs.core.Response.Status; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.errors.concepts.ErrorResponse; -import org.onap.policy.models.errors.concepts.ErrorResponseInfo; - -class RestUtilsTest { - - private static final String MESSAGE_ERROR = "Erorr"; - private static final Status STATUS_ERROR = Status.BAD_REQUEST; - - @Test - void testToSimpleResponse() { - var ex = new ErrorResponseInfo() { - - @Override - public ErrorResponse getErrorResponse() { - var er = new ErrorResponse(); - er.setErrorMessage(MESSAGE_ERROR); - er.setResponseCode(STATUS_ERROR); - return er; - } - }; - - var response = RestUtils.toSimpleResponse(ex); - - assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode()); - assertThat(response.getBody()).isNotNull(); - assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java new file mode 100644 index 000000000..ee79b27b7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.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.models.acm.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.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AcElementStatisticsTest { + @Test + void testAcElementStatisticsLombok() { + assertNotNull(new AcElementStatistics()); + AcElementStatistics aces0 = new AcElementStatistics(); + + assertThat(aces0.toString()).contains("AcElementStatistics("); + assertThat(aces0.hashCode()).isNotZero(); + assertEquals(true, aces0.equals(aces0)); + assertEquals(false, aces0.equals(null)); + + + AcElementStatistics aces1 = new AcElementStatistics(); + aces1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + aces1.setTimeStamp(Instant.now()); + + assertThat(aces1.toString()).contains("AcElementStatistics("); + assertEquals(false, aces1.hashCode() == 0); + assertEquals(false, aces1.equals(aces0)); + assertEquals(false, aces1.equals(null)); + + assertNotEquals(aces1, aces0); + + AcElementStatistics aces2 = new AcElementStatistics(); + aces2.setId(UUID.randomUUID()); + + // @formatter:off + assertThatThrownBy(() -> aces2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> aces2.setTimeStamp(null)).isInstanceOf(NullPointerException.class); + // @formatter:on + + assertNotEquals(aces2, aces0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java new file mode 100644 index 000000000..1d45e5919 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.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.models.acm.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.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class AutomationCompositionConceptPojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClasses(AutomationCompositionConceptPojosTest.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/models/acm/concepts/AutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java new file mode 100644 index 000000000..4e739db52 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.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.models.acm.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.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionElementTest { + @Test + void testAutomationCompositionElement() { + var ace0 = new AutomationCompositionElement(); + var ace1 = new AutomationCompositionElement(ace0); + assertEquals(ace0, ace1); + + ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + ace1.setDescription("Description"); + ace1.setId(UUID.randomUUID()); + ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ace1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); + ace1.setState(AutomationCompositionState.UNINITIALISED); + + var ace2 = new AutomationCompositionElement(ace1); + assertEquals(ace1, ace2); + } + + @Test + void testAutomationCompositionState() { + var ace0 = new AutomationCompositionElement(); + + assertTrue( + ace0.getOrderedState() + .equalsAutomationCompositionState(AutomationCompositionState.UNINITIALISED)); + + assertTrue( + ace0.getOrderedState().asState() + .equalsAutomationCompositionOrderedState(AutomationCompositionOrderedState.UNINITIALISED)); + } + + @Test + void testAutomationCompositionElementLombok() { + assertNotNull(new AutomationCompositionElement()); + var ace0 = new AutomationCompositionElement(); + + assertThat(ace0.toString()).contains("AutomationCompositionElement("); + assertThat(ace0.hashCode()).isNotZero(); + assertEquals(true, ace0.equals(ace0)); + assertEquals(false, ace0.equals(null)); + + var ace1 = new AutomationCompositionElement(); + + ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + ace1.setDescription("Description"); + ace1.setId(UUID.randomUUID()); + ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ace1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); + ace1.setState(AutomationCompositionState.UNINITIALISED); + + assertThat(ace1.toString()).contains("AutomationCompositionElement("); + assertEquals(false, ace1.hashCode() == 0); + assertEquals(false, ace1.equals(ace0)); + assertEquals(false, ace1.equals(null)); + + assertNotEquals(ace1, ace0); + + var ace2 = new AutomationCompositionElement(); + + // @formatter:off + assertThatThrownBy(() -> ace2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setId(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setOrderedState(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setState(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertNotEquals(ace2, ace0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java new file mode 100644 index 000000000..ad8a1bbea --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.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.models.acm.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.time.Instant; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionTest { + @Test + void testAutomationComposition() { + var ac0 = new AutomationComposition(); + ac0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); + assertEquals("dfName", ac0.getType()); + assertEquals("1.2.3", ac0.getTypeVersion()); + + var ac1 = new AutomationComposition(ac0); + assertEquals(ac0, ac1); + + assertEquals(0, ac0.compareTo(ac1)); + } + + @Test + void testAutomationCompositionLombok() { + assertNotNull(new AutomationComposition()); + var ac0 = new AutomationComposition(); + ac0.setElements(new LinkedHashMap<>()); + + assertThat(ac0.toString()).contains("AutomationComposition("); + assertThat(ac0.hashCode()).isNotZero(); + assertEquals(true, ac0.equals(ac0)); + assertEquals(false, ac0.equals(null)); + + var ac1 = new AutomationComposition(); + + ac1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + ac1.setDescription("Description"); + ac1.setElements(new LinkedHashMap<>()); + ac1.setName("Name"); + ac1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ac1.setState(AutomationCompositionState.UNINITIALISED); + ac1.setVersion("0.0.1"); + + assertThat(ac1.toString()).contains("AutomationComposition("); + assertEquals(false, ac1.hashCode() == 0); + assertEquals(false, ac1.equals(ac0)); + assertEquals(false, ac1.equals(null)); + + assertNotEquals(ac1, ac0); + + var ac2 = new AutomationComposition(); + ac2.setElements(new LinkedHashMap<>()); + + // @formatter:off + assertThatThrownBy(() -> ac2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(ac2, ac0); + + ac1.setCascadedOrderedState(AutomationCompositionOrderedState.PASSIVE); + assertEquals(AutomationCompositionOrderedState.PASSIVE, ac1.getOrderedState()); + + ac1.getElements().put(UUID.randomUUID(), new AutomationCompositionElement()); + ac1.setCascadedOrderedState(AutomationCompositionOrderedState.RUNNING); + assertEquals(AutomationCompositionOrderedState.RUNNING, ac1.getOrderedState()); + assertEquals(AutomationCompositionOrderedState.RUNNING, + ac1.getElements().values().iterator().next().getOrderedState()); + + assertNull(ac0.getElements().get(UUID.randomUUID())); + assertNull(ac1.getElements().get(UUID.randomUUID())); + + assertEquals(PfKey.NULL_KEY_NAME, ac0.getDefinition().getName()); + + } + + @Test + void testAutomationCompositionElementStatisticsList() { + var ac = new AutomationComposition(); + List emptylist = ac.getAutomationCompositionElementStatisticsList(ac); + assertEquals(List.of(), emptylist); + + var ac1 = getAutomationCompositionTest(); + List list = ac1.getAutomationCompositionElementStatisticsList(ac1); + assertNotNull(list); + assertEquals(2, list.size()); + assertEquals(AutomationCompositionState.UNINITIALISED, list.get(0).getState()); + } + + private AutomationComposition getAutomationCompositionTest() { + var ac = new AutomationComposition(); + ac.setDefinition(new ToscaConceptIdentifier("defName", "1.2.3")); + ac.setDescription("Description"); + ac.setElements(new LinkedHashMap<>()); + ac.setName("Name"); + ac.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ac.setState(AutomationCompositionState.UNINITIALISED); + ac.setVersion("0.0.1"); + + var uuid = UUID.randomUUID(); + var id = new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1"); + var acElement = getAutomationCompositionElementTest(uuid, id); + + var uuid2 = UUID.randomUUID(); + var id2 = new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipantIntermediary", + "0.0.1"); + var acElement2 = getAutomationCompositionElementTest(uuid2, id2); + + ac.getElements().put(uuid, acElement); + ac.getElements().put(uuid2, acElement2); + return ac; + } + + private AutomationCompositionElement getAutomationCompositionElementTest(UUID uuid, ToscaConceptIdentifier id) { + var acElement = new AutomationCompositionElement(); + acElement.setId(uuid); + acElement.setParticipantId(id); + acElement.setDefinition(id); + acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + var acElementStatistics = new AcElementStatistics(); + acElementStatistics.setParticipantId(id); + acElementStatistics.setState(AutomationCompositionState.UNINITIALISED); + acElementStatistics.setTimeStamp(Instant.now()); + + acElement.setAcElementStatistics(acElementStatistics); + + return acElement; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java new file mode 100644 index 000000000..de9b884d3 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantStatisticsTest { + @Test + 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/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java new file mode 100644 index 000000000..164c7c1a0 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantTest { + @Test + 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 + 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/models/acm/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java new file mode 100644 index 000000000..5252221a8 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.coder.StandardYamlCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +class ParticipantUtilsTest { + + private static final Coder CODER = new StandardCoder(); + private static final String TOSCA_TEMPLATE_YAML = "examples/acm/PMSubscriptionHandling.yaml"; + private static final String AUTOMATION_COMPOSITION_JSON = + "src/test/resources/providers/TestAutomationCompositions.json"; + private static final String AUTOMATION_COMPOSITION_ELEMENT = + "org.onap.policy.clamp.acm.AutomationCompositionElement"; + private static final String POLICY_AUTOMATION_COMPOSITION_ELEMENT = + "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement"; + private static final String PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT = "org.onap.policy.clamp.acm.Participant"; + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); + + @Test + void testFindParticipantType() throws CoderException { + var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1"); + var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier))); + assertThat(result).isEqualTo(identifier); + } + + @Test + void testFindStartPhase() { + var identifier = 13; + var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier)); + assertThat(result).isEqualTo(identifier); + } + + @Test + void testGetFirstStartPhase() throws CoderException { + var serviceTemplate = + YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), ToscaServiceTemplate.class); + var automationCompositions = + CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class); + var result = ParticipantUtils.getFirstStartPhase(automationCompositions.getAutomationCompositionList().get(0), + serviceTemplate); + assertThat(result).isZero(); + } + + @Test + void testCheckIfNodeTemplateIsAutomationCompositionElement() throws CoderException { + var serviceTemplate = + YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), ToscaServiceTemplate.class); + var nodeTemplate = new ToscaNodeTemplate(); + nodeTemplate.setType(AUTOMATION_COMPOSITION_ELEMENT); + assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)) + .isTrue(); + + nodeTemplate.setType(POLICY_AUTOMATION_COMPOSITION_ELEMENT); + assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)) + .isTrue(); + + nodeTemplate.setType(PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT); + assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)) + .isFalse(); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java new file mode 100644 index 000000000..49bb719ac --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.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.models.acm.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.jupiter.api.Test; + +class AutomationCompositionNotificationTest { + + @Test + void testAutomationCompositionNotification() { + AutomationCompositionNotification acn0 = new AutomationCompositionNotification(); + + List addedList = new ArrayList<>(); + addedList.add(new AutomationCompositionStatus()); + + List deletedList = new ArrayList<>(); + deletedList.add(new AutomationCompositionStatus()); + + assertEquals(true, acn0.isEmpty()); + + acn0.setAdded(addedList); + assertEquals(false, acn0.isEmpty()); + acn0.setAdded(null); + assertEquals(true, acn0.isEmpty()); + + acn0.setDeleted(deletedList); + assertEquals(false, acn0.isEmpty()); + acn0.setDeleted(null); + assertEquals(true, acn0.isEmpty()); + + acn0.setAdded(addedList); + acn0.setDeleted(deletedList); + assertEquals(false, acn0.isEmpty()); + acn0.setAdded(null); + acn0.setDeleted(null); + assertEquals(true, acn0.isEmpty()); + } + + @Test + void testAutomationCompositionNotificationLombok() { + assertNotNull(new AutomationCompositionNotification()); + assertNotNull(new AutomationCompositionNotification(new ArrayList<>(), new ArrayList<>())); + + AutomationCompositionNotification acn0 = new AutomationCompositionNotification(); + + assertThat(acn0.toString()).contains("AutomationCompositionNotification("); + assertEquals(false, acn0.hashCode() == 0); + assertEquals(true, acn0.equals(acn0)); + assertEquals(false, acn0.equals(null)); + + + AutomationCompositionNotification acn1 = new AutomationCompositionNotification(); + + assertThat(acn1.toString()).contains("AutomationCompositionNotification("); + assertEquals(false, acn1.hashCode() == 0); + assertEquals(true, acn1.equals(acn0)); + assertEquals(false, acn1.equals(null)); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java new file mode 100644 index 000000000..028566888 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.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.models.acm.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.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionStatusTest { + + @Test + void testAutomationCompositionStatusLombok() { + assertNotNull(new AutomationCompositionStatus()); + assertNotNull(new AutomationCompositionStatus(UUID.randomUUID(), new ToscaConceptIdentifier())); + + AutomationCompositionStatus acn0 = new AutomationCompositionStatus(); + + assertThat(acn0.toString()).contains("AutomationCompositionStatus("); + assertEquals(false, acn0.hashCode() == 0); + assertEquals(true, acn0.equals(acn0)); + assertEquals(false, acn0.equals(null)); + + AutomationCompositionStatus acn1 = new AutomationCompositionStatus(); + assertEquals(true, acn1.equals(acn0)); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java new file mode 100644 index 000000000..494252acc --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class NotificationPojosTest { + + @Test + void testPojos() { + List 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/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java new file mode 100644 index 000000000..383a55115 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementAck; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new AutomationCompositionAck((AutomationCompositionAck) null)) + .isInstanceOf(NullPointerException.class); + + final var orig = new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionAck(orig).toString())); + + // verify with all values + var id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + var acElementResult = new AutomationCompositionElementAck(AutomationCompositionState.UNINITIALISED, + true, "AutomationCompositionElement result"); + final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult); + orig.setAutomationCompositionResultMap(automationCompositionResultMap); + + orig.setResponseTo(UUID.randomUUID()); + orig.setResult(true); + orig.setMessage("Successfully processed AutomationCompositionUpdate message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionAck(orig).toString())); + + assertSerializable(orig, AutomationCompositionAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java new file mode 100644 index 000000000..6c48afad2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor and other methods. + */ +class AutomationCompositionStateChangeTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new AutomationCompositionStateChange(null)).isInstanceOf(NullPointerException.class); + + AutomationCompositionStateChange orig = new AutomationCompositionStateChange(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionStateChange(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setMessageId(UUID.randomUUID()); + orig.setOrderedState(AutomationCompositionOrderedState.RUNNING); + orig.setCurrentState(AutomationCompositionState.PASSIVE); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionStateChange(orig).toString())); + + assertSerializable(orig, AutomationCompositionStateChange.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java new file mode 100644 index 000000000..809256d40 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java @@ -0,0 +1,82 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; + +/** + * Test the copy constructor. + */ +class AutomationCompositionUpdateTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new AutomationCompositionUpdate(null)).isInstanceOf(NullPointerException.class); + + AutomationCompositionUpdate orig = new AutomationCompositionUpdate(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(null); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + AutomationCompositionElement acElement = new AutomationCompositionElement(); + acElement.setId(UUID.randomUUID()); + acElement.setDefinition(id); + acElement.setDescription("Description"); + acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + acElement.setState(AutomationCompositionState.PASSIVE); + acElement.setParticipantId(id); + acElement.setParticipantType(id); + + ToscaProperty property = new ToscaProperty(); + property.setName("test"); + property.setType("testType"); + Map propertiesMap = Map.of("Prop1", property); + acElement.setPropertiesMap(propertiesMap); + + ParticipantUpdates participantUpdates = new ParticipantUpdates(); + participantUpdates.setParticipantId(id); + participantUpdates.setAutomationCompositionElementList(List.of(acElement)); + orig.setParticipantUpdatesList(List.of(participantUpdates)); + + AutomationCompositionUpdate other = new AutomationCompositionUpdate(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + assertSerializable(orig, AutomationCompositionUpdate.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java new file mode 100644 index 000000000..89a34e33d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java @@ -0,0 +1,105 @@ +/*- + * ============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.models.acm.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 static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantAckMessageTest { + private ParticipantAckMessage message; + + private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); + private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); + private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); + private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantAckMessage((ParticipantAckMessage) null)) + .isInstanceOf(NullPointerException.class); + + // verify with null values + message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + ParticipantAckMessage newmsg = new ParticipantAckMessage(message); + newmsg.setResponseTo(message.getResponseTo()); + assertEquals(message.toString(), newmsg.toString()); + + // verify with all values + message = makeMessage(); + newmsg = new ParticipantAckMessage(message); + newmsg.setResponseTo(message.getResponseTo()); + assertEquals(message.toString(), newmsg.toString()); + + assertSerializable(message, ParticipantAckMessage.class); + } + + @Test + void testAppliesTo_NullParticipantId() { + message = makeMessage(); + + assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); + } + + @Test + void testAppliesTo_ParticipantIdMatches() { + message = makeMessage(); + + // ParticipantId matches + assertTrue(message.appliesTo(PTYPE_456, ID_123)); + assertFalse(message.appliesTo(PTYPE_456, ID_124)); + assertFalse(message.appliesTo(PTYPE_457, ID_123)); + } + + @Test + 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 ParticipantAckMessage makeMessage() { + ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); + + msg.setParticipantType(PTYPE_456); + msg.setParticipantId(ID_123); + msg.setMessage("Successfull Ack"); + msg.setResult(true); + msg.setResponseTo(UUID.randomUUID()); + + return msg; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java new file mode 100644 index 000000000..59a6d826b --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantDeregisterAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantDeregisterAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantDeregisterAck orig = new ParticipantDeregisterAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregisterAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregisterAck(orig).toString())); + + assertSerializable(orig, ParticipantDeregisterAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java new file mode 100644 index 000000000..873257696 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantDeregisterTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantDeregister(null)).isInstanceOf(NullPointerException.class); + + final ParticipantDeregister orig = new ParticipantDeregister(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregister(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregister(orig).toString())); + + assertSerializable(orig, ParticipantDeregister.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java new file mode 100644 index 000000000..fa16d145d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java @@ -0,0 +1,107 @@ +/*- + * ============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.models.acm.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 static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantMessageTest { + private ParticipantMessage message; + + private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); + private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); + private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); + private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); + + @Test + void testCopyConstructor() throws CoderException { + 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()); + + assertSerializable(message, ParticipantMessage.class); + } + + @Test + void testAppliesTo_NullParticipantId() { + message = makeMessage(); + + assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); + } + + @Test + void testAppliesTo_ParticipantIdMatches() { + message = makeMessage(); + + // ParticipantId matches + assertTrue(message.appliesTo(PTYPE_456, ID_123)); + assertFalse(message.appliesTo(PTYPE_456, ID_124)); + assertFalse(message.appliesTo(PTYPE_457, ID_123)); + } + + @Test + 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(PTYPE_456); + msg.setParticipantId(ID_123); + msg.setMessageId(UUID.randomUUID()); + msg.setTimestamp(Instant.ofEpochMilli(3000)); + + return msg; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java new file mode 100644 index 000000000..4ff4f3b35 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java @@ -0,0 +1,55 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.junit.Assert.assertEquals; + +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; + +/** + * 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"); + } + + /** + * Check if object is Serializable. + * + * @param object the Object + * @param clazz the class of the Object + * @throws CoderException if object is not Serializable + */ + public static void assertSerializable(Object object, Class clazz) throws CoderException { + var standardCoder = new StandardCoder(); + var json = standardCoder.encode(object); + var other = standardCoder.decode(json, clazz); + + assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString())); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java new file mode 100644 index 000000000..ce23a821f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.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.models.acm.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.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class ParticipantPojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClasses(ParticipantPojosTest.class.getPackageName()); + + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessage.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(AutomationCompositionAck.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(AutomationCompositionAckTest.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/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java new file mode 100644 index 000000000..10200d86f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantRegisterAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantRegisterAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantRegisterAck orig = new ParticipantRegisterAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegisterAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_REGISTER_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegisterAck(orig).toString())); + + assertSerializable(orig, ParticipantRegisterAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java new file mode 100644 index 000000000..d08acda47 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantRegisterTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantRegister(null)).isInstanceOf(NullPointerException.class); + + final ParticipantRegister orig = new ParticipantRegister(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegister(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegister(orig).toString())); + + assertSerializable(orig, ParticipantRegister.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java new file mode 100644 index 000000000..92025a707 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java @@ -0,0 +1,56 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor. + */ +class ParticipantStatusReqTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class); + + ParticipantStatusReq orig = new ParticipantStatusReq(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setParticipantId(id); + orig.setAutomationCompositionId(null); + orig.setParticipantType(null); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + ParticipantStatusReq other = new ParticipantStatusReq(orig); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + + assertSerializable(orig, ParticipantStatusReq.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java new file mode 100644 index 000000000..a33c12f2e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java @@ -0,0 +1,129 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionStatistics; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; + +class ParticipantStatusTest { + + @Test + void testCopyConstructor() throws CoderException { + 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", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4"); + orig.setParticipantType(type); + orig.setMessageId(UUID.randomUUID()); + orig.setState(ParticipantState.ACTIVE); + orig.setHealthStatus(ParticipantHealthStatus.HEALTHY); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + AutomationCompositionInfo acInfo = getAutomationCompositionInfo(id); + orig.setAutomationCompositionInfoList(List.of(acInfo)); + + ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); + participantDefinitionUpdate.setParticipantId(id); + participantDefinitionUpdate.setParticipantType(type); + AutomationCompositionElementDefinition acDefinition = getAcElementDefinition(id); + participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); + orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStatus(orig).toString())); + + assertSerializable(orig, ParticipantStatus.class); + } + + private AutomationCompositionInfo getAutomationCompositionInfo(ToscaConceptIdentifier id) { + AutomationCompositionInfo acInfo = new AutomationCompositionInfo(); + acInfo.setState(AutomationCompositionState.PASSIVE2RUNNING); + acInfo.setAutomationCompositionId(id); + + AutomationCompositionStatistics acStatistics = new AutomationCompositionStatistics(); + acStatistics.setAutomationCompositionId(id); + acStatistics.setAverageExecutionTime(12345); + acStatistics.setEventCount(12345); + acStatistics.setLastEnterTime(12345); + acStatistics.setLastExecutionTime(12345); + acStatistics.setLastStart(12345); + acStatistics.setTimeStamp(Instant.ofEpochMilli(3000)); + acStatistics.setUpTime(12345); + AcElementStatisticsList acElementStatisticsList = new AcElementStatisticsList(); + AcElementStatistics acElementStatistics = new AcElementStatistics(); + acElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + acElementStatistics.setTimeStamp(Instant.now()); + acElementStatisticsList.setAcElementStatistics(List.of(acElementStatistics)); + acStatistics.setAcElementStatisticsList(acElementStatisticsList); + + acInfo.setAutomationCompositionStatistics(acStatistics); + return acInfo; + } + + private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { + ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + AutomationCompositionElementDefinition acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(id); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + + ToscaProperty property = new ToscaProperty(); + property.setName("test"); + property.setType("testType"); + Map commonPropertiesMap = Map.of("Prop1", property); + acDefinition.setCommonPropertiesMap(commonPropertiesMap); + return acDefinition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java new file mode 100644 index 000000000..9f011a383 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantUpdateAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantUpdateAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantUpdateAck orig = new ParticipantUpdateAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantUpdateAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantUpdateAck(orig).toString())); + + assertSerializable(orig, ParticipantUpdateAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java new file mode 100644 index 000000000..f8aaffe11 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java @@ -0,0 +1,101 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Test the copy constructor. + */ +class ParticipantUpdateTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class); + + ParticipantUpdate orig = new ParticipantUpdate(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); + toscaServiceTemplate.setName("serviceTemplate"); + toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); + toscaServiceTemplate.setDescription("Description of serviceTemplate"); + toscaServiceTemplate.setVersion("1.2.3"); + + ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); + participantDefinitionUpdate.setParticipantType(id); + AutomationCompositionElementDefinition acDefinition = getAcElementDefinition(id); + participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); + orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); + + ParticipantUpdate other = new ParticipantUpdate(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + + assertSerializable(orig, ParticipantUpdate.class); + } + + private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { + ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + AutomationCompositionElementDefinition acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(id); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + + ToscaProperty property = new ToscaProperty(); + property.setName("test"); + property.setType("testType"); + Map commonPropertiesMap = Map.of("Prop1", property); + acDefinition.setCommonPropertiesMap(commonPropertiesMap); + return acDefinition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java new file mode 100644 index 000000000..4503be783 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class MessagesRestPojosTest { + + @Test + void testPojos() { + List 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/models/acm/messages/rest/instantiation/InstantiationCommandTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java new file mode 100644 index 000000000..348359743 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; + +class InstantiationCommandTest { + @Test + 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.setAutomationCompositionIdentifierList(new ArrayList<>()); + ic1.setOrderedState(AutomationCompositionOrderedState.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); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java new file mode 100644 index 000000000..ebbaf1d42 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaAcElementStatistics} comparisons. + */ +class DummyJpaAcElementStatisticsChild extends JpaAcElementStatistics { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java new file mode 100644 index 000000000..c7f4351c7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaAutomationComposition} comparisons. + */ +class DummyJpaAutomationCompositionChild extends JpaAutomationComposition { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java new file mode 100644 index 000000000..86723d98f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaAutomationCompositionElement} comparisons. + */ +class DummyJpaAutomationCompositionElementChild extends JpaAutomationCompositionElement { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java new file mode 100644 index 000000000..6b34cc44e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaParticipant} comparisons. + */ +class DummyJpaParticipantChild extends JpaParticipant { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java new file mode 100644 index 000000000..95082cac7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaParticipantStatistics} comparisons. + */ +class DummyJpaParticipantStatisticsChild extends JpaParticipantStatistics { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java new file mode 100644 index 000000000..4cf7b8af0 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.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.models.acm.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.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.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 JpaAcElementStatistics} class. + */ +class JpaAcElementStatisticsTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaAcElementStatisticsConstructor() { + assertThatThrownBy(() -> { + new JpaAcElementStatistics((JpaAcElementStatistics) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics((PfReferenceTimestampKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics(null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics(null, new PfConceptKey()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics(new PfReferenceTimestampKey(), null); + }).hasMessageMatching("participantId is marked .*ull but is null"); + + assertNotNull(new JpaAcElementStatistics()); + assertNotNull(new JpaAcElementStatistics((new PfReferenceTimestampKey()))); + assertNotNull(new JpaAcElementStatistics(new PfReferenceTimestampKey(), new PfConceptKey())); + } + + @Test + void testJpaAcElementStatistics() { + JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); + + AcElementStatistics aces = createAcElementStatisticsInstance(); + assertEquals(aces, testJpaAcElementStatistics.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaAcElementStatistics.fromAuthorative(null); + }).hasMessageMatching("acElementStatistics is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaAcElementStatistics((JpaAcElementStatistics) null)) + .isInstanceOf(NullPointerException.class); + + JpaAcElementStatistics testJpaAcElementStatisticsFa = new JpaAcElementStatistics(); + testJpaAcElementStatisticsFa.setKey(null); + testJpaAcElementStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + testJpaAcElementStatisticsFa.setKey(PfReferenceTimestampKey.getNullKey()); + testJpaAcElementStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + testJpaAcElementStatisticsFa.setKey(new PfReferenceTimestampKey("elementName", "0.0.1", + "a95757ba-b34a-4049-a2a8-46773abcbe5e", Instant.ofEpochSecond(123456L))); + testJpaAcElementStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + + testJpaAcElementStatisticsFa = new JpaAcElementStatistics(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + + assertEquals(1, testJpaAcElementStatistics.getKeys().size()); + + assertEquals("elementName", testJpaAcElementStatistics.getKey().getReferenceKey().getParentKeyName()); + + testJpaAcElementStatistics.clean(); + assertEquals("elementName", testJpaAcElementStatistics.getKey().getReferenceKey().getParentKeyName()); + + JpaAcElementStatistics testJpaAcElementStatistics2 = new JpaAcElementStatistics(testJpaAcElementStatistics); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatistics2); + } + + @Test + void testJpaAcElementStatisticsValidation() { + JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); + + assertThatThrownBy(() -> { + testJpaAcElementStatistics.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaAcElementStatistics.validate("").isValid()); + } + + @Test + void testJpaAcElementStatisticsCompareTo() { + JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); + + JpaAcElementStatistics otherJpaAcElementStatistics = new JpaAcElementStatistics(testJpaAcElementStatistics); + assertEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); + assertEquals(-1, testJpaAcElementStatistics.compareTo(null)); + assertEquals(0, testJpaAcElementStatistics.compareTo(testJpaAcElementStatistics)); + assertNotEquals(0, testJpaAcElementStatistics.compareTo(new DummyJpaAcElementStatisticsChild())); + + testJpaAcElementStatistics.setState(AutomationCompositionState.PASSIVE); + assertNotEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); + testJpaAcElementStatistics.setState(AutomationCompositionState.UNINITIALISED); + assertEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); + + assertEquals(testJpaAcElementStatistics, new JpaAcElementStatistics(testJpaAcElementStatistics)); + } + + @Test + void testJpaAcElementStatisticsLombok() { + assertNotNull(new Participant()); + JpaAcElementStatistics aces0 = new JpaAcElementStatistics(); + + assertThat(aces0.toString()).contains("JpaAcElementStatistics("); + assertThat(aces0.hashCode()).isNotZero(); + assertEquals(true, aces0.equals(aces0)); + assertEquals(false, aces0.equals(null)); + + + JpaAcElementStatistics aces11 = new JpaAcElementStatistics(); + + aces11.setState(AutomationCompositionState.UNINITIALISED); + + assertThat(aces11.toString()).contains("JpaAcElementStatistics("); + assertEquals(false, aces11.hashCode() == 0); + assertEquals(false, aces11.equals(aces0)); + assertEquals(false, aces11.equals(null)); + + assertNotEquals(aces11, aces0); + + JpaAcElementStatistics aces2 = new JpaAcElementStatistics(); + assertEquals(aces2, aces0); + } + + private JpaAcElementStatistics createJpaAcElementStatisticsInstance() { + AcElementStatistics testAces = createAcElementStatisticsInstance(); + JpaAcElementStatistics testJpaAcElementStatistics = new JpaAcElementStatistics(); + testJpaAcElementStatistics.setKey(null); + testJpaAcElementStatistics.fromAuthorative(testAces); + testJpaAcElementStatistics.setKey(PfReferenceTimestampKey.getNullKey()); + testJpaAcElementStatistics.fromAuthorative(testAces); + + return testJpaAcElementStatistics; + } + + private AcElementStatistics createAcElementStatisticsInstance() { + AcElementStatistics acElementStatistics = new AcElementStatistics(); + acElementStatistics.setParticipantId(new ToscaConceptIdentifier("elementName", "0.0.1")); + acElementStatistics.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); + acElementStatistics.setTimeStamp(Instant.ofEpochSecond(123456L)); + acElementStatistics.setState(AutomationCompositionState.UNINITIALISED); + + return acElementStatistics; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java new file mode 100644 index 000000000..f4257bdd2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java @@ -0,0 +1,315 @@ +/*- + * ============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.models.acm.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.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaAutomationCompositionElement} class. + */ +class JpaAutomationCompositionElementTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaAutomationCompositionElementConstructor() { + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement((PfReferenceKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, null, AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"), + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), null, + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), + null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, null, + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), + null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("participantType is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null, + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching("participantType is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), + new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertNotNull(new JpaAutomationCompositionElement()); + assertNotNull(new JpaAutomationCompositionElement((new PfReferenceKey()))); + assertNotNull(new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), + new PfConceptKey("participant", "0.0.1"), AutomationCompositionState.UNINITIALISED)); + } + + @Test + void testJpaAutomationCompositionElement() { + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + AutomationCompositionElement ace = createAutomationCompositionElementInstance(); + assertEquals(ace, testJpaAutomationCompositionElement.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaAutomationCompositionElement.fromAuthorative(null); + }).hasMessageMatching("element is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null)) + .isInstanceOf(NullPointerException.class); + + JpaAutomationCompositionElement testJpaAutomationCompositionElementFa = new JpaAutomationCompositionElement(); + testJpaAutomationCompositionElementFa.setKey(null); + testJpaAutomationCompositionElementFa.fromAuthorative(ace); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa); + testJpaAutomationCompositionElementFa.setKey(PfReferenceKey.getNullKey()); + testJpaAutomationCompositionElementFa.fromAuthorative(ace); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa); + testJpaAutomationCompositionElementFa.setKey( + new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + testJpaAutomationCompositionElementFa.fromAuthorative(ace); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa); + + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + testJpaAutomationCompositionElement.getKey().getLocalName()); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + new JpaAutomationCompositionElement(createAutomationCompositionElementInstance()).getKey().getLocalName()); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + ((PfReferenceKey) new JpaAutomationCompositionElement(createAutomationCompositionElementInstance()) + .getKeys().get(0)).getLocalName()); + + testJpaAutomationCompositionElement.clean(); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + testJpaAutomationCompositionElement.getKey().getLocalName()); + + testJpaAutomationCompositionElement.setDescription(" A Message "); + testJpaAutomationCompositionElement.clean(); + assertEquals("A Message", testJpaAutomationCompositionElement.getDescription()); + + JpaAutomationCompositionElement testJpaAutomationCompositionElement2 = + new JpaAutomationCompositionElement(testJpaAutomationCompositionElement); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElement2); + } + + @Test + void testJpaAutomationCompositionElementOrderedState() throws CoderException { + AutomationCompositionElement testAutomationCompositionElement = createAutomationCompositionElementInstance(); + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + testJpaAutomationCompositionElement.setOrderedState(null); + assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative()); + testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + AutomationCompositionElement noOrderedStateAce = new StandardCoder().decode( + new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), + AutomationCompositionElement.class); + + JpaAutomationCompositionElement noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce); + assertNull(noOrderedStateJpaAce.getOrderedState()); + noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce); + assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce); + } + + @Test + void testJpaAutomationCompositionElementValidation() { + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + assertThatThrownBy(() -> { + testJpaAutomationCompositionElement.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaAutomationCompositionElement.validate("").isValid()); + } + + @Test + void testJpaAutomationCompositionElementCompareTo() { + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + JpaAutomationCompositionElement otherJpaAutomationCompositionElement = + new JpaAutomationCompositionElement(testJpaAutomationCompositionElement); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null)); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement)); + assertNotEquals(0, + testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild())); + + testJpaAutomationCompositionElement + .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setKey( + new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("aceDef", "0.0.1")); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setDescription("Description"); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setDescription(null); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setState(AutomationCompositionState.PASSIVE); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setState(AutomationCompositionState.UNINITIALISED); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setParticipantType(new PfConceptKey("dummy", "0.0.1")); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setParticipantType(new PfConceptKey("participantType", "0.0.1")); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + assertEquals(testJpaAutomationCompositionElement, + new JpaAutomationCompositionElement(testJpaAutomationCompositionElement)); + } + + @Test + void testJpaAutomationCompositionElementLombok() { + assertNotNull(new Participant()); + JpaAutomationCompositionElement ace0 = new JpaAutomationCompositionElement(); + + assertThat(ace0.toString()).contains("JpaAutomationCompositionElement("); + assertThat(ace0.hashCode()).isNotZero(); + assertEquals(true, ace0.equals(ace0)); + assertEquals(false, ace0.equals(null)); + + JpaAutomationCompositionElement ace1 = new JpaAutomationCompositionElement(); + + ace1.setDefinition(new PfConceptKey("defName", "0.0.1")); + ace1.setDescription("Description"); + ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ace1.setState(AutomationCompositionState.UNINITIALISED); + ace1.setParticipantId(new PfConceptKey("participant", "0.0.1")); + + assertThat(ace1.toString()).contains("AutomationCompositionElement("); + assertEquals(false, ace1.hashCode() == 0); + assertEquals(false, ace1.equals(ace0)); + assertEquals(false, ace1.equals(null)); + + assertNotEquals(ace1, ace0); + + JpaAutomationCompositionElement ace2 = new JpaAutomationCompositionElement(); + assertEquals(ace2, ace0); + } + + private JpaAutomationCompositionElement createJpaAutomationCompositionElementInstance() { + AutomationCompositionElement testAce = createAutomationCompositionElementInstance(); + JpaAutomationCompositionElement testJpaAutomationCompositionElement = new JpaAutomationCompositionElement(); + testJpaAutomationCompositionElement.setKey(null); + testJpaAutomationCompositionElement.fromAuthorative(testAce); + testJpaAutomationCompositionElement.setKey(PfReferenceKey.getNullKey()); + testJpaAutomationCompositionElement.fromAuthorative(testAce); + + return testJpaAutomationCompositionElement; + } + + private AutomationCompositionElement createAutomationCompositionElementInstance() { + AutomationCompositionElement automationCompositionElement = new AutomationCompositionElement(); + automationCompositionElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); + automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1")); + automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1")); + + return automationCompositionElement; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java new file mode 100644 index 000000000..a016d1202 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java @@ -0,0 +1,310 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.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.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +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 JpaAutomationCompositionTest} class. + */ +class JpaAutomationCompositionTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaAutomationCompositionConstructor() { + assertThatThrownBy(() -> { + new JpaAutomationComposition((JpaAutomationComposition) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition((PfConceptKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, null, new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), null, new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, + new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, null, new LinkedHashMap<>()); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED, + new LinkedHashMap<>()); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>()); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), + AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching("elements is marked .*ull but is null"); + + assertNotNull(new JpaAutomationComposition()); + assertNotNull(new JpaAutomationComposition((new PfConceptKey()))); + assertNotNull(new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), + AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>())); + } + + @Test + void testJpaAutomationComposition() { + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + AutomationComposition participant = createAutomationCompositionInstance(); + assertEquals(participant, testJpaAutomationComposition.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaAutomationComposition.fromAuthorative(null); + }).hasMessageMatching("automationComposition is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaAutomationComposition((JpaAutomationComposition) null)) + .isInstanceOf(NullPointerException.class); + + JpaAutomationComposition testJpaAutomationCompositionFa = new JpaAutomationComposition(); + testJpaAutomationCompositionFa.setKey(null); + testJpaAutomationCompositionFa.fromAuthorative(participant); + assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + testJpaAutomationCompositionFa.setKey(PfConceptKey.getNullKey()); + testJpaAutomationCompositionFa.fromAuthorative(participant); + assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + testJpaAutomationCompositionFa.setKey(new PfConceptKey("automation-composition", "0.0.1")); + testJpaAutomationCompositionFa.fromAuthorative(participant); + assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + + assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName()); + assertEquals("automation-composition", + new JpaAutomationComposition(createAutomationCompositionInstance()).getKey().getName()); + assertEquals("automation-composition", + ((PfConceptKey) new JpaAutomationComposition(createAutomationCompositionInstance()).getKeys().get(0)) + .getName()); + + testJpaAutomationComposition.clean(); + assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName()); + + testJpaAutomationComposition.setDescription(" A Message "); + testJpaAutomationComposition.clean(); + assertEquals("A Message", testJpaAutomationComposition.getDescription()); + + JpaAutomationComposition testJpaAutomationComposition2 = + new JpaAutomationComposition(testJpaAutomationComposition); + assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2); + } + + @Test + void testJpaAutomationCompositionElementOrderedState() throws CoderException { + AutomationComposition testAutomationComposition = createAutomationCompositionInstance(); + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + testJpaAutomationComposition.setOrderedState(null); + assertEquals(testAutomationComposition, testJpaAutomationComposition.toAuthorative()); + testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + AutomationComposition noOrderedStateAc = new StandardCoder().decode( + new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"), AutomationComposition.class); + + JpaAutomationComposition noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc); + assertNull(noOrderedStateJpaAc.getOrderedState()); + noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc); + assertEquals(testJpaAutomationComposition, noOrderedStateJpaAc); + + AutomationCompositions automationCompositionsWithElements = new StandardCoder().decode( + new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class); + + JpaAutomationComposition jpaAutomationCompositionWithElements = + new JpaAutomationComposition(automationCompositionsWithElements.getAutomationCompositionList().get(0)); + assertEquals(4, jpaAutomationCompositionWithElements.getElements().size()); + assertEquals(18, jpaAutomationCompositionWithElements.getKeys().size()); + assertThatCode(() -> jpaAutomationCompositionWithElements.clean()).doesNotThrowAnyException(); + + assertEquals(automationCompositionsWithElements.getAutomationCompositionList().get(0), + jpaAutomationCompositionWithElements.toAuthorative()); + } + + @Test + void testJpaAutomationCompositionValidation() { + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + assertThatThrownBy(() -> { + testJpaAutomationComposition.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaAutomationComposition.validate("").isValid()); + } + + @Test + void testJpaAutomationCompositionCompareTo() { + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + JpaAutomationComposition otherJpaAutomationComposition = + new JpaAutomationComposition(testJpaAutomationComposition); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + assertEquals(-1, testJpaAutomationComposition.compareTo(null)); + assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition)); + assertNotEquals(0, testJpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild())); + + testJpaAutomationComposition.setKey(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setKey(new PfConceptKey("automation-composition", "0.0.1")); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setDefinition(new PfConceptKey("automationCompositionDefinitionName", "0.0.1")); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setState(AutomationCompositionState.UNINITIALISED); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setDescription("A description"); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setDescription(null); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setPrimed(true); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setPrimed(false); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + assertEquals(testJpaAutomationComposition, new JpaAutomationComposition(testJpaAutomationComposition)); + } + + @Test + void testJpaAutomationCompositionLombok() { + assertNotNull(new AutomationComposition()); + JpaAutomationComposition ac0 = new JpaAutomationComposition(); + + assertThat(ac0.toString()).contains("JpaAutomationComposition("); + assertThat(ac0.hashCode()).isNotZero(); + assertEquals(true, ac0.equals(ac0)); + assertEquals(false, ac0.equals(null)); + + JpaAutomationComposition ac1 = new JpaAutomationComposition(); + + ac1.setDefinition(new PfConceptKey("defName", "0.0.1")); + ac1.setDescription("Description"); + ac1.setElements(new LinkedHashMap<>()); + ac1.setKey(new PfConceptKey("participant", "0.0.1")); + ac1.setState(AutomationCompositionState.UNINITIALISED); + + assertThat(ac1.toString()).contains("AutomationComposition("); + assertEquals(false, ac1.hashCode() == 0); + assertEquals(false, ac1.equals(ac0)); + assertEquals(false, ac1.equals(null)); + + assertNotEquals(ac1, ac0); + + JpaAutomationComposition ac2 = new JpaAutomationComposition(); + assertEquals(ac2, ac0); + } + + private JpaAutomationComposition createJpaAutomationCompositionInstance() { + AutomationComposition testAutomationComposition = createAutomationCompositionInstance(); + JpaAutomationComposition testJpaAutomationComposition = new JpaAutomationComposition(); + testJpaAutomationComposition.setKey(null); + testJpaAutomationComposition.fromAuthorative(testAutomationComposition); + testJpaAutomationComposition.setKey(PfConceptKey.getNullKey()); + testJpaAutomationComposition.fromAuthorative(testAutomationComposition); + + return testJpaAutomationComposition; + } + + private AutomationComposition createAutomationCompositionInstance() { + AutomationComposition testAutomationComposition = new AutomationComposition(); + testAutomationComposition.setName("automation-composition"); + testAutomationComposition.setVersion("0.0.1"); + testAutomationComposition + .setDefinition(new ToscaConceptIdentifier("automationCompositionDefinitionName", "0.0.1")); + testAutomationComposition.setElements(new LinkedHashMap<>()); + + return testAutomationComposition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java new file mode 100644 index 000000000..284d13374 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.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. + */ +class JpaParticipantStatisticsTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + 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 + void testJpaParticipantStatistics() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + ParticipantStatistics aces = createParticipantStatisticsInstance(); + assertEquals(aces, 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(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey()); + testJpaParticipantStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + testJpaParticipantStatisticsFa + .setKey(new PfTimestampKey("participantName", "0.0.1", Instant.ofEpochMilli(123456L))); + testJpaParticipantStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + + testJpaParticipantStatisticsFa = new JpaParticipantStatistics(aces); + 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 + 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 + 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 + 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 testAces = createParticipantStatisticsInstance(); + JpaParticipantStatistics testJpaParticipantStatistics = new JpaParticipantStatistics(); + testJpaParticipantStatistics.setKey(null); + testJpaParticipantStatistics.fromAuthorative(testAces); + testJpaParticipantStatistics.setKey(PfTimestampKey.getNullKey()); + testJpaParticipantStatistics.fromAuthorative(testAces); + + 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/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java new file mode 100644 index 000000000..776aafa2e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java @@ -0,0 +1,254 @@ +/*- + * ============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.models.acm.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.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaParticiant} class. + */ +class JpaParticipantTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + 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 + 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 + void testJpaParticipantValidation() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + assertThatThrownBy(() -> { + testJpaParticipant.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaParticipant.validate("").isValid()); + } + + @Test + 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 + 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")); + testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "0.0.1")); + + return testParticipant; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java new file mode 100644 index 000000000..1f40fae5f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/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.models.acm.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.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class PojosTest { + + @Test + void testPojos() { + List 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/models/acm/persistence/provider/AcElementStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java new file mode 100644 index 000000000..15d1d845d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java @@ -0,0 +1,116 @@ +/*- + * ============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.models.acm.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.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.time.Instant; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; +import org.onap.policy.clamp.models.acm.persistence.repository.AcElementStatisticsRepository; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AcElementStatisticsProviderTest { + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + private static final Coder CODER = new StandardCoder(); + private static final String AC_ELEMENT_STATS_JSON = "src/test/resources/providers/TestAcElementStatistics.json"; + + private AcElementStatisticsProvider acElementStatisticsProvider; + private AcElementStatisticsList inputAcElementStats; + private String originalJson = ResourceUtils.getResourceAsString(AC_ELEMENT_STATS_JSON); + + /** + * Set up test AcElement statistics provider. + * + * @throws Exception on errors + */ + @BeforeEach + void beforeSetupDao() throws Exception { + + inputAcElementStats = CODER.decode(originalJson, AcElementStatisticsList.class); + var acElementStatisticsRepository = mock(AcElementStatisticsRepository.class); + + var jpaAcElementStatisticsList = + ProviderUtils.getJpaAndValidateList(inputAcElementStats.getAcElementStatistics(), + JpaAcElementStatistics::new, "automation composition element statistics"); + + for (var acElementStat : jpaAcElementStatisticsList) { + when(acElementStatisticsRepository.getById(eq(acElementStat.getKey()))).thenReturn(acElementStat); + when(acElementStatisticsRepository.findAllById(eq(List.of(acElementStat.getKey())))) + .thenReturn(List.of(acElementStat)); + } + + when(acElementStatisticsRepository.saveAll(anyList())).thenReturn(jpaAcElementStatisticsList); + + when(acElementStatisticsRepository.getFiltered(eq(JpaAcElementStatistics.class), any())) + .thenReturn(List.of(jpaAcElementStatisticsList.get(0))); + + acElementStatisticsProvider = new AcElementStatisticsProvider(acElementStatisticsRepository); + } + + @Test + void testAcElementStatisticsCreate() throws Exception { + assertThatThrownBy(() -> { + acElementStatisticsProvider.createAcElementStatistics(null); + }).hasMessageMatching(LIST_IS_NULL); + + AcElementStatisticsList createdAcElementStats = new AcElementStatisticsList(); + createdAcElementStats.setAcElementStatistics( + acElementStatisticsProvider.createAcElementStatistics(inputAcElementStats.getAcElementStatistics())); + + assertEquals(inputAcElementStats.toString().replaceAll("\\s+", ""), + createdAcElementStats.toString().replaceAll("\\s+", "")); + } + + @Test + void testGetAcElementStatistics() throws Exception { + + List getResponse; + + // Return empty list when no data present in db + getResponse = acElementStatisticsProvider.getAcElementStatistics(null, null, null, null); + assertThat(getResponse).isEmpty(); + + acElementStatisticsProvider.createAcElementStatistics(inputAcElementStats.getAcElementStatistics()); + ToscaConceptIdentifier identifier = inputAcElementStats.getAcElementStatistics().get(0).getParticipantId(); + Instant instant = inputAcElementStats.getAcElementStatistics().get(0).getTimeStamp(); + String id = inputAcElementStats.getAcElementStatistics().get(0).getId().toString(); + assertEquals(1, acElementStatisticsProvider + .getAcElementStatistics(identifier.getName(), identifier.getVersion(), id, instant).size()); + + assertEquals(1, acElementStatisticsProvider + .getFilteredAcElementStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java new file mode 100644 index 000000000..0a367eed8 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java @@ -0,0 +1,305 @@ +/*- + * ============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.models.acm.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.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Optional; +import javax.persistence.EntityNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; +import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplatesRepository; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; + +class AutomationCompositionProviderTest { + + private static final String LIST_IS_NULL = "automationCompositions is marked .*ull but is null"; + private static final String OBJECT_IS_NULL = "automationComposition is marked non-null but is null"; + + private static final String ID_NAME = "PMSHInstance1"; + private static final String ID_VERSION = "1.0.1"; + private static final String ID_NAME_NOT_EXTST = "not_exist"; + private static final String ID_NAME_NOT_VALID = "not_valid"; + + private static final Coder CODER = new StandardCoder(); + private static final String AUTOMATION_COMPOSITION_JSON = + "src/test/resources/providers/TestAutomationCompositions.json"; + private static final String TOSCA_TEMPLATE_YAML = "examples/acm/PMSubscriptionHandling.yaml"; + + private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); + + private AutomationCompositions inputAutomationCompositions; + private List inputAutomationCompositionsJpa; + private String originalJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON); + + @BeforeEach + void beforeSetupDao() throws Exception { + inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class); + inputAutomationCompositionsJpa = + ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(), + JpaAutomationComposition::new, "automation compositions"); + } + + @Test + void testAutomationCompositionsSave() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + assertThatThrownBy(() -> { + automationCompositionProvider.saveAutomationCompositions(null); + }).hasMessageMatching(LIST_IS_NULL); + + when(automationCompositionRepository.saveAll(inputAutomationCompositionsJpa)) + .thenReturn(inputAutomationCompositionsJpa); + + var createdAutomationCompositions = new AutomationCompositions(); + createdAutomationCompositions.setAutomationCompositionList(automationCompositionProvider + .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList())); + + assertEquals(inputAutomationCompositions, createdAutomationCompositions); + + when(automationCompositionRepository.saveAll(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider + .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()); + }).hasMessageMatching("Error in save AutomationCompositions"); + } + + @Test + void testAutomationCompositionSave() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + assertThatThrownBy(() -> { + automationCompositionProvider.saveAutomationComposition(null); + }).hasMessageMatching(OBJECT_IS_NULL); + + when(automationCompositionRepository.save(inputAutomationCompositionsJpa.get(0))) + .thenReturn(inputAutomationCompositionsJpa.get(0)); + + var createdAutomationComposition = automationCompositionProvider + .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)); + + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), createdAutomationComposition); + + when(automationCompositionRepository.save(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider + .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)); + }).hasMessageMatching("Error in save automationComposition"); + } + + @Test + void testGetAutomationCompositions() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + // Return empty list when no data present in db + List getResponse = automationCompositionProvider.getAutomationCompositions(); + assertThat(getResponse).isEmpty(); + + automationCompositionProvider + .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()); + + var automationComposition0 = inputAutomationCompositions.getAutomationCompositionList().get(1); + var name = automationComposition0.getName(); + var version = automationComposition0.getVersion(); + var automationComposition1 = inputAutomationCompositions.getAutomationCompositionList().get(1); + + when(automationCompositionRepository.getFiltered(eq(JpaAutomationComposition.class), any(), any())) + .thenReturn(List.of(new JpaAutomationComposition(automationComposition0), + new JpaAutomationComposition(automationComposition1))); + when(automationCompositionRepository.findById(automationComposition0.getKey().asIdentifier().asConceptKey())) + .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition0))); + when(automationCompositionRepository.getById(automationComposition0.getKey().asIdentifier().asConceptKey())) + .thenReturn(new JpaAutomationComposition(automationComposition0)); + when(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version)) + .thenReturn(List.of(new JpaAutomationComposition(automationComposition0))); + when(automationCompositionRepository.findById(automationComposition1.getKey().asIdentifier().asConceptKey())) + .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1))); + + assertEquals(1, automationCompositionProvider.getAutomationCompositions(name, version).size()); + + var ac = automationCompositionProvider + .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)).get(); + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac); + + ac = automationCompositionProvider.getAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)); + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac); + + when(automationCompositionRepository.getById(any())).thenThrow(EntityNotFoundException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider + .getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)); + }).hasMessageMatching("AutomationComposition not found"); + + ac = automationCompositionProvider.findAutomationComposition(ID_NAME, ID_VERSION).get(); + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac); + + assertThat(automationCompositionProvider + .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty(); + + when(automationCompositionRepository.findById(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider.findAutomationComposition(ID_NAME_NOT_VALID, ID_VERSION); + }).hasMessageMatching("Not valid parameter"); + } + + @Test + void testDeleteAutomationComposition() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + assertThatThrownBy(() -> { + automationCompositionProvider.deleteAutomationComposition(ID_NAME_NOT_EXTST, ID_VERSION); + }).hasMessageMatching(".*.failed, automation composition does not exist"); + + var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0); + var name = automationComposition.getName(); + var version = automationComposition.getVersion(); + + when(automationCompositionRepository.findById(new PfConceptKey(name, version))) + .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0))); + + AutomationComposition deletedAc = automationCompositionProvider.deleteAutomationComposition(name, version); + assertEquals(automationComposition, deletedAc); + } + + @Test + void testDeleteAllInstanceProperties() throws Exception { + var automationCompositionProvider = + new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + var toscaServiceTemplate = testAutomationCompositionRead(); + automationCompositionProvider.deleteInstanceProperties( + automationCompositionProvider.saveInstanceProperties(toscaServiceTemplate), + automationCompositionProvider.getAllNodeTemplates()); + assertThat(automationCompositionProvider.getAutomationCompositions()).isEmpty(); + } + + @Test + void testSaveAndDeleteInstanceProperties() throws Exception { + var toscaNodeTemplatesRepository = mock(ToscaNodeTemplatesRepository.class); + var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider( + mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository, toscaNodeTemplatesRepository); + var toscaServiceTest = testAutomationCompositionRead(); + + automationCompositionProvider.saveInstanceProperties(toscaServiceTest); + verify(toscaNodeTemplatesRepository).save(any()); + + var name = "org.onap.policy.acm.PolicyAutomationCompositionParticipant"; + var version = "2.3.1"; + var elem = toscaServiceTest.getToscaTopologyTemplate().getNodeTemplates().get(name); + when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version)) + .thenReturn(List.of(new JpaToscaNodeTemplate(elem))); + + var filtered = automationCompositionProvider.getNodeTemplates(name, version); + verify(toscaNodeTemplateRepository).getFiltered(JpaToscaNodeTemplate.class, name, version); + + automationCompositionProvider + .deleteInstanceProperties(automationCompositionProvider.saveInstanceProperties(toscaServiceTest), filtered); + + verify(toscaNodeTemplateRepository).delete(any()); + } + + @Test + void testGetNodeTemplates() throws Exception { + var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); + var automationCompositionProvider = + new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository, + mock(ToscaNodeTemplatesRepository.class)); + + var toscaNodeTemplate0 = new JpaToscaNodeTemplate(new PfConceptKey(ID_NAME, ID_VERSION)); + var toscaNodeTemplate1 = new JpaToscaNodeTemplate(new PfConceptKey("PMSHInstance2", ID_VERSION)); + + when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, null, null)) + .thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); + when(toscaNodeTemplateRepository.findAll()).thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); + when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, ID_NAME, ID_VERSION)) + .thenReturn(List.of(toscaNodeTemplate0)); + + // Getting all nodes + var listNodes = automationCompositionProvider.getAllNodeTemplates(); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(2); + + listNodes = automationCompositionProvider.getNodeTemplates(ID_NAME, ID_VERSION); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(1); + + listNodes = automationCompositionProvider.getAllNodeTemplates(); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(2); + + var nodeTemplateFilter = + ToscaTypedEntityFilter.builder().name(ID_NAME).version(ID_VERSION).build(); + + listNodes = automationCompositionProvider.getFilteredNodeTemplates(nodeTemplateFilter); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(1); + + assertThatThrownBy(() -> { + automationCompositionProvider.getFilteredNodeTemplates(null); + }).hasMessageMatching("filter is marked non-null but is null"); + } + + private static ToscaServiceTemplate testAutomationCompositionRead() { + return testAutomationCompositionYamlSerialization(TOSCA_TEMPLATE_YAML); + } + + private static ToscaServiceTemplate testAutomationCompositionYamlSerialization( + String automationCompositionFilePath) { + var automationCompositionString = ResourceUtils.getResourceAsString(automationCompositionFilePath); + return yamlTranslator.fromYaml(automationCompositionString, ToscaServiceTemplate.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java new file mode 100644 index 000000000..f537e2cd7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java @@ -0,0 +1,149 @@ +/*- + * ============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.models.acm.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.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; +import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository; +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.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +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 List inputParticipants = new ArrayList<>(); + private List jpaParticipantList; + private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON); + + @BeforeEach + void beforeSetupDao() throws Exception { + inputParticipants.add(CODER.decode(originalJson, Participant.class)); + jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant"); + } + + @Test + void testParticipantSave() throws Exception { + var participantRepository = mock(ParticipantRepository.class); + for (var participant : jpaParticipantList) { + when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion()))) + .thenReturn(participant); + } + var participantProvider = new ParticipantProvider(participantRepository); + + assertThatThrownBy(() -> { + participantProvider.saveParticipant(null); + }).hasMessageMatching(LIST_IS_NULL); + + when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0)); + + Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0)); + assertEquals(savedParticipant, inputParticipants.get(0)); + + when(participantRepository.save(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + participantProvider.saveParticipant(inputParticipants.get(0)); + }).hasMessageMatching("Error in save Participant"); + } + + @Test + void testGetAutomationCompositions() throws Exception { + var participantRepository = mock(ParticipantRepository.class); + var participantProvider = new ParticipantProvider(participantRepository); + + // Return empty list when no data present in db + List getResponse = participantProvider.getParticipants(null, null); + assertThat(getResponse).isEmpty(); + + String name = inputParticipants.get(0).getName(); + String version = inputParticipants.get(0).getVersion(); + when(participantRepository.getFiltered(any(), eq(name), eq(version))) + .thenReturn(List.of(jpaParticipantList.get(0))); + assertEquals(1, participantProvider.getParticipants(name, version).size()); + + assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty(); + + assertThat(participantProvider.findParticipant("invalid_name", "1.0.1")).isEmpty(); + + when(participantRepository.findAll()).thenReturn(jpaParticipantList); + assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size()); + + when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + participantProvider.findParticipant("notValid", "notValid"); + }).hasMessageMatching("Error in find Participant"); + + assertThatThrownBy(() -> { + participantProvider.getFilteredParticipants(null); + }).hasMessageMatching("filter is marked .*ull but is null"); + + when(participantRepository.getFiltered(eq(JpaParticipant.class), eq(null), eq(null))) + .thenReturn(jpaParticipantList); + + final ToscaTypedEntityFilter filter = ToscaTypedEntityFilter.builder() + .type("org.onap.domain.pmsh.PMSHAutomationCompositionDefinition").build(); + assertEquals(1, participantProvider.getFilteredParticipants(filter).size()); + + } + + @Test + void testDeleteParticipant() throws Exception { + var participantRepository = mock(ParticipantRepository.class); + var participantProvider = new ParticipantProvider(participantRepository); + + assertThatThrownBy(() -> { + participantProvider.deleteParticipant("Invalid_name", "1.0.1"); + }).hasMessageMatching(".*.failed, participant does not exist"); + + String name = inputParticipants.get(0).getName(); + String version = inputParticipants.get(0).getVersion(); + + when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0))); + + Participant deletedParticipant = participantProvider.deleteParticipant(name, version); + assertEquals(inputParticipants.get(0), deletedParticipant); + + when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); + assertThatThrownBy(() -> { + participantProvider.deleteParticipant(name, version); + }).hasMessageMatching("Error in delete Participant"); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java new file mode 100644 index 000000000..3c6b1eb83 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java @@ -0,0 +1,107 @@ +/*- + * ============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.models.acm.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.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.time.Instant; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatisticsList; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; +import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantStatisticsRepository; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +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 ParticipantStatisticsProvider participantStatisticsProvider; + private ParticipantStatisticsList inputParticipantStatistics; + private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON); + + @BeforeEach + void beforeSetupDao() throws Exception { + var participantStatisticsRepository = mock(ParticipantStatisticsRepository.class); + participantStatisticsProvider = new ParticipantStatisticsProvider(participantStatisticsRepository); + inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class); + + var jpaParticipantStatisticsList = + ProviderUtils.getJpaAndValidateList(inputParticipantStatistics.getStatisticsList(), + JpaParticipantStatistics::new, "Participant Statistics"); + + for (var participantStat : jpaParticipantStatisticsList) { + when(participantStatisticsRepository.getById(eq(participantStat.getKey()))).thenReturn(participantStat); + when(participantStatisticsRepository.findAllById(eq(List.of(participantStat.getKey())))) + .thenReturn(List.of(participantStat)); + } + + when(participantStatisticsRepository.getFiltered(eq(JpaParticipantStatistics.class), any())) + .thenReturn(List.of(jpaParticipantStatisticsList.get(0))); + + when(participantStatisticsRepository.saveAll(anyList())).thenReturn(jpaParticipantStatisticsList); + } + + @Test + 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 + void testGetAutomationCompositions() throws Exception { + // Return empty list when no data present in db + List 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/models/acm/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java new file mode 100644 index 000000000..4d998717e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java @@ -0,0 +1,169 @@ +/*- + * ============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.models.acm.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaServiceTemplateRepository; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardYamlCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; + +class ServiceTemplateProviderTest { + + private static final String TOSCA_SERVICE_TEMPLATE_YAML = + "src/test/resources/providers/tosca-for-smoke-testing.yaml"; + + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); + + private static ToscaServiceTemplate inputServiceTemplate; + + @BeforeAll + static void loadServiceTemplate() { + inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + } + + @Test + void testGetCommonOrInstancePropertiesFromNodeTypes() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + + var result = serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); + assertNotNull(result); + assertThat(result).hasSize(8); + } + + @Test + void testGetDerivedCommonOrInstanceNodeTemplates() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + + var commonOrInstanceNodeTypeProps = + serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); + + var result = serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates( + inputServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(), commonOrInstanceNodeTypeProps); + + assertNotNull(result); + assertThat(result).hasSize(8); + } + + @Test + void testCreateServiceTemplate() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + when(serviceTemplateRepository.save(jpaServiceTemplate)).thenReturn(jpaServiceTemplate); + + var result = serviceTemplateProvider.createServiceTemplate(inputServiceTemplate); + + assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + @Test + void testDeleteServiceTemplate() throws PfModelException { + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository + .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) + .thenReturn(Optional.of(jpaServiceTemplate)); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + var result = serviceTemplateProvider.deleteServiceTemplate(inputServiceTemplate.getName(), + inputServiceTemplate.getVersion()); + + assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + @Test + void testGetServiceTemplateListEmpty() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository.findById(any())).thenReturn(Optional.empty()); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + assertThatThrownBy(() -> serviceTemplateProvider.getToscaServiceTemplate("Name", "1.0.0")) + .hasMessage("Automation composition definitions not found"); + } + + @Test + void testGetServiceTemplateList() throws PfModelException { + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository + .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) + .thenReturn(Optional.of(jpaServiceTemplate)); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + var result = serviceTemplateProvider.getToscaServiceTemplate(inputServiceTemplate.getName(), + inputServiceTemplate.getVersion()); + + assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + @Test + void testGetServiceTemplate() throws PfModelException { + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, inputServiceTemplate.getName(), + inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate)); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + var result = serviceTemplateProvider.getServiceTemplateList(inputServiceTemplate.getName(), + inputServiceTemplate.getVersion()); + + assertThat(result).hasSize(1); + assertThat(result.get(0)).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + /** + * Get ToscaServiceTemplate from resource. + * + * @param path path of the resource + */ + public static ToscaServiceTemplate getToscaServiceTemplate(String path) { + + try { + return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); + } catch (CoderException e) { + fail("Cannot read or decode " + path); + return null; + } + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java new file mode 100644 index 000000000..7210a6afd --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.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.models.acm.persistence.repository; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; +import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.dao.PfFilterParameters; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.provider.impl.ModelsProvider; + +class FilterRepositoryImplTest { + private static final String AUTOMATION_COMPOSITION_JSON = + "src/test/resources/providers/TestAutomationCompositions.json"; + private static final Coder CODER = new StandardCoder(); + private static final AtomicInteger dbNameCounter = new AtomicInteger(); + private static final String originalJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON); + private static List jpaAutomationCompositions; + private PfDao pfDao; + + @BeforeEach + void beforeSetupDao() throws Exception { + var 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:automationCompositionProviderTestDb" + dbNameCounter.getAndDecrement()); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword("P01icY"); + parameters.setPersistenceUnit("ToscaConceptTest"); + + pfDao = ModelsProvider.init(parameters); + var inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class); + jpaAutomationCompositions = + ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(), + JpaAutomationComposition::new, "AutomationCompositions"); + + pfDao.createCollection(jpaAutomationCompositions); + } + + @Test + void testGetPfDao() { + assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull(); + } + + @Test + void testGetFilteredParams() { + var filterRepositoryImpl = new FilterRepositoryImpl() { + @Override + protected PfDao getPfDao() { + return pfDao; + } + }; + var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, null, null); + assertThat(result).hasSize(2); + + result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, + jpaAutomationCompositions.get(0).getName(), null); + assertThat(result).hasSize(1); + } + + @Test + void testGetFiltered() { + var filterRepositoryImpl = new FilterRepositoryImpl() { + @Override + protected PfDao getPfDao() { + return pfDao; + } + }; + + // @formatter:off + PfFilterParameters filterParams = PfFilterParameters + .builder() + .name(jpaAutomationCompositions.get(0).getName()) + .build(); + // @formatter:on + + var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, filterParams); + assertThat(result).hasSize(1); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java new file mode 100644 index 000000000..a62f78ba2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java @@ -0,0 +1,54 @@ +/*- + * ============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.models.acm.rest; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.ws.rs.core.Response.Status; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.errors.concepts.ErrorResponse; +import org.onap.policy.models.errors.concepts.ErrorResponseInfo; + +class RestUtilsTest { + + private static final String MESSAGE_ERROR = "Erorr"; + private static final Status STATUS_ERROR = Status.BAD_REQUEST; + + @Test + void testToSimpleResponse() { + var ex = new ErrorResponseInfo() { + + @Override + public ErrorResponse getErrorResponse() { + var er = new ErrorResponse(); + er.setErrorMessage(MESSAGE_ERROR); + er.setResponseCode(STATUS_ERROR); + return er; + } + }; + + var response = RestUtils.toSimpleResponse(ex); + + assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode()); + assertThat(response.getBody()).isNotNull(); + assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java new file mode 100644 index 000000000..a5434240a --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -0,0 +1,149 @@ +/*- + * ============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.models.acm.utils; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; + +class AcmUtilsTest { + + private ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.0.0"); + private ToscaConceptIdentifier idNode = + new ToscaConceptIdentifier("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", "0.0.0"); + + @Test + void testCommonUtilsParticipantUpdate() { + var acElement = new AutomationCompositionElement(); + List participantUpdates = new ArrayList<>(); + assertThat(participantUpdates).isEmpty(); + + AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); + assertThat(participantUpdates).isNotEmpty(); + assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0)); + + AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); + assertNotEquals(id, participantUpdates.get(0).getParticipantId()); + + acElement.setParticipantId(id); + acElement.setParticipantType(id); + AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); + assertEquals(id, participantUpdates.get(1).getParticipantId()); + } + + @Test + void testCommonUtilsServiceTemplate() { + var acElement = new AutomationCompositionElement(); + var toscaServiceTemplate = getDummyToscaServiceTemplate(); + AcmUtils.setServiceTemplatePolicyInfo(acElement, toscaServiceTemplate); + assertEquals(getDummyToscaDataTypeMap(), acElement.getToscaServiceTemplateFragment().getDataTypes()); + } + + @Test + void testCommonUtilsDefinitionUpdate() { + var toscaServiceTemplate = getDummyToscaServiceTemplate(); + List participantDefinitionUpdates = new ArrayList<>(); + assertThat(participantDefinitionUpdates).isEmpty(); + + checkParticipantDefinitionUpdate(toscaServiceTemplate, participantDefinitionUpdates); + assertThat(participantDefinitionUpdates).isNotEmpty(); + assertEquals(id, participantDefinitionUpdates.get(0).getParticipantType()); + + checkParticipantDefinitionUpdate(toscaServiceTemplate, participantDefinitionUpdates); + assertEquals(idNode, participantDefinitionUpdates.get(0).getAutomationCompositionElementDefinitionList().get(0) + .getAcElementDefinitionId()); + } + + private ToscaServiceTemplate getDummyToscaServiceTemplate() { + var toscaServiceTemplate = new ToscaServiceTemplate(); + var policyTypes = getDummyPolicyTypesMap(); + toscaServiceTemplate.setPolicyTypes(policyTypes); + + var dataTypes = getDummyToscaDataTypeMap(); + dataTypes.put("onap.datatypes.ToscaConceptIdentifier", new ToscaDataType()); + toscaServiceTemplate.setDataTypes(dataTypes); + + var toscaTopologyTemplate = new ToscaTopologyTemplate(); + Map policy = new HashMap<>(); + toscaTopologyTemplate.setPolicies(List.of(policy)); + var nodeTemplates = getDummyNodeTemplates(); + toscaTopologyTemplate.setNodeTemplates(nodeTemplates); + + toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate); + toscaServiceTemplate.setDerivedFrom("tosca.nodetypes.Root"); + toscaServiceTemplate.setDescription("description"); + toscaServiceTemplate.setMetadata(null); + toscaServiceTemplate.setName("name"); + toscaServiceTemplate.setToscaDefinitionsVersion("1.0.0"); + toscaServiceTemplate.setVersion("1.0.1"); + return toscaServiceTemplate; + } + + private Map getDummyPolicyTypesMap() { + Map policyTypes = new HashMap<>(); + policyTypes.put("onap.policies.Match", new ToscaPolicyType()); + return policyTypes; + } + + private Map getDummyToscaDataTypeMap() { + Map dataTypes = new HashMap<>(); + dataTypes.put("onap.datatypes.ToscaConceptIdentifier", new ToscaDataType()); + return dataTypes; + } + + private Map getDummyNodeTemplates() { + Map nodeTemplates = new HashMap<>(); + var nodeTemplate = new ToscaNodeTemplate(); + nodeTemplate.setType("org.onap.policy.clamp.acm.AutomationCompositionElement"); + nodeTemplates.put("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", nodeTemplate); + return nodeTemplates; + } + + private void checkParticipantDefinitionUpdate(ToscaServiceTemplate toscaServiceTemplate, + List participantDefinitionUpdates) { + + for (Map.Entry toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate() + .getNodeTemplates().entrySet()) { + if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(), + toscaServiceTemplate)) { + AcmUtils.prepareParticipantDefinitionUpdate(id, toscaInputEntry.getKey(), toscaInputEntry.getValue(), + participantDefinitionUpdates, null); + } + } + } +} -- cgit 1.2.3-korg