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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.tosca.simple.concepts;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNull;
28 import java.util.ArrayList;
29 import org.junit.Test;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
33 * Test the {@link JpaToscaConstraintLogical} class.
35 * @author Liam Fallon (liam.fallon@est.tech)
37 public class JpaToscaConstraintLogicalTest {
39 private static final String HELLO = "Hello";
42 public void testLogicalConstraint() {
43 ToscaConstraint c0 = new ToscaConstraint();
45 JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
46 assertEquals(c0, jc0.toAuthorative());
48 ToscaConstraint c1 = new ToscaConstraint();
49 c1.setGreaterOrEqual(HELLO);
50 JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
51 assertEquals(c1, jc1.toAuthorative());
53 ToscaConstraint c2 = new ToscaConstraint();
54 c2.setGreaterThan(HELLO);
55 JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
56 assertEquals(c2, jc2.toAuthorative());
58 ToscaConstraint c3 = new ToscaConstraint();
59 c3.setLessOrEqual(HELLO);
60 JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
61 assertEquals(c3, jc3.toAuthorative());
63 ToscaConstraint c4 = new ToscaConstraint();
64 c4.setLessThan(HELLO);
65 JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
66 assertEquals(c4, jc4.toAuthorative());
68 ToscaConstraint c5 = new ToscaConstraint();
69 JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
70 assertNull(jc5.toAuthorative());
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));