Changes for Checkstyle 8.32
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaEntrySchemaTest.java
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.tosca.simple.concepts;
23
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;
29
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;
35
36 /**
37  * DAO test for ToscaEntrySchema.
38  *
39  * @author Liam Fallon (liam.fallon@est.tech)
40  */
41 public class JpaToscaEntrySchemaTest {
42
43     private static final String A_DESCRIPTION = "A Description";
44
45     @Test
46     public void testEntrySchemaPojo() {
47         assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
48         assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
49
50         assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null))
51                 .hasMessageMatching("type is marked .*on.*ull but is null");
52
53         assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null))
54                 .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
55
56         PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
57         JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
58
59         tes.setDescription(A_DESCRIPTION);
60         assertEquals(A_DESCRIPTION, tes.getDescription());
61
62         List<JpaToscaConstraint> constraints = new ArrayList<>();
63         JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
64         constraints.add(lsc);
65         tes.setConstraints(constraints);
66         assertEquals(constraints, tes.getConstraints());
67
68         JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes);
69         assertEquals(tes, tdtClone0);
70         assertEquals(0, tes.compareTo(tdtClone0));
71
72         JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes);
73         assertEquals(tes, tdtClone1);
74         assertEquals(0, tes.compareTo(tdtClone1));
75
76         assertEquals(-1, tes.compareTo(null));
77         assertEquals(0, tes.compareTo(tes));
78
79         JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey);
80
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));
88
89         assertThatThrownBy(() -> tes.copyTo(null)).hasMessageMatching("target is marked .*on.*ull but is null");
90
91         assertEquals(1, tes.getKeys().size());
92         assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
93
94         new JpaToscaEntrySchema(typeKey).clean();
95         tes.clean();
96         assertEquals(tdtClone0, tes);
97
98         assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid());
99         assertTrue(tes.validate(new PfValidationResult()).isValid());
100
101         tes.setType(PfConceptKey.getNullKey());
102         assertFalse(tes.validate(new PfValidationResult()).isValid());
103         tes.setType(null);
104         assertFalse(tes.validate(new PfValidationResult()).isValid());
105         tes.setType(typeKey);
106         assertTrue(tes.validate(new PfValidationResult()).isValid());
107
108         tes.setDescription("");
109
110         assertFalse(tes.validate(new PfValidationResult()).isValid());
111         tes.setDescription(A_DESCRIPTION);
112         assertTrue(tes.validate(new PfValidationResult()).isValid());
113
114         tes.getConstraints().add(null);
115         assertFalse(tes.validate(new PfValidationResult()).isValid());
116         tes.getConstraints().remove(null);
117         assertTrue(tes.validate(new PfValidationResult()).isValid());
118
119         assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
120     }
121 }