5c429b96c6c08ed308d8bbb6097421e9e5a6a538
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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.controlloop.models.controlloop.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.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28
29 import org.junit.jupiter.api.Test;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
31
32 class ParticipantTest {
33     @Test
34     void testParticipant() {
35
36         Participant p0 = new Participant();
37         p0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3"));
38         assertEquals("dfName", p0.getType());
39         assertEquals("1.2.3", p0.getTypeVersion());
40
41         Participant p1 = new Participant(p0);
42         assertEquals(p0, p1);
43
44         assertEquals(0, p0.compareTo(p1));
45     }
46
47     @Test
48     void testParticipantLombok() {
49         assertNotNull(new Participant());
50         Participant p0 = new Participant();
51
52         assertThat(p0.toString()).contains("Participant(");
53         assertThat(p0.hashCode()).isNotZero();
54         assertEquals(true, p0.equals(p0));
55         assertEquals(false, p0.equals(null));
56
57
58         Participant p1 = new Participant();
59
60         p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
61         p1.setDescription("Description");
62         p1.setHealthStatus(ParticipantHealthStatus.HEALTHY);
63         p1.setName("Name");
64         p1.setParticipantState(ParticipantState.ACTIVE);
65         p1.setVersion("0.0.1");
66
67         assertThat(p1.toString()).contains("Participant(");
68         assertEquals(false, p1.hashCode() == 0);
69         assertEquals(false, p1.equals(p0));
70         assertEquals(false, p1.equals(null));
71
72         assertNotEquals(p1, p0);
73
74         Participant p2 = new Participant();
75
76         // @formatter:off
77         assertThatThrownBy(() -> p2.setDefinition(null)).      isInstanceOf(NullPointerException.class);
78         assertThatThrownBy(() -> p2.setHealthStatus(null)).    isInstanceOf(NullPointerException.class);
79         assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
80         // @formatter:on
81
82         assertEquals(p2, p0);
83     }
84 }