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
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.utils;
23 import static org.assertj.core.api.Assertions.assertThatCode;
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.assertTrue;
29 import org.junit.Test;
30 import org.onap.policy.models.base.PfConceptKey;
31 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
32 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
33 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
34 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
35 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
38 * Import the {@link ToscaUtils} class.
40 * @author Liam Fallon (liam.fallon@est.tech)
42 public class ToscaUtilsTest {
45 public void testAssertDataTypes() {
46 JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
48 assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
49 assertEquals("no data types specified on service template",
50 ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
51 assertThatThrownBy(() -> {
52 ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
53 }).hasMessage("no data types specified on service template");
55 jpaToscaServiceTemplate.setDataTypes(new JpaToscaDataTypes());
57 assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
58 assertEquals("list of data types specified on service template is empty",
59 ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
60 assertThatThrownBy(() -> {
61 ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
62 }).hasMessage("list of data types specified on service template is empty");
64 jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null);
66 assertTrue(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
67 assertEquals(null, ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
68 assertThatCode(() -> {
69 ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
70 }).doesNotThrowAnyException();
75 public void testAssertPolicyTypes() {
76 JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
78 assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
79 assertEquals("no policy types specified on service template",
80 ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
81 assertThatThrownBy(() -> {
82 ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
83 }).hasMessage("no policy types specified on service template");
85 jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
87 assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
88 assertEquals("list of policy types specified on service template is empty",
89 ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
90 assertThatThrownBy(() -> {
91 ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
92 }).hasMessage("list of policy types specified on service template is empty");
94 jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null);
96 assertTrue(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
97 assertEquals(null, ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
98 assertThatCode(() -> {
99 ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
100 }).doesNotThrowAnyException();
104 public void testAssertPolicies() {
105 JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
107 assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
108 assertEquals("topology template not specified on service template",
109 ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
110 assertThatThrownBy(() -> {
111 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
112 }).hasMessage("topology template not specified on service template");
114 jpaToscaServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
116 assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
117 assertEquals("no policies specified on topology template of service template",
118 ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
119 assertThatThrownBy(() -> {
120 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
121 }).hasMessage("no policies specified on topology template of service template");
123 jpaToscaServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
125 assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
126 assertEquals("list of policies specified on topology template of service template is empty",
127 ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
128 assertThatThrownBy(() -> {
129 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
130 }).hasMessage("list of policies specified on topology template of service template is empty");
132 jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null);
134 assertTrue(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
135 assertEquals(null, ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
136 assertThatCode(() -> {
137 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
138 }).doesNotThrowAnyException();