d3239da73e15884348d9f0bd83cc5f81d7e91db5
[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 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.models.tosca.simple.concepts;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
25 import static org.junit.Assert.assertNull;
26
27 import java.util.ArrayList;
28
29 import org.junit.Test;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
31
32 /**
33  * Test the {@link JpaToscaConstraintLogical} class.
34  *
35  * @author Liam Fallon (liam.fallon@est.tech)
36  */
37 public class JpaToscaConstraintLogicalTest {
38
39     @Test
40     public void testLogicalConstraint() {
41         ToscaConstraint c0 = new ToscaConstraint();
42         c0.setEqual("Hello");
43         JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
44         assertEquals(c0, jc0.toAuthorative());
45
46         ToscaConstraint c1 = new ToscaConstraint();
47         c1.setGreaterOrEqual("Hello");
48         JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
49         assertEquals(c1, jc1.toAuthorative());
50
51         ToscaConstraint c2 = new ToscaConstraint();
52         c2.setGreaterThan("Hello");
53         JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
54         assertEquals(c2, jc2.toAuthorative());
55
56         ToscaConstraint c3 = new ToscaConstraint();
57         c3.setLessOrEqual("Hello");
58         JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
59         assertEquals(c3, jc3.toAuthorative());
60
61         ToscaConstraint c4 = new ToscaConstraint();
62         c4.setLessThan("Hello");
63         JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
64         assertEquals(c4, jc4.toAuthorative());
65
66         ToscaConstraint c5 = new ToscaConstraint();
67         JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
68         assertNull(jc5.toAuthorative());
69
70         assertEquals(-1, jc0.compareTo(null));
71         assertEquals(0, jc0.compareTo(jc0));
72         assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>())));
73         assertEquals(-2, jc0.compareTo(jc1));
74     }
75 }