2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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;
32 import org.junit.Test;
33 import org.onap.policy.models.base.PfConceptKey;
34 import org.onap.policy.models.base.PfValidationResult;
37 * DAO test for ToscaEntrySchema.
39 * @author Liam Fallon (liam.fallon@est.tech)
41 public class JpaToscaEntrySchemaTest {
43 private static final String A_DESCRIPTION = "A Description";
46 public void testEntrySchemaPojo() {
47 assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
48 assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
50 assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null))
51 .hasMessage("type is marked @NonNull but is null");
53 assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null))
54 .hasMessage("copyConcept is marked @NonNull but is null");
56 PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
57 JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
59 tes.setDescription(A_DESCRIPTION);
60 assertEquals(A_DESCRIPTION, tes.getDescription());
62 List<JpaToscaConstraint> constraints = new ArrayList<>();
63 JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
65 tes.setConstraints(constraints);
66 assertEquals(constraints, tes.getConstraints());
68 JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes);
69 assertEquals(tes, tdtClone0);
70 assertEquals(0, tes.compareTo(tdtClone0));
72 JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes);
73 assertEquals(tes, tdtClone1);
74 assertEquals(0, tes.compareTo(tdtClone1));
76 assertEquals(-1, tes.compareTo(null));
77 assertEquals(0, tes.compareTo(tes));
79 JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey);
81 assertFalse(tes.compareTo(otherEs) == 0);
82 otherEs.setType(typeKey);
83 assertFalse(tes.compareTo(otherEs) == 0);
84 otherEs.setDescription(A_DESCRIPTION);
85 assertFalse(tes.compareTo(otherEs) == 0);
86 otherEs.setConstraints(constraints);
87 assertEquals(0, tes.compareTo(otherEs));
89 assertThatThrownBy(() -> tes.copyTo(null)).hasMessage("target is marked @NonNull but is null");
91 assertEquals(1, tes.getKeys().size());
92 assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
94 new JpaToscaEntrySchema(typeKey).clean();
96 assertEquals(tdtClone0, tes);
98 assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid());
99 assertTrue(tes.validate(new PfValidationResult()).isValid());
101 tes.setType(PfConceptKey.getNullKey());
102 assertFalse(tes.validate(new PfValidationResult()).isValid());
104 assertFalse(tes.validate(new PfValidationResult()).isValid());
105 tes.setType(typeKey);
106 assertTrue(tes.validate(new PfValidationResult()).isValid());
108 tes.setDescription("");;
109 assertFalse(tes.validate(new PfValidationResult()).isValid());
110 tes.setDescription(A_DESCRIPTION);
111 assertTrue(tes.validate(new PfValidationResult()).isValid());
113 tes.getConstraints().add(null);
114 assertFalse(tes.validate(new PfValidationResult()).isValid());
115 tes.getConstraints().remove(null);
116 assertTrue(tes.validate(new PfValidationResult()).isValid());
118 assertThatThrownBy(() -> tes.validate(null)).hasMessage("resultIn is marked @NonNull but is null");