2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.simple.concepts;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.fail;
28 import java.util.ArrayList;
29 import java.util.List;
31 import org.junit.Test;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
33 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
36 * DAO test for ToscaConstraintLogicalString.
38 * @author Liam Fallon (liam.fallon@est.tech)
40 public class JpaToscaConstraintTest {
43 public void testConstraintLogicalStringPojo() {
44 assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
47 new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null);
48 fail("test should throw an exception");
49 } catch (Exception exc) {
50 assertEquals("operation is marked @NonNull but is null", exc.getMessage());
54 new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello");
55 fail("test should throw an exception");
56 } catch (Exception exc) {
57 assertEquals("operation is marked @NonNull but is null", exc.getMessage());
61 new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null);
62 fail("test should throw an exception");
63 } catch (Exception exc) {
64 assertEquals("compareTo is marked @NonNull but is null", exc.getMessage());
67 assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
69 assertEquals(0, new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")
70 .compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")));
72 JpaToscaConstraintOperation op = JpaToscaConstraintOperation.EQ;
73 assertEquals("equal_to", op.getToscaToken());
75 List<String> validValues = new ArrayList<>();
76 validValues.add("hello");
77 validValues.add("goodbye");
78 JpaToscaConstraintValidValues cvv0 = new JpaToscaConstraintValidValues(validValues);
79 assertEquals(-1, cvv0.compareTo(null));
80 assertEquals(0, cvv0.compareTo(cvv0));
81 assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")));
82 JpaToscaConstraintValidValues cvv1 = new JpaToscaConstraintValidValues(validValues);
83 assertEquals(0, cvv0.compareTo(cvv1));
85 cvv1.fromAuthorative(new ToscaConstraint());
86 assertNotNull(cvv1.getValidValues());