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.ToscaConstraintLogical;
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 ToscaConstraintLogicalTest {
44 public void testConstraintLogicalPojo() {
45 assertNotNull(new ToscaConstraintLogical());
46 assertNotNull(new ToscaConstraintLogical(new PfReferenceKey()));
49 new ToscaConstraintLogical((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 ToscaConstraintLogical((ToscaConstraintLogical) 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 ToscaConstraintLogical tcl = new ToscaConstraintLogical(tclKey, ToscaConstraintLogical.Operation.EQ);
67 new ToscaConstraintLogical(tcl);
68 fail("test should throw an exception");
69 } catch (Exception exc) {
70 assertEquals("cannot copy an immutable constraint", exc.getMessage());
73 ToscaConstraintLogical tclClone1 = new ToscaConstraintLogical();
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 ToscaConstraintLogical(tclKey, ToscaConstraintLogical.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 ToscaConstraintLogical differentTcl =
90 new ToscaConstraintLogical(new PfReferenceKey(), ToscaConstraintLogical.Operation.EQ);
91 assertFalse(tcl.compareTo(differentTcl) == 0);
93 ToscaConstraintLogical otherTc = new ToscaConstraintLogical(tclKey, ToscaConstraintLogical.Operation.EQ);
94 assertEquals(0, tcl.compareTo(otherTc));
98 fail("test should throw an exception");
99 } catch (Exception exc) {
100 assertEquals("target is marked @NonNull but is null", exc.getMessage());
103 assertEquals(1, tcl.getKeys().size());
104 assertEquals(1, new ToscaConstraintLogical().getKeys().size());
106 ToscaConstraintLogical tclClone0 = new ToscaConstraintLogical();
107 new ToscaConstraintLogical().clean();
109 assertEquals(tclClone0, tcl);
111 assertFalse(new ToscaConstraintLogical().validate(new PfValidationResult()).isValid());
112 assertTrue(tcl.validate(new PfValidationResult()).isValid());
116 fail("test should throw an exception");
117 } catch (Exception exc) {
118 assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
121 DummyToscaConstraint dtc = new DummyToscaConstraint();
123 new DummyToscaConstraint(dtc);
124 fail("test should throw an exception");
125 } catch (Exception exc) {
126 assertEquals("cannot copy an immutable constraint", exc.getMessage());
130 new DummyToscaConstraint((PfReferenceKey)null);
131 fail("test should throw an exception");
132 } catch (Exception exc) {
133 assertEquals("key is marked @NonNull but is null", exc.getMessage());
137 new DummyToscaConstraint((DummyToscaConstraint)null);
138 fail("test should throw an exception");
139 } catch (Exception exc) {
140 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
143 DummyToscaConstraint dtcClone = new DummyToscaConstraint();
145 assertEquals(dtc, dtcClone);
146 assertEquals(dtc, dtc);
147 assertEquals(0, dtc.compareTo(dtcClone));
148 assertEquals(0, dtc.compareTo(dtc));
149 assertEquals(-1, dtc.compareTo(null));
150 assertEquals(0, dtc.compareTo(dtcClone));
151 assertFalse(dtc.compareTo(dtcClone.getKey()) == 0);
155 fail("test should throw an exception");
156 } catch (Exception exc) {
157 assertEquals("target is marked @NonNull but is null", exc.getMessage());
161 dtc.copyTo(dtcClone);
162 fail("target should throw an exception");
163 } catch (Exception exc) {
164 assertEquals("cannot copy an immutable constraint", exc.getMessage());