Merge "Convert models to JUnit 5"
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaConstraintLogicalTest.java
1 /*-
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.tosca.simple.concepts;
24
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;
29
30 import java.util.ArrayList;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
33
34 /**
35  * Test the {@link JpaToscaConstraintLogical} class.
36  *
37  * @author Liam Fallon (liam.fallon@est.tech)
38  */
39 class JpaToscaConstraintLogicalTest {
40
41     private static final String HELLO = "Hello";
42
43     @Test
44     void testLogicalConstraint() {
45         ToscaConstraint c0 = new ToscaConstraint();
46         c0.setEqual(HELLO);
47         JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
48         assertEquals(c0, jc0.toAuthorative());
49
50         ToscaConstraint c1 = new ToscaConstraint();
51         c1.setGreaterOrEqual(HELLO);
52         JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
53         assertEquals(c1, jc1.toAuthorative());
54
55         ToscaConstraint c2 = new ToscaConstraint();
56         c2.setGreaterThan(HELLO);
57         JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
58         assertEquals(c2, jc2.toAuthorative());
59
60         ToscaConstraint c3 = new ToscaConstraint();
61         c3.setLessOrEqual(HELLO);
62         JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
63         assertEquals(c3, jc3.toAuthorative());
64
65         ToscaConstraint c4 = new ToscaConstraint();
66         c4.setLessThan(HELLO);
67         JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
68         assertEquals(c4, jc4.toAuthorative());
69
70         ToscaConstraint c5 = new ToscaConstraint();
71         JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
72         assertNull(jc5.toAuthorative());
73
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));
78     }
79 }