53b42caa7b3466fc332ea908bbebfd49feb6e9a5
[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  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.tosca.simple.concepts;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNull;
27
28 import java.util.ArrayList;
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     private static final String HELLO = "Hello";
40
41     @Test
42     public void testLogicalConstraint() {
43         ToscaConstraint c0 = new ToscaConstraint();
44         c0.setEqual(HELLO);
45         JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
46         assertEquals(c0, jc0.toAuthorative());
47
48         ToscaConstraint c1 = new ToscaConstraint();
49         c1.setGreaterOrEqual(HELLO);
50         JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
51         assertEquals(c1, jc1.toAuthorative());
52
53         ToscaConstraint c2 = new ToscaConstraint();
54         c2.setGreaterThan(HELLO);
55         JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
56         assertEquals(c2, jc2.toAuthorative());
57
58         ToscaConstraint c3 = new ToscaConstraint();
59         c3.setLessOrEqual(HELLO);
60         JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
61         assertEquals(c3, jc3.toAuthorative());
62
63         ToscaConstraint c4 = new ToscaConstraint();
64         c4.setLessThan(HELLO);
65         JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
66         assertEquals(c4, jc4.toAuthorative());
67
68         ToscaConstraint c5 = new ToscaConstraint();
69         JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
70         assertNull(jc5.toAuthorative());
71
72         assertEquals(-1, jc0.compareTo(null));
73         assertEquals(0, jc0.compareTo(jc0));
74         assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>())));
75         assertEquals(-2, jc0.compareTo(jc1));
76     }
77 }