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
24 import org.camunda.bpm.engine.ProcessEngineServices
25 import org.camunda.bpm.engine.RepositoryService
26 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
27 import org.camunda.bpm.engine.repository.ProcessDefinition
28 import org.junit.Before
29 import org.junit.Ignore
32 import org.junit.runner.RunWith
33 import org.mockito.ArgumentCaptor
34 import org.mockito.Captor
35 import org.mockito.MockitoAnnotations
36 import org.mockito.runners.MockitoJUnitRunner
37 import org.onap.so.bpmn.mock.StubResponseAAI
39 import static org.mockito.Mockito.*
41 @RunWith(MockitoJUnitRunner.class)
43 class PrepareUpdateAAIVfModuleTest {
45 public WireMockRule wireMockRule = new WireMockRule(28090)
48 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
51 void init() throws IOException {
52 MockitoAnnotations.initMocks(this);
56 void testGetGenericVnf() {
57 ExecutionEntity mockExecution = setupMock()
58 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
59 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
60 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
61 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
62 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
63 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
65 StubResponseAAI.MockAAIVfModule()
67 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
68 obj.getGenericVnf(mockExecution)
70 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 200)
74 void testGetGenericVnfEndpointNull() {
75 ExecutionEntity mockExecution = setupMock()
76 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
77 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
78 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
79 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
80 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
81 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
83 StubResponseAAI.MockAAIVfModule()
85 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
86 obj.getGenericVnf(mockExecution)
87 } catch (Exception ex) {
88 println " Test End - Handle catch-throw BpmnError()! "
91 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 500)
92 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponse", "AAI GET Failed:org.apache.http.client.ClientProtocolException")
96 void testUpdateVfModule() {
97 ExecutionEntity mockExecution = setupMock()
98 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
99 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
100 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
102 def node = new Node(null, 'vfModule')
103 new Node(node, 'vf-module-name', "abc")
104 VfModule vfModule = new VfModule(node, true)
106 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
107 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
108 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
109 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
110 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
111 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
113 StubResponseAAI.MockAAIVfModule()
114 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
115 obj.updateVfModule(mockExecution)
117 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 200)
118 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "")
122 void testUpdateVfModuleEndpointNull() {
123 ExecutionEntity mockExecution = setupMock()
124 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
125 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
126 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
128 def node = new Node(null, 'vfModule')
129 new Node(node, 'vf-module-name', "abc")
130 VfModule vfModule = new VfModule(node, true)
132 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
133 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
134 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
135 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
136 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
137 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
139 StubResponseAAI.MockAAIVfModule()
141 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
142 obj.updateVfModule(mockExecution)
143 } catch (Exception ex) {
144 println " Test End - Handle catch-throw BpmnError()! "
147 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 500)
148 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "AAI PATCH Failed:org.apache.http.client.ClientProtocolException")
151 private static ExecutionEntity setupMock() {
152 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
153 when(mockProcessDefinition.getKey()).thenReturn("PrepareUpdateAAIVfModule")
154 RepositoryService mockRepositoryService = mock(RepositoryService.class)
155 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
156 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PrepareUpdateAAIVfModule")
157 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
158 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
159 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
161 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
162 // Initialize prerequisite variables
163 when(mockExecution.getId()).thenReturn("100")
164 when(mockExecution.getProcessDefinitionId()).thenReturn("PrepareUpdateAAIVfModule")
165 when(mockExecution.getProcessInstanceId()).thenReturn("PrepareUpdateAAIVfModule")
166 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
167 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)