2987814a6924e5c39ede76fb38a17201fc3d4094
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaConstraintTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 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.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.assertNotNull;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import org.junit.Test;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
34
35 /**
36  * DAO test for ToscaConstraintLogicalString.
37  *
38  * @author Liam Fallon (liam.fallon@est.tech)
39  */
40 public class JpaToscaConstraintTest {
41
42     private static final String CONSTRAINT = "Constraint";
43
44     @Test
45     public void testConstraintLogicalStringPojo() {
46         assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
47
48         assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null))
49                 .hasMessageMatching("operation is marked .*on.*ull but is null");
50
51         assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello"))
52                 .hasMessageMatching("operation is marked .*on.*ull but is null");
53
54         assertThatThrownBy(() -> new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null))
55                 .hasMessageMatching("compareTo is marked .*on.*ull but is null");
56
57         assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
58
59         assertEquals(0, new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")
60                 .compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")));
61
62         JpaToscaConstraintOperation op = JpaToscaConstraintOperation.EQ;
63         assertEquals("equal_to", op.getToscaToken());
64
65         List<String> validValues = new ArrayList<>();
66         validValues.add("hello");
67         validValues.add("goodbye");
68         JpaToscaConstraintValidValues cvv0 = new JpaToscaConstraintValidValues(validValues);
69         assertEquals(-1, cvv0.compareTo(null));
70         assertEquals(0, cvv0.compareTo(cvv0));
71         assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT)));
72         JpaToscaConstraintValidValues cvv1 = new JpaToscaConstraintValidValues(validValues);
73         assertEquals(0, cvv0.compareTo(cvv1));
74
75         cvv1.fromAuthorative(new ToscaConstraint());
76         assertNotNull(cvv1.getValidValues());
77     }
78 }