Rename packages from openecomp to onap.
[sdc.git] / openecomp-be / lib / openecomp-tosca-lib / src / test / java / org / openecomp / sdc / tosca / services / DataModelUtilTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.tosca.services;
22
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.onap.sdc.tosca.datatypes.model.GroupDefinition;
30 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
31 import org.onap.sdc.tosca.datatypes.model.NodeType;
32 import org.onap.sdc.tosca.datatypes.model.PolicyDefinition;
33 import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
34 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
35 import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
36
37 import java.util.ArrayList;
38
39 /**
40  * @author shiria
41  * @since September 15, 2016.
42  */
43 @RunWith(MockitoJUnitRunner.class)
44 public class DataModelUtilTest {
45
46   @Rule
47   public ExpectedException thrown = ExpectedException.none();
48
49   @Test
50   public void testAddSubstitutionMapping() throws Exception {
51     thrown.expect(CoreException.class);
52     thrown.expectMessage(
53         "Invalid action, can't add 'Substitution Mapping' to 'Service Template', 'Service Template' entity is NULL.");
54     DataModelUtil.addSubstitutionMapping(null, new SubstitutionMapping());
55   }
56
57   @Test
58   public void testAddSubstitutionMappingReq() throws Exception {
59     thrown.expect(CoreException.class);
60     thrown.expectMessage(
61         "Invalid action, can't add 'Substitution Mapping Requirements' to 'Service Template', 'Service Template' entity is NULL.");
62     DataModelUtil.addSubstitutionMappingReq(null, "123", new ArrayList<>());
63   }
64
65   @Test
66   public void testAddNodeTemplate() throws Exception {
67     thrown.expect(CoreException.class);
68     thrown.expectMessage(
69         "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL.");
70     DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate());
71   }
72
73   @Test
74   public void testAddPolicyDefinition() throws Exception {
75     thrown.expect(CoreException.class);
76     thrown.expectMessage(
77         "Invalid action, can't add 'Policy Definition' to 'Service Template', 'Service Template' entity is NULL.");
78     DataModelUtil.addPolicyDefinition(null, "123", new PolicyDefinition());
79   }
80
81   @Test
82   public void testAddNodeType() throws Exception {
83     thrown.expect(CoreException.class);
84     thrown.expectMessage(
85         "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL.");
86     DataModelUtil.addNodeType(null, "123", new NodeType());
87   }
88
89   @Test
90   public void testAddRelationshipTemplate() throws Exception {
91     thrown.expect(CoreException.class);
92     thrown.expectMessage(
93         "Invalid action, can't add 'Relationship Template' to 'Service Template', 'Service Template' entity is NULL.");
94     DataModelUtil.addRelationshipTemplate(null, "123", new RelationshipTemplate());
95   }
96
97   @Test
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());
103   }
104
105   @Test
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());
111   }
112
113   @Test
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());
119   }
120
121   @Test
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());
127   }
128 }