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;
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;
35 * Import the {@link ToscaUtils} class.
37 * @author Liam Fallon (liam.fallon@est.tech)
39 public class ToscaUtilsTest {
42 public void testAssertDataTypes() {
43 JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
45 assertThatThrownBy(() -> {
46 ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
47 }).hasMessage("no data types specified on service template");
49 jpaToscaServiceTemplate.setDataTypes(new JpaToscaDataTypes());
51 assertThatThrownBy(() -> {
52 ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
53 }).hasMessage("list of data types specified on service template is empty");
55 jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null);
57 assertThatCode(() -> {
58 ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
59 }).doesNotThrowAnyException();
63 public void testAssertPolicyTypes() {
64 JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
66 assertThatThrownBy(() -> {
67 ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
68 }).hasMessage("no policy types specified on service template");
70 jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
72 assertThatThrownBy(() -> {
73 ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
74 }).hasMessage("list of policy types specified on service template is empty");
76 jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null);
78 assertThatCode(() -> {
79 ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
80 }).doesNotThrowAnyException();
84 public void testAssertPolicies() {
85 JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
87 assertThatThrownBy(() -> {
88 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
89 }).hasMessage("topology template not specified on service template");
91 jpaToscaServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
93 assertThatThrownBy(() -> {
94 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
95 }).hasMessage("no policies specified on topology template of service template");
97 jpaToscaServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
99 assertThatThrownBy(() -> {
100 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
101 }).hasMessage("list of policies specified on topology template of service template is empty");
103 jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null);
105 assertThatCode(() -> {
106 ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
107 }).doesNotThrowAnyException();