Support persistence of data types
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / utils / ToscaUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.tosca.utils;
22
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25
26 import org.junit.Test;
27 import org.onap.policy.models.base.PfConceptKey;
28 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
29 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
30 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
31 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
32 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
33
34 /**
35  * Import the {@link ToscaUtils} class.
36  *
37  * @author Liam Fallon (liam.fallon@est.tech)
38  */
39 public class ToscaUtilsTest {
40
41     @Test
42     public void testAssertDataTypes() {
43         JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
44
45         assertThatThrownBy(() -> {
46             ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
47         }).hasMessage("no data types specified on service template");
48
49         jpaToscaServiceTemplate.setDataTypes(new JpaToscaDataTypes());
50
51         assertThatThrownBy(() -> {
52             ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
53         }).hasMessage("list of data types specified on service template is empty");
54
55         jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null);
56
57         assertThatCode(() -> {
58             ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
59         }).doesNotThrowAnyException();
60     }
61
62     @Test
63     public void testAssertPolicyTypes() {
64         JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
65
66         assertThatThrownBy(() -> {
67             ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
68         }).hasMessage("no policy types specified on service template");
69
70         jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
71
72         assertThatThrownBy(() -> {
73             ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
74         }).hasMessage("list of policy types specified on service template is empty");
75
76         jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null);
77
78         assertThatCode(() -> {
79             ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
80         }).doesNotThrowAnyException();
81     }
82
83     @Test
84     public void testAssertPolicies() {
85         JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
86
87         assertThatThrownBy(() -> {
88             ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
89         }).hasMessage("topology template not specified on service template");
90
91         jpaToscaServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
92
93         assertThatThrownBy(() -> {
94             ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
95         }).hasMessage("no policies specified on topology template of service template");
96
97         jpaToscaServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
98
99         assertThatThrownBy(() -> {
100             ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
101         }).hasMessage("list of policies specified on topology template of service template is empty");
102
103         jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null);
104
105         assertThatCode(() -> {
106             ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
107         }).doesNotThrowAnyException();
108     }
109 }