2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023,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
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.assertDoesNotThrow;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertNotEquals;
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 assertDoesNotThrow(() -> new JpaParticipantSupportedElementType("key", "key"));
78 assertDoesNotThrow(() -> new JpaParticipantSupportedElementType("key", "key", "name",
83 void testJpaParticipantSupportedElementType() {
84 var testJpaSupportElement = createJpaParticipantSupportedElementType();
86 var testSupportedElement = createParticipantSupportedElementType();
87 assertEquals(testSupportedElement.getId(), testJpaSupportElement.toAuthorative().getId());
88 assertEquals(testSupportedElement.getTypeName(), testJpaSupportElement.toAuthorative().getTypeName());
89 assertEquals(testSupportedElement.getTypeVersion(), testJpaSupportElement.toAuthorative().getTypeVersion());
91 assertThatThrownBy(() -> {
92 testJpaSupportElement.fromAuthorative(null);
93 }).hasMessageMatching("participantSupportedElementType is marked .*ull but is null");
95 assertThatThrownBy(() -> new JpaParticipantSupportedElementType((JpaParticipantSupportedElementType) null))
96 .isInstanceOf(NullPointerException.class);
98 var testJpaSupportElementFa =
99 new JpaParticipantSupportedElementType(testSupportedElement.getId().toString(),
100 testJpaSupportElement.getParticipantId());
101 testJpaSupportElementFa.fromAuthorative(testSupportedElement);
102 assertEquals(testJpaSupportElement, testJpaSupportElementFa);
104 assertEquals(ID, testJpaSupportElement.getId());
106 var testJpaSupportElement2 = new JpaParticipantSupportedElementType(testJpaSupportElement);
107 assertEquals(testJpaSupportElement, testJpaSupportElement2);
111 void testJpaAutomationCompositionElementCompareTo() {
112 var testJpaSupportElement = createJpaParticipantSupportedElementType();
114 var otherJpaSupportElement =
115 new JpaParticipantSupportedElementType(testJpaSupportElement);
116 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
117 assertEquals(-1, testJpaSupportElement.compareTo(null));
118 assertEquals(0, testJpaSupportElement.compareTo(testJpaSupportElement));
120 testJpaSupportElement.setId("BadValue");
121 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
122 testJpaSupportElement.setId(ID);
123 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
125 testJpaSupportElement.setParticipantId("BadValue");
126 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
127 testJpaSupportElement.setParticipantId(PARTICIPANT_ID);
128 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
130 testJpaSupportElement.setTypeName("BadName");
131 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
132 testJpaSupportElement.setTypeName("type");
133 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
135 testJpaSupportElement.setTypeVersion("BadVersion");
136 assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
137 testJpaSupportElement.setTypeVersion("1.0.0");
138 assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement));
140 assertEquals(testJpaSupportElement,
141 new JpaParticipantSupportedElementType(otherJpaSupportElement));
144 private JpaParticipantSupportedElementType createJpaParticipantSupportedElementType() {
145 var testSupportedElement = createParticipantSupportedElementType();
146 var testJpaSupportElement = new JpaParticipantSupportedElementType(testSupportedElement.getId().toString(),
149 testJpaSupportElement.fromAuthorative(testSupportedElement);
151 return testJpaSupportElement;
154 private ParticipantSupportedElementType createParticipantSupportedElementType() {
155 var testSupportedElement = new ParticipantSupportedElementType();
156 testSupportedElement.setId(UUID.fromString(ID));
157 testSupportedElement.setTypeName("type");
158 testSupportedElement.setTypeVersion("1.0.0");
160 return testSupportedElement;