2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2023 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.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNull;
29 import java.util.ArrayList;
30 import org.junit.Test;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
34 * Test the {@link JpaToscaConstraintLogical} class.
36 * @author Liam Fallon (liam.fallon@est.tech)
38 public class JpaToscaConstraintLogicalTest {
40 private static final String HELLO = "Hello";
43 public void testLogicalConstraint() {
44 ToscaConstraint c0 = new ToscaConstraint();
46 JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
47 assertEquals(c0, jc0.toAuthorative());
49 ToscaConstraint c1 = new ToscaConstraint();
50 c1.setGreaterOrEqual(HELLO);
51 JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
52 assertEquals(c1, jc1.toAuthorative());
54 ToscaConstraint c2 = new ToscaConstraint();
55 c2.setGreaterThan(HELLO);
56 JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
57 assertEquals(c2, jc2.toAuthorative());
59 ToscaConstraint c3 = new ToscaConstraint();
60 c3.setLessOrEqual(HELLO);
61 JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
62 assertEquals(c3, jc3.toAuthorative());
64 ToscaConstraint c4 = new ToscaConstraint();
65 c4.setLessThan(HELLO);
66 JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
67 assertEquals(c4, jc4.toAuthorative());
69 ToscaConstraint c5 = new ToscaConstraint();
70 JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
71 assertNull(jc5.toAuthorative());
73 assertThatThrownBy(() -> jc0.compareTo(null)).isInstanceOf(NullPointerException.class);
74 assertEquals(0, jc0.compareTo(jc0));
75 assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>())));
76 assertEquals(-2, jc0.compareTo(jc1));