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.JpaToscaEventFilter;
36 * DAO test for ToscaEventFilter.
38 * @author Liam Fallon (liam.fallon@est.tech)
40 public class JpaToscaEventFilterTest {
43 public void testEventFilterPojo() {
44 assertNotNull(new JpaToscaEventFilter());
45 assertNotNull(new JpaToscaEventFilter(new PfReferenceKey()));
46 assertNotNull(new JpaToscaEventFilter(new PfReferenceKey(), new PfConceptKey()));
47 assertNotNull(new JpaToscaEventFilter(new JpaToscaEventFilter()));
50 new JpaToscaEventFilter((PfReferenceKey) null);
51 fail("test should throw an exception");
52 } catch (Exception exc) {
53 assertEquals("key is marked @NonNull but is null", exc.getMessage());
57 new JpaToscaEventFilter(null, null);
58 fail("test should throw an exception");
59 } catch (Exception exc) {
60 assertEquals("key is marked @NonNull but is null", exc.getMessage());
64 new JpaToscaEventFilter(null, new PfConceptKey());
65 fail("test should throw an exception");
66 } catch (Exception exc) {
67 assertEquals("key is marked @NonNull but is null", exc.getMessage());
71 new JpaToscaEventFilter(new PfReferenceKey(), null);
72 fail("test should throw an exception");
73 } catch (Exception exc) {
74 assertEquals("node is marked @NonNull but is null", exc.getMessage());
78 new JpaToscaEventFilter((JpaToscaEventFilter) null);
79 fail("test should throw an exception");
80 } catch (Exception exc) {
81 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
84 PfConceptKey efParentKey = new PfConceptKey("tParentKey", "0.0.1");
85 PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
86 PfConceptKey nodeKey = new PfConceptKey("tParentKey", "0.0.1");
87 JpaToscaEventFilter tef = new JpaToscaEventFilter(efKey, nodeKey);
89 tef.setRequirement("A Requrement");
90 assertEquals("A Requrement", tef.getRequirement());
92 tef.setCapability("A Capability");
93 assertEquals("A Capability", tef.getCapability());
95 JpaToscaEventFilter tdtClone0 = new JpaToscaEventFilter(tef);
96 assertEquals(tef, tdtClone0);
97 assertEquals(0, tef.compareTo(tdtClone0));
99 JpaToscaEventFilter tdtClone1 = new JpaToscaEventFilter();
100 tef.copyTo(tdtClone1);
101 assertEquals(tef, tdtClone1);
102 assertEquals(0, tef.compareTo(tdtClone1));
104 assertEquals(-1, tef.compareTo(null));
105 assertEquals(0, tef.compareTo(tef));
106 assertFalse(tef.compareTo(tef.getKey()) == 0);
108 PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherEventFilter");
109 JpaToscaEventFilter otherDt = new JpaToscaEventFilter(otherDtKey);
111 assertFalse(tef.compareTo(otherDt) == 0);
112 otherDt.setKey(efKey);
113 assertFalse(tef.compareTo(otherDt) == 0);
114 otherDt.setNode(nodeKey);
115 assertFalse(tef.compareTo(otherDt) == 0);
116 otherDt.setRequirement("A Requrement");
117 assertFalse(tef.compareTo(otherDt) == 0);
118 otherDt.setCapability("A Capability");
119 assertEquals(0, tef.compareTo(otherDt));
123 fail("test should throw an exception");
124 } catch (Exception exc) {
125 assertEquals("target is marked @NonNull but is null", exc.getMessage());
128 assertEquals(2, tef.getKeys().size());
129 assertEquals(2, new JpaToscaEventFilter().getKeys().size());
131 new JpaToscaEventFilter().clean();
133 assertEquals(tdtClone0, tef);
135 assertFalse(new JpaToscaEventFilter().validate(new PfValidationResult()).isValid());
136 assertTrue(tef.validate(new PfValidationResult()).isValid());
138 tef.setRequirement(null);
139 assertTrue(tef.validate(new PfValidationResult()).isValid());
140 tef.setRequirement("");
141 assertFalse(tef.validate(new PfValidationResult()).isValid());
142 tef.setRequirement("A Requrement");
143 assertTrue(tef.validate(new PfValidationResult()).isValid());
145 tef.setCapability(null);
146 assertTrue(tef.validate(new PfValidationResult()).isValid());
147 tef.setCapability("");
148 assertFalse(tef.validate(new PfValidationResult()).isValid());
149 tef.setCapability("A Capability");
150 assertTrue(tef.validate(new PfValidationResult()).isValid());
153 assertFalse(tef.validate(new PfValidationResult()).isValid());
154 tef.setNode(PfConceptKey.getNullKey());
155 assertFalse(tef.validate(new PfValidationResult()).isValid());
156 tef.setNode(nodeKey);
157 assertTrue(tef.validate(new PfValidationResult()).isValid());
161 fail("test should throw an exception");
162 } catch (Exception exc) {
163 assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());