2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.models.acm.persistence.concepts;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNotEquals;
26 import static org.junit.jupiter.api.Assertions.assertNotNull;
28 import java.util.UUID;
29 import org.junit.jupiter.api.Test;
30 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
33 * Test the {@link JpaParticipantSupportedElementType} class.
35 class JpaParticipantSupportedElementTypeTest {
37 private static final String NULL_PARTICIPANT_ID_ERROR = "participantId is marked .*ull but is null";
38 private static final String NULL_ID_ERROR = "id is marked .*ull but is null";
39 private static final String NULL_ERROR = " is marked .*ull but is null";
40 private static final String ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e";
41 private static final String PARTICIPANT_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a";
44 void testJpaAutomationCompositionElementConstructor() {
45 assertThatThrownBy(() -> {
46 new JpaParticipantSupportedElementType((JpaParticipantSupportedElementType) null);
47 }).hasMessageMatching("copyConcept is marked .*ull but is null");
49 assertThatThrownBy(() -> {
50 new JpaParticipantSupportedElementType("key", null);
51 }).hasMessageMatching(NULL_PARTICIPANT_ID_ERROR);
53 assertThatThrownBy(() -> {
54 new JpaParticipantSupportedElementType(null, "key");
55 }).hasMessageMatching(NULL_ID_ERROR);
57 assertThatThrownBy(() -> {
58 new JpaParticipantSupportedElementType(null, null);
59 }).hasMessageMatching(NULL_ID_ERROR);
61 assertThatThrownBy(() -> {
62 new JpaParticipantSupportedElementType(null, null, null, null);
63 }).hasMessageMatching(NULL_ID_ERROR);
65 assertThatThrownBy(() -> {
66 new JpaParticipantSupportedElementType("key", null, null, null);
67 }).hasMessageMatching(NULL_PARTICIPANT_ID_ERROR);
69 assertThatThrownBy(() -> {
70 new JpaParticipantSupportedElementType("key", "key", null, "1.0.0");
71 }).hasMessageMatching("typeName" + NULL_ERROR);
73 assertThatThrownBy(() -> {
74 new JpaParticipantSupportedElementType("key", "key", "name", null);
75 }).hasMessageMatching("typeVersion" + NULL_ERROR);
77 assertNotNull(new JpaParticipantSupportedElementType());
78 assertNotNull(new JpaParticipantSupportedElementType("key", "key"));
79 assertNotNull(new JpaParticipantSupportedElementType("key", "key", "name",
84 void testJpaParticipantSupportedElementType() {
85 var testJpaSupportElement = createJpaParticipantSupportedElementType();
87 var testSupportedElement = createParticipantSupportedElementType();
88 assertEquals(testSupportedElement.getId(), testJpaSupportElement.toAuthorative().getId());
89 assertEquals(testSupportedElement.getTypeName(), testJpaSupportElement.toAuthorative().getTypeName());
90 assertEquals(testSupportedElement.getTypeVersion(), testJpaSupportElement.toAuthorative().getTypeVersion());
92 assertThatThrownBy(() -> {
93 testJpaSupportElement.fromAuthorative(null);
94 }).hasMessageMatching("participantSupportedElementType is marked .*ull but is null");
96 assertThatThrownBy(() -> new JpaParticipantSupportedElementType((JpaParticipantSupportedElementType) null))
97 .isInstanceOf(NullPointerException.class);
99 var testJpaSupportElementFa =
100 new JpaParticipantSupportedElementType(testSupportedElement.getId().toString(),
101 testJpaSupportElement.getParticipantId());
102 testJpaSupportElementFa.fromAuthorative(testSupportedElement);
103 assertEquals(testJpaSupportElement, testJpaSupportElementFa);
105 assertEquals(ID, testJpaSupportElement.getId());
107 var testJpaSupportElement2 = new JpaParticipantSupportedElementType(testJpaSupportElement);
108 assertEquals(testJpaSupportElement, testJpaSupportElement2);
112 void testJpaAutomationCompositionElementCompareTo() {
113 var testJpaSupportElement = createJpaParticipantSupportedElementType();
115 var otherJpaSupportElement =
116 new JpaParticipantSupportedElementType(testJpaSupportElement);
117 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
118 assertEquals(-1, testJpaSupportElement.compareTo(null));
119 assertEquals(0, testJpaSupportElement.compareTo(testJpaSupportElement));
121 testJpaSupportElement.setId("BadValue");
122 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
123 testJpaSupportElement.setId(ID);
124 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
126 testJpaSupportElement.setParticipantId("BadValue");
127 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
128 testJpaSupportElement.setParticipantId(PARTICIPANT_ID);
129 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
131 testJpaSupportElement.setTypeName("BadName");
132 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
133 testJpaSupportElement.setTypeName("type");
134 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
136 testJpaSupportElement.setTypeVersion("BadVersion");
137 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
138 testJpaSupportElement.setTypeVersion("1.0.0");
139 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
141 assertEquals(testJpaSupportElement,
142 new JpaParticipantSupportedElementType(otherJpaSupportElement));
145 private JpaParticipantSupportedElementType createJpaParticipantSupportedElementType() {
146 var testSupportedElement = createParticipantSupportedElementType();
147 var testJpaSupportElement = new JpaParticipantSupportedElementType(testSupportedElement.getId().toString(),
150 testJpaSupportElement.fromAuthorative(testSupportedElement);
152 return testJpaSupportElement;
155 private ParticipantSupportedElementType createParticipantSupportedElementType() {
156 var testSupportedElement = new ParticipantSupportedElementType();
157 testSupportedElement.setId(UUID.fromString(ID));
158 testSupportedElement.setTypeName("type");
159 testSupportedElement.setTypeVersion("1.0.0");
161 return testSupportedElement;