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.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
29 import org.junit.Test;
30 import org.onap.policy.models.base.PfConceptKey;
31 import org.onap.policy.models.base.PfReferenceKey;
32 import org.onap.policy.models.base.PfValidationResult;
33 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
34 import org.onap.policy.models.tosca.simple.concepts.testconcepts.DummyToscaConstraint;
37 * DAO test for ToscaConstraintLogical.
39 * @author Liam Fallon (liam.fallon@est.tech)
41 public class JpaToscaConstraintLogicalTest {
44 public void testConstraintLogicalPojo() {
45 assertNotNull(new JpaToscaConstraintLogical());
46 assertNotNull(new JpaToscaConstraintLogical(new PfReferenceKey()));
49 new JpaToscaConstraintLogical((PfReferenceKey) null);
50 fail("test should throw an exception");
51 } catch (Exception exc) {
52 assertEquals("key is marked @NonNull but is null", exc.getMessage());
56 new JpaToscaConstraintLogical((JpaToscaConstraintLogical) null);
57 fail("test should throw an exception");
58 } catch (Exception exc) {
59 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
62 PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
63 PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
64 JpaToscaConstraintLogical tcl = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
67 new JpaToscaConstraintLogical(tcl);
68 fail("test should throw an exception");
69 } catch (Exception exc) {
70 assertEquals("cannot copy an immutable constraint", exc.getMessage());
73 JpaToscaConstraintLogical tclClone1 = new JpaToscaConstraintLogical();
75 tcl.copyTo(tclClone1);
76 fail("test should throw an exception");
77 } catch (Exception exc) {
78 assertEquals("cannot copy an immutable constraint", exc.getMessage());
80 tclClone1 = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
82 assertEquals(tcl, tclClone1);
83 assertEquals(0, tcl.compareTo(tclClone1));
85 assertEquals(-1, tcl.compareTo(null));
86 assertEquals(0, tcl.compareTo(tcl));
87 assertFalse(tcl.compareTo(tcl.getKey()) == 0);
89 JpaToscaConstraintLogical differentTcl =
90 new JpaToscaConstraintLogical(new PfReferenceKey(), JpaToscaConstraintLogical.Operation.EQ);
91 assertFalse(tcl.compareTo(differentTcl) == 0);
93 JpaToscaConstraintLogical otherTc =
94 new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
95 assertEquals(0, tcl.compareTo(otherTc));
99 fail("test should throw an exception");
100 } catch (Exception exc) {
101 assertEquals("target is marked @NonNull but is null", exc.getMessage());
104 assertEquals(1, tcl.getKeys().size());
105 assertEquals(1, new JpaToscaConstraintLogical().getKeys().size());
107 JpaToscaConstraintLogical tclClone0 = new JpaToscaConstraintLogical();
108 new JpaToscaConstraintLogical().clean();
110 assertEquals(tclClone0, tcl);
112 assertFalse(new JpaToscaConstraintLogical().validate(new PfValidationResult()).isValid());
113 assertTrue(tcl.validate(new PfValidationResult()).isValid());
117 fail("test should throw an exception");
118 } catch (Exception exc) {
119 assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
122 DummyToscaConstraint dtc = new DummyToscaConstraint();
124 new DummyToscaConstraint(dtc);
125 fail("test should throw an exception");
126 } catch (Exception exc) {
127 assertEquals("cannot copy an immutable constraint", exc.getMessage());
131 new DummyToscaConstraint((PfReferenceKey) null);
132 fail("test should throw an exception");
133 } catch (Exception exc) {
134 assertEquals("key is marked @NonNull but is null", exc.getMessage());
138 new DummyToscaConstraint((DummyToscaConstraint) null);
139 fail("test should throw an exception");
140 } catch (Exception exc) {
141 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
144 DummyToscaConstraint dtcClone = new DummyToscaConstraint();
146 assertEquals(dtc, dtcClone);
147 assertEquals(dtc, dtc);
148 assertEquals(0, dtc.compareTo(dtcClone));
149 assertEquals(0, dtc.compareTo(dtc));
150 assertEquals(-1, dtc.compareTo(null));
151 assertEquals(0, dtc.compareTo(dtcClone));
152 assertFalse(dtc.compareTo(dtcClone.getKey()) == 0);
156 fail("test should throw an exception");
157 } catch (Exception exc) {
158 assertEquals("target is marked @NonNull but is null", exc.getMessage());
162 dtc.copyTo(dtcClone);
163 fail("target should throw an exception");
164 } catch (Exception exc) {
165 assertEquals("cannot copy an immutable constraint", exc.getMessage());