2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.tosca.simple.concepts;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.junit.Test;
34 import org.onap.policy.models.base.PfConceptKey;
35 import org.onap.policy.models.base.PfValidationResult;
38 * DAO test for ToscaEntrySchema.
40 * @author Liam Fallon (liam.fallon@est.tech)
42 public class JpaToscaEntrySchemaTest {
44 private static final String A_DESCRIPTION = "A Description";
47 public void testEntrySchemaPojo() {
48 assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
49 assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
51 assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null))
52 .hasMessageMatching("type is marked .*on.*ull but is null");
54 assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null))
55 .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
57 PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
58 JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
60 tes.setDescription(A_DESCRIPTION);
61 assertEquals(A_DESCRIPTION, tes.getDescription());
63 List<JpaToscaConstraint> constraints = new ArrayList<>();
64 JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
66 tes.setConstraints(constraints);
67 assertEquals(constraints, tes.getConstraints());
69 JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes);
70 assertEquals(tes, tdtClone0);
71 assertEquals(0, tes.compareTo(tdtClone0));
73 JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes);
74 assertEquals(tes, tdtClone1);
75 assertEquals(0, tes.compareTo(tdtClone1));
77 assertEquals(-1, tes.compareTo(null));
78 assertEquals(0, tes.compareTo(tes));
80 JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey);
82 assertFalse(tes.compareTo(otherEs) == 0);
83 otherEs.setType(typeKey);
84 assertFalse(tes.compareTo(otherEs) == 0);
85 otherEs.setDescription(A_DESCRIPTION);
86 assertFalse(tes.compareTo(otherEs) == 0);
87 otherEs.setConstraints(constraints);
88 assertEquals(0, tes.compareTo(otherEs));
90 assertThatThrownBy(() -> tes.copyTo(null)).hasMessageMatching("target is marked .*on.*ull but is null");
92 assertEquals(1, tes.getKeys().size());
93 assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
95 new JpaToscaEntrySchema(typeKey).clean();
97 assertEquals(tdtClone0, tes);
99 assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid());
100 assertTrue(tes.validate(new PfValidationResult()).isValid());
102 tes.setType(PfConceptKey.getNullKey());
103 assertFalse(tes.validate(new PfValidationResult()).isValid());
105 assertFalse(tes.validate(new PfValidationResult()).isValid());
106 tes.setType(typeKey);
107 assertTrue(tes.validate(new PfValidationResult()).isValid());
109 tes.setDescription("");
111 assertFalse(tes.validate(new PfValidationResult()).isValid());
112 tes.setDescription(A_DESCRIPTION);
113 assertTrue(tes.validate(new PfValidationResult()).isValid());
115 tes.getConstraints().add(null);
116 assertFalse(tes.validate(new PfValidationResult()).isValid());
117 tes.getConstraints().remove(null);
118 assertTrue(tes.validate(new PfValidationResult()).isValid());
120 assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");