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.PfValidationResult;
35 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
36 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
39 * DAO test for ToscaEntrySchema.
41 * @author Liam Fallon (liam.fallon@est.tech)
43 public class JpaToscaEntrySchemaTest {
46 public void testEntrySchemaPojo() {
47 assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
48 assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
51 new JpaToscaEntrySchema((PfConceptKey) null);
52 fail("test should throw an exception");
53 } catch (Exception exc) {
54 assertEquals("type is marked @NonNull but is null", exc.getMessage());
58 new JpaToscaEntrySchema((JpaToscaEntrySchema) null);
59 fail("test should throw an exception");
60 } catch (Exception exc) {
61 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
64 PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
65 JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
67 tes.setDescription("A Description");
68 assertEquals("A Description", tes.getDescription());
70 List<JpaToscaConstraint> constraints = new ArrayList<>();
71 JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
73 tes.setConstraints(constraints);
74 assertEquals(constraints, tes.getConstraints());
76 JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes);
77 assertEquals(tes, tdtClone0);
78 assertEquals(0, tes.compareTo(tdtClone0));
80 JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes);
81 assertEquals(tes, tdtClone1);
82 assertEquals(0, tes.compareTo(tdtClone1));
84 assertEquals(-1, tes.compareTo(null));
85 assertEquals(0, tes.compareTo(tes));
87 JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey);
89 assertFalse(tes.compareTo(otherEs) == 0);
90 otherEs.setType(typeKey);
91 assertFalse(tes.compareTo(otherEs) == 0);
92 otherEs.setDescription("A Description");
93 assertFalse(tes.compareTo(otherEs) == 0);
94 otherEs.setConstraints(constraints);
95 assertEquals(0, tes.compareTo(otherEs));
99 fail("test should throw an exception");
100 } catch (Exception exc) {
101 assertEquals("target is marked @NonNull but is null", exc.getMessage());
104 assertEquals(1, tes.getKeys().size());
105 assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
107 new JpaToscaEntrySchema(typeKey).clean();
109 assertEquals(tdtClone0, tes);
111 assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid());
112 assertTrue(tes.validate(new PfValidationResult()).isValid());
114 tes.setType(PfConceptKey.getNullKey());
115 assertFalse(tes.validate(new PfValidationResult()).isValid());
117 assertFalse(tes.validate(new PfValidationResult()).isValid());
118 tes.setType(typeKey);
119 assertTrue(tes.validate(new PfValidationResult()).isValid());
121 tes.setDescription("");;
122 assertFalse(tes.validate(new PfValidationResult()).isValid());
123 tes.setDescription("A Description");
124 assertTrue(tes.validate(new PfValidationResult()).isValid());
126 tes.getConstraints().add(null);
127 assertFalse(tes.validate(new PfValidationResult()).isValid());
128 tes.getConstraints().remove(null);
129 assertTrue(tes.validate(new PfValidationResult()).isValid());
133 fail("test should throw an exception");
134 } catch (Exception exc) {
135 assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());