d77760860c2d2c2010baf7461096345dcc7b5db2
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2024 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.models.acm.persistence.concepts;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import static org.junit.jupiter.api.Assertions.assertNotEquals;
28
29 import java.util.UUID;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica;
32 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
33 import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
34
35 class JpaParticipantReplicaTest {
36
37     @Test
38     void testJpaParticipantReplicaConstructor() {
39         assertThatThrownBy(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), null))
40                 .hasMessageMatching("participantId is marked .*ull but is null");
41
42         assertThatThrownBy(() -> new JpaParticipantReplica(null, UUID.randomUUID().toString()))
43                 .hasMessageMatching("replicaId is marked .*ull but is null");
44
45         assertDoesNotThrow(() -> new JpaParticipantReplica());
46         assertDoesNotThrow(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
47     }
48
49     @Test
50     void testJpaParticipantReplica() {
51         var p0 = new JpaParticipantReplica();
52
53         assertThat(p0.toString()).contains("JpaParticipantReplica(");
54         assertThat(p0.hashCode()).isNotZero();
55         assertNotEquals(null, p0);
56
57         var p1 = new JpaParticipantReplica();
58         p1.setParticipantState(ParticipantState.ON_LINE);
59
60         assertThat(p1.toString()).contains("ParticipantReplica(");
61         assertNotEquals(0, p1.hashCode());
62         assertNotEquals(p1, p0);
63         assertNotEquals(null, p1);
64
65         var p2 = new JpaParticipantReplica();
66         p2.setReplicaId(p0.getReplicaId());
67         p2.setParticipantId(p0.getParticipantId());
68         p2.setLastMsg(p0.getLastMsg());
69         p2.setParticipantState(p0.getParticipantState());
70         assertEquals(p2, p0);
71     }
72 }