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.onap.so.bpmn.common.scripts
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.*
28 import org.onap.so.rest.HttpHeader
29 import org.mockito.MockitoAnnotations
30 import org.mockito.runners.MockitoJUnitRunner
31 import org.mockito.internal.debugging.MockitoDebuggerImpl
32 import org.junit.Before
33 import org.onap.so.bpmn.common.scripts.AaiUtil;
34 import org.junit.Rule;
36 import org.junit.rules.ExpectedException
37 import org.junit.Ignore
38 import org.junit.runner.RunWith
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.camunda.bpm.engine.ProcessEngineServices
42 import org.camunda.bpm.engine.RepositoryService
43 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
44 import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
45 import org.camunda.bpm.engine.repository.ProcessDefinition
47 @RunWith(MockitoJUnitRunner.class)
49 class AaiUtilTest extends MsoGroovyTest {
53 public WireMockRule wireMockRule = new WireMockRule(8090);
56 public ExpectedException thrown = ExpectedException.none
59 def aaiPaylod = "<allotted-resource xmlns=\"http://org.openecomp.aai.inventory/v9\">\n" +
60 "\t\t\t\t<id>allottedResourceId</id>\n" +
61 "\t\t\t\t<description></description>\n" +
62 "\t\t\t\t<type>allottedResourceType</type>\n" +
63 "\t\t\t\t<role>allottedResourceRole</role>\n" +
64 "\t\t\t\t<selflink></selflink>\n" +
65 "\t\t\t\t<model-invariant-id></model-invariant-id>\n" +
66 "\t\t\t\t<model-version-id></model-version-id>\n" +
67 "\t\t\t\t<model-customization-id></model-customization-id>\n" +
68 "\t\t\t\t<orchestration-status>PendingCreate</orchestration-status>\n" +
69 "\t\t\t\t<operation-status></operation-status>\n" +
70 "\t\t\t\t<relationship-list>\n" +
71 "\t\t\t\t\t<relationship>\n" +
72 " \t\t\t<related-to>service-instance</related-to>\n" +
73 " \t\t\t<related-link>CSI_resourceLink</related-link>\n" +
74 "\t\t\t\t\t</relationship>\n" +
75 "\t\t\t\t</relationship-list>\n" +
76 "\t\t\t</allotted-resource>";
79 public void testGetVersionDefault() {
80 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
81 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
82 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
84 CreateAAIVfModule myproc = new CreateAAIVfModule()
85 AaiUtil aaiUtil = new AaiUtil(myproc)
86 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
87 assertEquals('8', version)
91 public void testGetVersionResourceSpecific() {
92 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
93 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
94 when(mockExecution.getVariable("mso.workflow.default.aai.l3-network.version")).thenReturn('7')
95 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
96 CreateAAIVfModule myproc = new CreateAAIVfModule()
97 AaiUtil aaiUtil = new AaiUtil(myproc)
98 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
99 assertEquals('7', version)
103 public void testGetVersionFlowSpecific() {
104 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
105 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
106 when(mockExecution.getVariable("mso.workflow.custom.CreateAAIVfModule.aai.version")).thenReturn('6')
107 when(mockExecution.getVariable("mso.workflow.default.aai.l3-network.version")).thenReturn('7')
109 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
111 CreateAAIVfModule myproc = new CreateAAIVfModule()
112 AaiUtil aaiUtil = new AaiUtil(myproc)
113 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
114 assertEquals('6', version)
118 public void testGetVersionNotDefined() {
119 thrown.expect(Exception.class)
120 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
121 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
122 CreateAAIVfModule myproc = new CreateAAIVfModule()
123 AaiUtil aaiUtil = new AaiUtil(myproc)
124 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn("")
126 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
131 public void testExecuteAAIGetCall() {
132 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
133 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
134 when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3")
135 when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f")
136 CreateAAIVfModule myproc = new CreateAAIVfModule()
137 AaiUtil aaiUtil = new AaiUtil(myproc)
138 def uri = aaiUtil.executeAAIGetCall(mockExecution,"http://localhost:8090/aai/v9/business/customers/customer/CUST/service-subscriptions/service-subscription/SVC/service-instances/service-instance/NST/allotted-resources/allotted-resource/allottedResourceId")
143 public void testExecuteAAIPutCall() {
144 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
145 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
146 when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3")
147 when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f")
148 CreateAAIVfModule myproc = new CreateAAIVfModule()
149 AaiUtil aaiUtil = new AaiUtil(myproc)
150 def uri = aaiUtil.executeAAIPutCall(mockExecution,"http://localhost:8090/aai/v9/business/customers/customer/CUST/service-subscriptions/service-subscription/SVC/service-instances/service-instance/NST/allotted-resources/allotted-resource/allottedResourceId",aaiPaylod)
154 public void testGetNamespaceFromUri_twoArguments() { // (execution, uri)
155 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
157 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
158 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('10')
159 when(mockExecution.getVariable("mso.workflow.default.aai.v10.l3-network.uri")).thenReturn('/aai/v10/network/l3-networks/l3-network')
160 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
162 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
163 CreateAAIVfModule myproc = new CreateAAIVfModule()
164 AaiUtil aaiUtil = new AaiUtil(myproc)
165 def ns = aaiUtil.getNamespaceFromUri(mockExecution, '/aai/v10/search/generic-query')
166 assertEquals('http://org.openecomp.aai.inventory/v10', ns)