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
38 import static org.mockito.Mockito.*
40 @RunWith(MockitoJUnitRunner.class)
42 class PrepareUpdateAAIVfModuleTest {
45 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
48 void init() throws IOException {
49 MockitoAnnotations.initMocks(this);
53 void testGetGenericVnf() {
54 ExecutionEntity mockExecution = setupMock()
55 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
56 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
57 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
58 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
59 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
61 StubResponseAAI.MockAAIVfModule()
63 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
64 obj.getGenericVnf(mockExecution)
66 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 200)
70 void testGetGenericVnfEndpointNull() {
71 ExecutionEntity mockExecution = setupMock()
72 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
73 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
75 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
76 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
77 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
79 StubResponseAAI.MockAAIVfModule()
81 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
82 obj.getGenericVnf(mockExecution)
83 } catch (Exception ex) {
84 println " Test End - Handle catch-throw BpmnError()! "
87 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 500)
88 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponse", "AAI GET Failed:org.apache.http.client.ClientProtocolException")
92 void testUpdateVfModule() {
93 ExecutionEntity mockExecution = setupMock()
94 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
95 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
96 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
98 def node = new Node(null, 'vfModule')
99 new Node(node, 'vf-module-name', "abc")
100 VfModule vfModule = new VfModule(node, true)
102 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
103 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
105 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
106 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
107 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
109 StubResponseAAI.MockAAIVfModule()
110 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
111 obj.updateVfModule(mockExecution)
113 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 200)
114 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "")
118 void testUpdateVfModuleEndpointNull() {
119 ExecutionEntity mockExecution = setupMock()
120 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
121 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
122 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
124 def node = new Node(null, 'vfModule')
125 new Node(node, 'vf-module-name', "abc")
126 VfModule vfModule = new VfModule(node, true)
128 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
129 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
131 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
132 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
133 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
135 StubResponseAAI.MockAAIVfModule()
137 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
138 obj.updateVfModule(mockExecution)
139 } catch (Exception ex) {
140 println " Test End - Handle catch-throw BpmnError()! "
143 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 500)
144 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "AAI PATCH Failed:org.apache.http.client.ClientProtocolException")
147 private static ExecutionEntity setupMock() {
148 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
149 when(mockProcessDefinition.getKey()).thenReturn("PrepareUpdateAAIVfModule")
150 RepositoryService mockRepositoryService = mock(RepositoryService.class)
151 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
152 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PrepareUpdateAAIVfModule")
153 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
154 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
155 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
157 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
158 // Initialize prerequisite variables
159 when(mockExecution.getId()).thenReturn("100")
160 when(mockExecution.getProcessDefinitionId()).thenReturn("PrepareUpdateAAIVfModule")
161 when(mockExecution.getProcessInstanceId()).thenReturn("PrepareUpdateAAIVfModule")
162 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
163 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)