diff options
author | Ramesh Murugan Iyer <ramesh.murugan.iyer@est.tech> | 2024-06-11 09:19:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-06-11 09:19:49 +0000 |
commit | a35b7acb63a5990293231d30ff6efbe046267f3e (patch) | |
tree | 0f8f5d3e1b6ccedf6dcd20c86bfadb65aaa06ada /models/src/test/java | |
parent | f010d3432b500258121a190ecf94d757c881390e (diff) | |
parent | 8d4778eb89eed2da8ba3998d04063775360dd3e2 (diff) |
Merge "Create model in clamp runtime for the replica table"
Diffstat (limited to 'models/src/test/java')
4 files changed, 154 insertions, 8 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java new file mode 100644 index 000000000..8df6db65e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.utils.CommonTestData; + +class ParticipantReplicaTest { + + @Test + void testParticipantLombok() { + assertDoesNotThrow(() -> new ParticipantReplica()); + var p0 = new ParticipantReplica(); + + assertThat(p0.toString()).contains("ParticipantReplica("); + assertThat(p0.hashCode()).isNotZero(); + assertNotEquals(null, p0); + + var p1 = new ParticipantReplica(); + + p1.setReplicaId(CommonTestData.getReplicaId()); + p1.setParticipantState(ParticipantState.ON_LINE); + + assertThat(p1.toString()).contains("ParticipantReplica("); + assertNotEquals(0, p1.hashCode()); + assertNotEquals(p1, p0); + assertNotEquals(null, p1); + + var p2 = new ParticipantReplica(); + assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class); + assertEquals(p2, p0); + } + + @Test + void testCopyConstructor() { + var p0 = new ParticipantReplica(); + p0.setReplicaId(UUID.randomUUID()); + p0.setParticipantState(ParticipantState.ON_LINE); + + var p2 = new ParticipantReplica(p0); + assertEquals(p2, p0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java new file mode 100644 index 000000000..d77760860 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; + +class JpaParticipantReplicaTest { + + @Test + void testJpaParticipantReplicaConstructor() { + assertThatThrownBy(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), null)) + .hasMessageMatching("participantId is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaParticipantReplica(null, UUID.randomUUID().toString())) + .hasMessageMatching("replicaId is marked .*ull but is null"); + + assertDoesNotThrow(() -> new JpaParticipantReplica()); + assertDoesNotThrow(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), UUID.randomUUID().toString())); + } + + @Test + void testJpaParticipantReplica() { + var p0 = new JpaParticipantReplica(); + + assertThat(p0.toString()).contains("JpaParticipantReplica("); + assertThat(p0.hashCode()).isNotZero(); + assertNotEquals(null, p0); + + var p1 = new JpaParticipantReplica(); + p1.setParticipantState(ParticipantState.ON_LINE); + + assertThat(p1.toString()).contains("ParticipantReplica("); + assertNotEquals(0, p1.hashCode()); + assertNotEquals(p1, p0); + assertNotEquals(null, p1); + + var p2 = new JpaParticipantReplica(); + p2.setReplicaId(p0.getReplicaId()); + p2.setParticipantId(p0.getParticipantId()); + p2.setLastMsg(p0.getLastMsg()); + p2.setParticipantState(p0.getParticipantState()); + assertEquals(p2, p0); + } +} 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 index e64a6893f..e0f2f55c1 100644 --- 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 @@ -52,20 +52,25 @@ class JpaParticipantTest { assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)) .hasMessageMatching("copyConcept is marked .*ull but is null"); - assertThatThrownBy(() -> new JpaParticipant(null, null, null)).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> new JpaParticipant(null, ParticipantState.ON_LINE, new ArrayList<>())) + assertThatThrownBy(() -> new JpaParticipant(null, ParticipantState.ON_LINE, + new ArrayList<>(), new ArrayList<>())) .hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null, new ArrayList<>())) + assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null, + new ArrayList<>(), new ArrayList<>())) .hasMessageMatching("participantState is marked .*ull but is null"); - assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE, null)) + assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE, + null, new ArrayList<>())) .hasMessageMatching("supportedElements is marked .*ull but is null"); + assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE, + new ArrayList<>(), null)) + .hasMessageMatching("replicas is marked .*ull but is null"); + assertDoesNotThrow(() -> new JpaParticipant()); assertDoesNotThrow(() -> new JpaParticipant(UUID.randomUUID().toString(), - ParticipantState.ON_LINE, new ArrayList<>())); + ParticipantState.ON_LINE, new ArrayList<>(), new ArrayList<>())); } @Test @@ -158,6 +163,7 @@ class JpaParticipantTest { testParticipant.setParticipantId(UUID.randomUUID()); testParticipant.setLastMsg(TimestampHelper.now()); testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>()); + testParticipant.setReplicas(new LinkedHashMap<>()); return testParticipant; } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java index b8075c3ef..3bd1549ad 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java @@ -51,9 +51,9 @@ public class CommonTestData { } /** - * Returns participantId for test cases. + * Returns participant replica Id for test cases. * - * @return participant Id + * @return replica Id */ public static UUID getReplicaId() { return REPLICA_ID; |