2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.tosca.services;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
26 import org.junit.runner.RunWith;
27 import org.mockito.runners.MockitoJUnitRunner;
28 import org.openecomp.sdc.common.errors.CoreException;
29 import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
30 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
31 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
32 import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition;
33 import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate;
34 import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
35 import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping;
37 import java.util.ArrayList;
41 * @since September 15, 2016.
43 @RunWith(MockitoJUnitRunner.class)
44 public class DataModelUtilTest {
47 public ExpectedException thrown = ExpectedException.none();
50 public void testAddSubstitutionMapping() throws Exception {
51 thrown.expect(CoreException.class);
53 "Invalid action, can't add 'Substitution Mapping' to 'Service Template', 'Service Template' entity is NULL.");
54 DataModelUtil.addSubstitutionMapping(null, new SubstitutionMapping());
58 public void testAddSubstitutionMappingReq() throws Exception {
59 thrown.expect(CoreException.class);
61 "Invalid action, can't add 'Substitution Mapping Requirements' to 'Service Template', 'Service Template' entity is NULL.");
62 DataModelUtil.addSubstitutionMappingReq(null, "123", new ArrayList<>());
66 public void testAddNodeTemplate() throws Exception {
67 thrown.expect(CoreException.class);
69 "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL.");
70 DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate());
74 public void testAddPolicyDefinition() throws Exception {
75 thrown.expect(CoreException.class);
77 "Invalid action, can't add 'Policy Definition' to 'Service Template', 'Service Template' entity is NULL.");
78 DataModelUtil.addPolicyDefinition(null, "123", new PolicyDefinition());
82 public void testAddNodeType() throws Exception {
83 thrown.expect(CoreException.class);
85 "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL.");
86 DataModelUtil.addNodeType(null, "123", new NodeType());
90 public void testAddRelationshipTemplate() throws Exception {
91 thrown.expect(CoreException.class);
93 "Invalid action, can't add 'Relationship Template' to 'Service Template', 'Service Template' entity is NULL.");
94 DataModelUtil.addRelationshipTemplate(null, "123", new RelationshipTemplate());
98 public void testAddRequirementAssignment() throws Exception {
99 thrown.expect(CoreException.class);
100 thrown.expectMessage(
101 "Invalid action, can't add 'Requirement Assignment' to 'Node Template', 'Node Template' entity is NULL.");
102 DataModelUtil.addRequirementAssignment(null, "123", new RequirementAssignment());
106 public void testGetNodeTemplate() throws Exception {
107 thrown.expect(CoreException.class);
108 thrown.expectMessage(
109 "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL.");
110 DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate());
114 public void testGetNodeType() throws Exception {
115 thrown.expect(CoreException.class);
116 thrown.expectMessage(
117 "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL.");
118 DataModelUtil.addNodeType(null, "123", new NodeType());
122 public void testAddGroupToTopologyTemplate() throws Exception {
123 thrown.expect(CoreException.class);
124 thrown.expectMessage(
125 "Invalid action, can't add 'Group Definition' to 'Service Template', 'Service Template' entity is NULL.");
126 DataModelUtil.addGroupDefinitionToTopologyTemplate(null, "123", new GroupDefinition());