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.mso.bpmn.common.scripts;
23 import static org.junit.Assert.*;
24 import static org.mockito.Mockito.*
26 import org.openecomp.mso.rest.HttpHeader
27 import org.mockito.MockitoAnnotations
28 import org.mockito.runners.MockitoJUnitRunner
29 import org.mockito.internal.debugging.MockitoDebuggerImpl
30 import org.junit.Before
31 import org.openecomp.mso.bpmn.common.scripts.AaiUtil;
32 import org.junit.Rule;
34 import org.junit.Ignore
35 import org.junit.runner.RunWith
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.camunda.bpm.engine.ProcessEngineServices
39 import org.camunda.bpm.engine.RepositoryService
40 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
41 import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
42 import org.camunda.bpm.engine.repository.ProcessDefinition
44 @RunWith(MockitoJUnitRunner.class)
45 class AaiUtilTest extends MsoGroovyTest {
48 public void testGetVersionDefault() {
49 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
50 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
51 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
52 CreateAAIVfModule myproc = new CreateAAIVfModule()
53 AaiUtil aaiUtil = new AaiUtil(myproc)
54 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
55 assertEquals('8', version)
59 public void testGetVersionResourceSpecific() {
60 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
61 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
62 when(mockExecution.getVariable("URN_mso_workflow_default_aai_l3_network_version")).thenReturn('7')
63 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
64 CreateAAIVfModule myproc = new CreateAAIVfModule()
65 AaiUtil aaiUtil = new AaiUtil(myproc)
66 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
67 assertEquals('7', version)
71 public void testGetVersionFlowSpecific() {
72 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
73 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
74 when(mockExecution.getVariable("URN_mso_workflow_custom_CreateAAIVfModule_aai_version")).thenReturn('6')
75 when(mockExecution.getVariable("URN_mso_workflow_default_aai_l3_network_version")).thenReturn('7')
76 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
77 CreateAAIVfModule myproc = new CreateAAIVfModule()
78 AaiUtil aaiUtil = new AaiUtil(myproc)
79 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
80 assertEquals('6', version)
83 @Test(expected=java.lang.Exception.class)
84 public void testGetVersionNotDefined() {
85 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
86 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
87 CreateAAIVfModule myproc = new CreateAAIVfModule()
88 AaiUtil aaiUtil = new AaiUtil(myproc)
89 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
93 public void testGetUriDefaultVersion() {
94 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
95 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
96 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_l3_network_uri")).thenReturn('/aai/v8/network/l3-networks/l3-network')
97 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
99 CreateAAIVfModule myproc = new CreateAAIVfModule()
100 AaiUtil aaiUtil = new AaiUtil(myproc)
101 def uri = aaiUtil.getUri(mockExecution, 'l3-network')
102 assertEquals('/aai/v8/network/l3-networks/l3-network', uri)
106 public void testGetUriFlowAndResourceSpecific() {
107 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
108 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
109 when(mockExecution.getVariable("URN_mso_workflow_CreateAAIVfModule_aai_l3_network_uri")).thenReturn('/aai/v6/network/l3-networks/l3-network')
110 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_l3_network_uri")).thenReturn('/aai/v8/network/l3-networks/l3-network')
111 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
113 CreateAAIVfModule myproc = new CreateAAIVfModule()
114 AaiUtil aaiUtil = new AaiUtil(myproc)
115 def uri = aaiUtil.getUri(mockExecution, 'l3-network')
116 assertEquals('/aai/v6/network/l3-networks/l3-network', uri)
120 public void testGetNetworkGenericVnfEndpoint() {
121 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
122 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
123 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
124 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_generic_vnf_uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf')
125 when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090')
127 CreateAAIVfModule myproc = new CreateAAIVfModule()
128 AaiUtil aaiUtil = new AaiUtil(myproc)
129 def endpoint = aaiUtil.getNetworkGenericVnfEndpoint(mockExecution)
130 assertEquals('http://localhost:28090/aai/v8/network/generic-vnfs/generic-vnf', endpoint)
134 public void testGetNetworkGenericVnfUri() {
135 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
136 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
137 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
138 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_generic_vnf_uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf')
140 CreateAAIVfModule myproc = new CreateAAIVfModule()
141 AaiUtil aaiUtil = new AaiUtil(myproc)
142 def uri = aaiUtil.getNetworkGenericVnfUri(mockExecution)
143 assertEquals('/aai/v8/network/generic-vnfs/generic-vnf', uri)
147 public void testGetNetworkVpnBindingUri() {
148 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
149 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
150 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
151 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_vpn_binding_uri")).thenReturn('/aai/v8/network/vpn-bindings/vpn-binding')
153 CreateAAIVfModule myproc = new CreateAAIVfModule()
154 AaiUtil aaiUtil = new AaiUtil(myproc)
155 def uri = aaiUtil.getNetworkVpnBindingUri(mockExecution)
156 assertEquals('/aai/v8/network/vpn-bindings/vpn-binding', uri)
160 public void testGetNetworkPolicyUri() {
161 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
162 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
163 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
164 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_network_policy_uri")).thenReturn('/aai/v8/network/network-policies/network-policy')
166 CreateAAIVfModule myproc = new CreateAAIVfModule()
167 AaiUtil aaiUtil = new AaiUtil(myproc)
168 def uri = aaiUtil.getNetworkPolicyUri(mockExecution)
169 assertEquals('/aai/v8/network/network-policies/network-policy', uri)
173 public void testGetNetworkTableReferencesUri() {
174 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
175 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
176 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
177 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_route_table_reference_uri")).thenReturn('/aai/v8/network/route-table-references/route-table-reference')
179 CreateAAIVfModule myproc = new CreateAAIVfModule()
180 AaiUtil aaiUtil = new AaiUtil(myproc)
181 def uri = aaiUtil.getNetworkTableReferencesUri(mockExecution)
182 assertEquals('/aai/v8/network/route-table-references/route-table-reference', uri)
186 public void testGetNetworkVceUri() {
187 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
188 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
189 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
190 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_vce_uri")).thenReturn('/aai/v8/network/vces/vce')
192 CreateAAIVfModule myproc = new CreateAAIVfModule()
193 AaiUtil aaiUtil = new AaiUtil(myproc)
194 def uri = aaiUtil.getNetworkVceUri(mockExecution)
195 assertEquals('/aai/v8/network/vces/vce', uri)
199 public void testGetNetworkL3NetworkUri() {
200 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
201 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
202 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
203 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_l3_network_uri")).thenReturn('/aai/v8/network/l3-networks/l3-network')
204 CreateAAIVfModule myproc = new CreateAAIVfModule()
205 AaiUtil aaiUtil = new AaiUtil(myproc)
206 def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution)
207 assertEquals('/aai/v8/network/l3-networks/l3-network', uri)
211 public void testGetBusinessCustomerUri() {
212 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
213 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
214 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
215 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_customer_uri")).thenReturn('/aai/v8/business/customers/customer')
216 CreateAAIVfModule myproc = new CreateAAIVfModule()
217 AaiUtil aaiUtil = new AaiUtil(myproc)
218 def uri = aaiUtil.getBusinessCustomerUri(mockExecution)
219 assertEquals('/aai/v8/business/customers/customer', uri)
223 public void testGetCloudInfrastructureCloudRegionEndpoint() {
224 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
225 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
226 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
227 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_cloud_region_uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic')
228 when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090')
229 CreateAAIVfModule myproc = new CreateAAIVfModule()
230 AaiUtil aaiUtil = new AaiUtil(myproc)
231 def uri = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(mockExecution)
232 assertEquals('http://localhost:28090/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic', uri)
236 public void testGetCloudInfrastructureCloudRegionUri() {
237 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
238 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
239 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
240 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_cloud_region_uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic')
241 CreateAAIVfModule myproc = new CreateAAIVfModule()
242 AaiUtil aaiUtil = new AaiUtil(myproc)
243 def uri = aaiUtil.getCloudInfrastructureCloudRegionUri(mockExecution)
244 assertEquals('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic', uri)
248 public void testGetCloudInfrastructureVolumeGroupUri() {
249 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
250 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
251 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
252 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_volume_group_uri")).thenReturn('/aai/v8/cloud-infrastructure/volume-groups/volume-group')
253 CreateAAIVfModule myproc = new CreateAAIVfModule()
254 AaiUtil aaiUtil = new AaiUtil(myproc)
255 def uri = aaiUtil.getCloudInfrastructureVolumeGroupUri(mockExecution)
256 assertEquals('/aai/v8/cloud-infrastructure/volume-groups/volume-group', uri)
260 public void testGetCloudInfrastructureTenantUri() {
261 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
262 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
263 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
264 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_tenant_uri")).thenReturn('/aai/v8/cloud-infrastructure/tenants/tenant')
265 CreateAAIVfModule myproc = new CreateAAIVfModule()
266 AaiUtil aaiUtil = new AaiUtil(myproc)
267 def uri = aaiUtil.getCloudInfrastructureTenantUri(mockExecution)
268 assertEquals('/aai/v8/cloud-infrastructure/tenants/tenant', uri)
272 public void testGetSearchNodesQueryUri() {
273 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
274 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
275 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
276 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_nodes_query_uri")).thenReturn('/aai/v8/search/nodes-query')
277 CreateAAIVfModule myproc = new CreateAAIVfModule()
278 AaiUtil aaiUtil = new AaiUtil(myproc)
279 def uri = aaiUtil.getSearchNodesQueryUri(mockExecution)
280 assertEquals('/aai/v8/search/nodes-query', uri)
284 public void testGetSearchNodesQueryEndpoint() {
285 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
286 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
287 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
288 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_nodes_query_uri")).thenReturn('/aai/v8/search/nodes-query')
289 when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090')
290 CreateAAIVfModule myproc = new CreateAAIVfModule()
291 AaiUtil aaiUtil = new AaiUtil(myproc)
292 def uri = aaiUtil.getSearchNodesQueryEndpoint(mockExecution)
293 assertEquals('http://localhost:28090/aai/v8/search/nodes-query', uri)
297 public void testGetSearchGenericQueryUri() {
298 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
299 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
300 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8')
301 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_generic_query_uri")).thenReturn('/aai/v8/search/generic-query')
302 CreateAAIVfModule myproc = new CreateAAIVfModule()
303 AaiUtil aaiUtil = new AaiUtil(myproc)
304 def uri = aaiUtil.getSearchGenericQueryUri(mockExecution)
305 assertEquals('/aai/v8/search/generic-query', uri)
309 public void testGetNamespaceFromUri() {
310 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
311 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
312 CreateAAIVfModule myproc = new CreateAAIVfModule()
313 AaiUtil aaiUtil = new AaiUtil(myproc)
314 def ns = aaiUtil.getNamespaceFromUri('/aai/v6/search/generic-query')
315 assertEquals('http://org.openecomp.aai.inventory/v6', ns)