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("aai.endpoint")).thenReturn("http://localhost:28090")
61 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
62 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
64 StubResponseAAI.MockAAIVfModule()
66 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
67 obj.getGenericVnf(mockExecution)
69 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 200)
73 void testGetGenericVnfEndpointNull() {
74 ExecutionEntity mockExecution = setupMock()
75 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
76 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
78 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
79 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
80 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
82 StubResponseAAI.MockAAIVfModule()
84 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
85 obj.getGenericVnf(mockExecution)
86 } catch (Exception ex) {
87 println " Test End - Handle catch-throw BpmnError()! "
90 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 500)
91 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponse", "AAI GET Failed:org.apache.http.client.ClientProtocolException")
95 void testUpdateVfModule() {
96 ExecutionEntity mockExecution = setupMock()
97 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
98 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
99 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
101 def node = new Node(null, 'vfModule')
102 new Node(node, 'vf-module-name', "abc")
103 VfModule vfModule = new VfModule(node, true)
105 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
106 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
108 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
109 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
110 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
112 StubResponseAAI.MockAAIVfModule()
113 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
114 obj.updateVfModule(mockExecution)
116 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 200)
117 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "")
121 void testUpdateVfModuleEndpointNull() {
122 ExecutionEntity mockExecution = setupMock()
123 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
124 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
125 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
127 def node = new Node(null, 'vfModule')
128 new Node(node, 'vf-module-name', "abc")
129 VfModule vfModule = new VfModule(node, true)
131 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
132 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
134 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
135 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
136 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
138 StubResponseAAI.MockAAIVfModule()
140 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
141 obj.updateVfModule(mockExecution)
142 } catch (Exception ex) {
143 println " Test End - Handle catch-throw BpmnError()! "
146 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 500)
147 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "AAI PATCH Failed:org.apache.http.client.ClientProtocolException")
150 private static ExecutionEntity setupMock() {
151 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
152 when(mockProcessDefinition.getKey()).thenReturn("PrepareUpdateAAIVfModule")
153 RepositoryService mockRepositoryService = mock(RepositoryService.class)
154 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
155 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PrepareUpdateAAIVfModule")
156 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
157 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
158 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
160 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
161 // Initialize prerequisite variables
162 when(mockExecution.getId()).thenReturn("100")
163 when(mockExecution.getProcessDefinitionId()).thenReturn("PrepareUpdateAAIVfModule")
164 when(mockExecution.getProcessInstanceId()).thenReturn("PrepareUpdateAAIVfModule")
165 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
166 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)