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.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;
35 * DAO test for ToscaConstraintLogicalString.
37 * @author Liam Fallon (liam.fallon@est.tech)
39 public class ToscaConstraintLogicalStringTest {
42 public void testConstraintLogicalStringPojo() {
43 assertNotNull(new ToscaConstraintLogicalString());
44 assertNotNull(new ToscaConstraintLogicalString(new PfReferenceKey()));
45 assertNotNull(new ToscaConstraintLogicalString(new PfReferenceKey(), ToscaConstraintLogicalString.Operation.EQ,
49 new ToscaConstraintLogicalString((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 ToscaConstraintLogicalString((ToscaConstraintLogicalString) 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 ToscaConstraintLogicalString tcl =
65 new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "Constraint");
68 new ToscaConstraintLogicalString(tcl);
69 fail("test should throw an exception");
70 } catch (Exception exc) {
71 assertEquals("cannot copy an immutable constraint", exc.getMessage());
74 ToscaConstraintLogicalString tclClone1 = new ToscaConstraintLogicalString();
76 tcl.copyTo(tclClone1);
77 fail("test should throw an exception");
78 } catch (Exception exc) {
79 assertEquals("cannot copy an immutable constraint", exc.getMessage());
81 tclClone1 = new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "Constraint");
83 assertEquals(tcl, tclClone1);
84 assertEquals(0, tcl.compareTo(tclClone1));
86 assertEquals(-1, tcl.compareTo(null));
87 assertEquals(0, tcl.compareTo(tcl));
88 assertFalse(tcl.compareTo(tcl.getKey()) == 0);
90 ToscaConstraintLogicalString differentTcl = new ToscaConstraintLogicalString(new PfReferenceKey(),
91 ToscaConstraintLogicalString.Operation.EQ, "Constraint");
92 assertFalse(tcl.compareTo(differentTcl) == 0);
94 ToscaConstraintLogicalString otherTc =
95 new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "Constraint");
96 assertEquals(0, tcl.compareTo(otherTc));
100 fail("test should throw an exception");
101 } catch (Exception exc) {
102 assertEquals("target is marked @NonNull but is null", exc.getMessage());
105 assertEquals(1, tcl.getKeys().size());
106 assertEquals(1, new ToscaConstraintLogicalString().getKeys().size());
108 new ToscaConstraintLogicalString().clean();
110 assertEquals(tclClone1, tcl);
112 assertFalse(new ToscaConstraintLogicalString().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());
123 new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, null)
124 .validate(new PfValidationResult());
125 fail("test should throw an exception");
126 } catch (Exception exc) {
127 assertEquals("compareToString is marked @NonNull but is null", exc.getMessage());
130 assertFalse(new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "")
131 .validate(new PfValidationResult()).isValid());