4f48c664a689bbdc691c0496b1816d3580fbebc9
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
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.ParticipantState;
32
33 class JpaParticipantReplicaTest {
34
35     @Test
36     void testJpaParticipantReplicaConstructor() {
37         assertThatThrownBy(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), null))
38                 .hasMessageMatching("participantId is marked .*ull but is null");
39
40         assertThatThrownBy(() -> new JpaParticipantReplica(null, UUID.randomUUID().toString()))
41                 .hasMessageMatching("replicaId is marked .*ull but is null");
42
43         assertDoesNotThrow(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
44     }
45
46     @Test
47     void testJpaParticipantReplica() {
48         var p0 = new JpaParticipantReplica();
49
50         assertThat(p0.toString()).contains("JpaParticipantReplica(");
51         assertThat(p0.hashCode()).isNotZero();
52         assertNotEquals(null, p0);
53
54         var p1 = new JpaParticipantReplica();
55         p1.setParticipantState(ParticipantState.ON_LINE);
56
57         assertThat(p1.toString()).contains("ParticipantReplica(");
58         assertNotEquals(0, p1.hashCode());
59         assertNotEquals(p1, p0);
60         assertNotEquals(null, p1);
61
62         var p2 = new JpaParticipantReplica();
63         p2.setReplicaId(p0.getReplicaId());
64         p2.setParticipantId(p0.getParticipantId());
65         p2.setLastMsg(p0.getLastMsg());
66         p2.setParticipantState(p0.getParticipantState());
67         assertEquals(p2, p0);
68     }
69 }