2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2023 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2024 Nordix Foundation
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.tosca.simple.concepts;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import static org.junit.jupiter.api.Assertions.assertNotEquals;
28 import static org.junit.jupiter.api.Assertions.assertNull;
30 import java.util.ArrayList;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
35 * Test the {@link JpaToscaConstraintLogical} class.
37 * @author Liam Fallon (liam.fallon@est.tech)
39 class JpaToscaConstraintLogicalTest {
41 private static final String HELLO = "Hello";
44 void testLogicalConstraint() {
45 ToscaConstraint c0 = new ToscaConstraint();
47 JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
48 assertEquals(c0, jc0.toAuthorative());
50 ToscaConstraint c1 = new ToscaConstraint();
51 c1.setGreaterOrEqual(HELLO);
52 JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
53 assertEquals(c1, jc1.toAuthorative());
55 ToscaConstraint c2 = new ToscaConstraint();
56 c2.setGreaterThan(HELLO);
57 JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
58 assertEquals(c2, jc2.toAuthorative());
60 ToscaConstraint c3 = new ToscaConstraint();
61 c3.setLessOrEqual(HELLO);
62 JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
63 assertEquals(c3, jc3.toAuthorative());
65 ToscaConstraint c4 = new ToscaConstraint();
66 c4.setLessThan(HELLO);
67 JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
68 assertEquals(c4, jc4.toAuthorative());
70 ToscaConstraint c5 = new ToscaConstraint();
71 JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
72 assertNull(jc5.toAuthorative());
74 assertThatThrownBy(() -> jc0.compareTo(null)).isInstanceOf(NullPointerException.class);
75 assertEquals(0, jc0.compareTo(jc0));
76 assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>())));
77 assertEquals(-2, jc0.compareTo(jc1));