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 java.util.ArrayList;
30 import java.util.List;
32 import org.junit.Test;
33 import org.onap.policy.models.base.PfConceptKey;
34 import org.onap.policy.models.base.PfReferenceKey;
35 import org.onap.policy.models.base.PfValidationResult;
36 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
37 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
38 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
39 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
42 * DAO test for ToscaEntrySchema.
44 * @author Liam Fallon (liam.fallon@est.tech)
46 public class JpaToscaEntrySchemaTest {
49 public void testEntrySchemaPojo() {
50 assertNotNull(new JpaToscaEntrySchema());
51 assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey()));
52 assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey(), new PfConceptKey()));
53 assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema()));
56 new JpaToscaEntrySchema((PfReferenceKey) null);
57 fail("test should throw an exception");
58 } catch (Exception exc) {
59 assertEquals("key is marked @NonNull but is null", exc.getMessage());
63 new JpaToscaEntrySchema((JpaToscaEntrySchema) null);
64 fail("test should throw an exception");
65 } catch (Exception exc) {
66 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
69 PfReferenceKey esKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "entrySchema");
70 PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
71 JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey);
73 tes.setDescription("A Description");
74 assertEquals("A Description", tes.getDescription());
76 List<JpaToscaConstraint> constraints = new ArrayList<>();
77 JpaToscaConstraintLogicalString lsc =
78 new JpaToscaConstraintLogicalString(new PfReferenceKey(esKey, "sc"), Operation.EQ, "hello");
80 tes.setConstraints(constraints);
81 assertEquals(constraints, tes.getConstraints());
83 JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes);
84 assertEquals(tes, tdtClone0);
85 assertEquals(0, tes.compareTo(tdtClone0));
87 JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema();
88 tes.copyTo(tdtClone1);
89 assertEquals(tes, tdtClone1);
90 assertEquals(0, tes.compareTo(tdtClone1));
92 assertEquals(-1, tes.compareTo(null));
93 assertEquals(0, tes.compareTo(tes));
94 assertFalse(tes.compareTo(tes.getKey()) == 0);
96 PfReferenceKey otherEsKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "otherEntrySchema");
97 JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(otherEsKey);
99 assertFalse(tes.compareTo(otherEs) == 0);
100 otherEs.setKey(esKey);
101 assertFalse(tes.compareTo(otherEs) == 0);
102 otherEs.setType(typeKey);
103 assertFalse(tes.compareTo(otherEs) == 0);
104 otherEs.setDescription("A Description");
105 assertFalse(tes.compareTo(otherEs) == 0);
106 otherEs.setConstraints(constraints);
107 assertEquals(0, tes.compareTo(otherEs));
111 fail("test should throw an exception");
112 } catch (Exception exc) {
113 assertEquals("target is marked @NonNull but is null", exc.getMessage());
116 assertEquals(3, tes.getKeys().size());
117 assertEquals(2, new JpaToscaEntrySchema().getKeys().size());
119 new JpaToscaEntrySchema().clean();
121 assertEquals(tdtClone0, tes);
123 assertFalse(new JpaToscaEntrySchema().validate(new PfValidationResult()).isValid());
124 assertTrue(tes.validate(new PfValidationResult()).isValid());
126 tes.setType(PfConceptKey.getNullKey());
127 assertFalse(tes.validate(new PfValidationResult()).isValid());
129 assertFalse(tes.validate(new PfValidationResult()).isValid());
130 tes.setType(typeKey);
131 assertTrue(tes.validate(new PfValidationResult()).isValid());
133 tes.setDescription("");;
134 assertFalse(tes.validate(new PfValidationResult()).isValid());
135 tes.setDescription("A Description");
136 assertTrue(tes.validate(new PfValidationResult()).isValid());
138 tes.getConstraints().add(null);
139 assertFalse(tes.validate(new PfValidationResult()).isValid());
140 tes.getConstraints().remove(null);
141 assertTrue(tes.validate(new PfValidationResult()).isValid());
145 fail("test should throw an exception");
146 } catch (Exception exc) {
147 assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());