aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
blob: 2fdd29c5a09b8ebee04c1f584218dd7071f444be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2019, 2023 Nordix Foundation.
 *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.models.tosca.simple.concepts;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;

import java.util.ArrayList;
import org.junit.Test;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;

/**
 * Test the {@link JpaToscaConstraintLogical} class.
 *
 * @author Liam Fallon (liam.fallon@est.tech)
 */
public class JpaToscaConstraintLogicalTest {

    private static final String HELLO = "Hello";

    @Test
    public void testLogicalConstraint() {
        ToscaConstraint c0 = new ToscaConstraint();
        c0.setEqual(HELLO);
        JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
        assertEquals(c0, jc0.toAuthorative());

        ToscaConstraint c1 = new ToscaConstraint();
        c1.setGreaterOrEqual(HELLO);
        JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
        assertEquals(c1, jc1.toAuthorative());

        ToscaConstraint c2 = new ToscaConstraint();
        c2.setGreaterThan(HELLO);
        JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
        assertEquals(c2, jc2.toAuthorative());

        ToscaConstraint c3 = new ToscaConstraint();
        c3.setLessOrEqual(HELLO);
        JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
        assertEquals(c3, jc3.toAuthorative());

        ToscaConstraint c4 = new ToscaConstraint();
        c4.setLessThan(HELLO);
        JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
        assertEquals(c4, jc4.toAuthorative());

        ToscaConstraint c5 = new ToscaConstraint();
        JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
        assertNull(jc5.toAuthorative());

        assertThatThrownBy(() -> jc0.compareTo(null)).isInstanceOf(NullPointerException.class);
        assertEquals(0, jc0.compareTo(jc0));
        assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>())));
        assertEquals(-2, jc0.compareTo(jc1));
    }
}