8cc9580cbe837f42862dfbb6ebd27e0c74c7e1db
[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.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());
44         assertDoesNotThrow(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
45     }
46
47     @Test
48     void testJpaParticipantReplica() {
49         var p0 = new JpaParticipantReplica();
50
51         assertThat(p0.toString()).contains("JpaParticipantReplica(");
52         assertThat(p0.hashCode()).isNotZero();
53         assertNotEquals(null, p0);
54
55         var p1 = new JpaParticipantReplica();
56         p1.setParticipantState(ParticipantState.ON_LINE);
57
58         assertThat(p1.toString()).contains("ParticipantReplica(");
59         assertNotEquals(0, p1.hashCode());
60         assertNotEquals(p1, p0);
61         assertNotEquals(null, p1);
62
63         var p2 = new JpaParticipantReplica();
64         p2.setReplicaId(p0.getReplicaId());
65         p2.setParticipantId(p0.getParticipantId());
66         p2.setLastMsg(p0.getLastMsg());
67         p2.setParticipantState(p0.getParticipantState());
68         assertEquals(p2, p0);
69     }
70 }