diff options
Diffstat (limited to 'models/src/test')
4 files changed, 65 insertions, 18 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java index fd06b3941..a843c8279 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-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. @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.UUID; import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; class ParticipantInformationTest { @@ -33,6 +34,7 @@ class ParticipantInformationTest { var participant = new Participant(); participant.setParticipantId(UUID.randomUUID()); participant.setParticipantState(ParticipantState.ON_LINE); + participant.setLastMsg(TimestampHelper.now()); participant.setParticipantSupportedElementTypes(new HashMap<>()); var participantInfo1 = new ParticipantInformation(); participantInfo1.setParticipant(participant); 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 05ab495c5..e64a6893f 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-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. @@ -27,12 +27,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.sql.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; /** * Test the {@link JpaParticipant} class. @@ -43,6 +46,9 @@ class JpaParticipantTest { @Test void testJpaParticipantConstructor() { + assertThatThrownBy(() -> new JpaParticipant((Participant) null)) + .hasMessageMatching("authorativeConcept is marked .*ull but is null"); + assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)) .hasMessageMatching("copyConcept is marked .*ull but is null"); @@ -64,11 +70,8 @@ class JpaParticipantTest { @Test void testJpaParticipant() { - var testJpaParticipant = createJpaParticipantInstance(); - var participant = createParticipantInstance(); - - participant.setParticipantId(testJpaParticipant.toAuthorative().getParticipantId()); + var testJpaParticipant = new JpaParticipant(participant); assertEquals(participant, testJpaParticipant.toAuthorative()); @@ -89,7 +92,7 @@ class JpaParticipantTest { @Test void testJpaParticipantValidation() { - var testJpaParticipant = createJpaParticipantInstance(); + var testJpaParticipant = new JpaParticipant(createParticipantInstance()); assertThatThrownBy(() -> testJpaParticipant.validate(null)) .hasMessageMatching("fieldName is marked .*ull but is null"); @@ -99,7 +102,7 @@ class JpaParticipantTest { @Test void testJpaParticipantCompareTo() { - var testJpaParticipant = createJpaParticipantInstance(); + var testJpaParticipant = new JpaParticipant(createParticipantInstance()); var otherJpaParticipant = new JpaParticipant(testJpaParticipant); otherJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId()); @@ -114,6 +117,12 @@ class JpaParticipantTest { assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant)); + testJpaParticipant.setLastMsg(Timestamp.from(Instant.EPOCH)); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setLastMsg(otherJpaParticipant.getLastMsg()); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant)); + var newJpaParticipant = new JpaParticipant(testJpaParticipant); newJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId()); assertEquals(testJpaParticipant, newJpaParticipant); @@ -140,22 +149,14 @@ class JpaParticipantTest { var p2 = new JpaParticipant(); p2.setParticipantId(p0.getParticipantId()); + p2.setLastMsg(p0.getLastMsg()); assertEquals(p2, p0); } - private JpaParticipant createJpaParticipantInstance() { - var testParticipant = createParticipantInstance(); - var testJpaParticipant = new JpaParticipant(); - testParticipant.setParticipantId(UUID.fromString(testJpaParticipant.getParticipantId())); - testJpaParticipant.fromAuthorative(testParticipant); - testJpaParticipant.fromAuthorative(testParticipant); - - return testJpaParticipant; - } - private Participant createParticipantInstance() { var testParticipant = new Participant(); testParticipant.setParticipantId(UUID.randomUUID()); + testParticipant.setLastMsg(TimestampHelper.now()); testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>()); return testParticipant; diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java new file mode 100644 index 000000000..aaba0bcc8 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java @@ -0,0 +1,43 @@ +/*- + * ============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.utils; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class TimestampHelperTest { + + @Test + void testNow() { + assertThat(TimestampHelper.nowTimestamp()).isNotNull(); + assertThat(TimestampHelper.now()).isNotNull(); + assertThat(TimestampHelper.nowEpochMilli()).isNotNull(); + } + + @Test + void testToEpochMilli() { + var timeStr = TimestampHelper.now(); + var milli = TimestampHelper.toTimestamp(timeStr).toInstant().toEpochMilli(); + var result = TimestampHelper.toEpochMilli(timeStr); + assertThat(milli).isEqualTo(result); + } +} diff --git a/models/src/test/resources/providers/TestParticipant.json b/models/src/test/resources/providers/TestParticipant.json index 689c6a2b2..3f19baab4 100644 --- a/models/src/test/resources/providers/TestParticipant.json +++ b/models/src/test/resources/providers/TestParticipant.json @@ -8,6 +8,7 @@ "participantState": "ON_LINE", "description": "A dummy PMSH participant1", "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6", + "lastMsg": "2024-05-22 10:04:37.6020187", "participantSupportedElementTypes": { "68fe8c61-7629-4be7-99d8-18bc6a92d178": { "id": "68fe8c61-7629-4be7-99d8-18bc6a92d178", |