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.Assert;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.junit.runner.RunWith;
28 import org.mockito.runners.MockitoJUnitRunner;
29 import org.onap.sdc.tosca.datatypes.model.*;
30 import org.openecomp.sdc.common.errors.CoreException;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.Optional;
38 * @since September 15, 2016.
40 @RunWith(MockitoJUnitRunner.class)
41 public class DataModelUtilTest {
44 public ExpectedException thrown = ExpectedException.none();
47 public void testAddSubstitutionMapping() throws Exception {
48 thrown.expect(CoreException.class);
50 "Invalid action, can't add 'Substitution Mapping' to 'Service Template', 'Service Template' entity is NULL.");
51 DataModelUtil.addSubstitutionMapping(null, new SubstitutionMapping());
55 public void testAddSubstitutionMappingReq() throws Exception {
56 thrown.expect(CoreException.class);
58 "Invalid action, can't add 'Substitution Mapping Requirements' to 'Service Template', 'Service Template' entity is NULL.");
59 DataModelUtil.addSubstitutionMappingReq(null, "123", new ArrayList<>());
63 public void testAddNodeTemplate() throws Exception {
64 thrown.expect(CoreException.class);
66 "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL.");
67 DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate());
71 public void testAddPolicyDefinition() throws Exception {
72 thrown.expect(CoreException.class);
74 "Invalid action, can't add 'Policy Definition' to 'Service Template', 'Service Template' entity is NULL.");
75 DataModelUtil.addPolicyDefinition(null, "123", new PolicyDefinition());
79 public void testAddNodeType() throws Exception {
80 thrown.expect(CoreException.class);
82 "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL.");
83 DataModelUtil.addNodeType(null, "123", new NodeType());
87 public void testAddRelationshipTemplate() throws Exception {
88 thrown.expect(CoreException.class);
90 "Invalid action, can't add 'Relationship Template' to 'Service Template', 'Service Template' entity is NULL.");
91 DataModelUtil.addRelationshipTemplate(null, "123", new RelationshipTemplate());
95 public void testAddRequirementAssignment() throws Exception {
96 thrown.expect(CoreException.class);
98 "Invalid action, can't add 'Requirement Assignment' to 'Node Template', 'Node Template' entity is NULL.");
99 DataModelUtil.addRequirementAssignment(null, "123", new RequirementAssignment());
103 public void testGetNodeTemplate() throws Exception {
104 thrown.expect(CoreException.class);
105 thrown.expectMessage(
106 "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL.");
107 DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate());
111 public void testGetNodeType() throws Exception {
112 thrown.expect(CoreException.class);
113 thrown.expectMessage(
114 "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL.");
115 DataModelUtil.addNodeType(null, "123", new NodeType());
119 public void testAddGroupToTopologyTemplate() throws Exception {
120 thrown.expect(CoreException.class);
121 thrown.expectMessage(
122 "Invalid action, can't add 'Group Definition' to 'Service Template', 'Service Template' entity is NULL.");
123 DataModelUtil.addGroupDefinitionToTopologyTemplate(null, "123", new GroupDefinition());
128 public void testGetRelationshipTemplate(){
129 RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
130 String testingRelationshipType = "testingRelationshipType";
131 relationshipTemplate.setType(testingRelationshipType);
132 TopologyTemplate topologyTemplate = new TopologyTemplate();
133 topologyTemplate.setRelationship_templates(new HashMap<>());
134 String relationId = "rtest";
135 topologyTemplate.getRelationship_templates().put(relationId, relationshipTemplate);
136 ServiceTemplate serviceTemplate = new ServiceTemplate();
137 serviceTemplate.setTopology_template(topologyTemplate);
139 Optional<RelationshipTemplate> relationshipTemplateOut =
140 DataModelUtil.getRelationshipTemplate(serviceTemplate, relationId);
141 Assert.assertNotNull(relationshipTemplateOut);
142 Assert.assertEquals(true,relationshipTemplateOut.isPresent());
143 Assert.assertEquals(testingRelationshipType, relationshipTemplateOut.get().getType());
147 public void testGetEmptyRelationshipTemplate(){
148 ServiceTemplate serviceTemplate = new ServiceTemplate();
149 String relationId = "rtest";
150 Optional<RelationshipTemplate> relationshipTemplateOut =
151 DataModelUtil.getRelationshipTemplate(serviceTemplate, relationId);
152 Assert.assertNotNull(relationshipTemplateOut);
153 Assert.assertEquals(false,relationshipTemplateOut.isPresent());