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 {
44 public WireMockRule wireMockRule = new WireMockRule(28090)
47 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
50 void init() throws IOException {
51 MockitoAnnotations.initMocks(this);
55 void testGetGenericVnf() {
56 ExecutionEntity mockExecution = setupMock()
57 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
58 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
59 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
60 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
61 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
63 StubResponseAAI.MockAAIVfModule()
65 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
66 obj.getGenericVnf(mockExecution)
68 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 200)
72 void testGetGenericVnfEndpointNull() {
73 ExecutionEntity mockExecution = setupMock()
74 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
75 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
77 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
78 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
79 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
81 StubResponseAAI.MockAAIVfModule()
83 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
84 obj.getGenericVnf(mockExecution)
85 } catch (Exception ex) {
86 println " Test End - Handle catch-throw BpmnError()! "
89 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 500)
90 verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponse", "AAI GET Failed:org.apache.http.client.ClientProtocolException")
94 void testUpdateVfModule() {
95 ExecutionEntity mockExecution = setupMock()
96 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
97 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
98 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
100 def node = new Node(null, 'vfModule')
101 new Node(node, 'vf-module-name', "abc")
102 VfModule vfModule = new VfModule(node, true)
104 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
105 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
107 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
108 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
109 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
111 StubResponseAAI.MockAAIVfModule()
112 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
113 obj.updateVfModule(mockExecution)
115 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 200)
116 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "")
120 void testUpdateVfModuleEndpointNull() {
121 ExecutionEntity mockExecution = setupMock()
122 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
123 when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask")
124 when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool")
126 def node = new Node(null, 'vfModule')
127 new Node(node, 'vf-module-name', "abc")
128 VfModule vfModule = new VfModule(node, true)
130 when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule)
131 when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created")
133 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
134 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
135 when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8')
137 StubResponseAAI.MockAAIVfModule()
139 PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule()
140 obj.updateVfModule(mockExecution)
141 } catch (Exception ex) {
142 println " Test End - Handle catch-throw BpmnError()! "
145 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 500)
146 verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "AAI PATCH Failed:org.apache.http.client.ClientProtocolException")
149 private static ExecutionEntity setupMock() {
150 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
151 when(mockProcessDefinition.getKey()).thenReturn("PrepareUpdateAAIVfModule")
152 RepositoryService mockRepositoryService = mock(RepositoryService.class)
153 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
154 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PrepareUpdateAAIVfModule")
155 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
156 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
157 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
159 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
160 // Initialize prerequisite variables
161 when(mockExecution.getId()).thenReturn("100")
162 when(mockExecution.getProcessDefinitionId()).thenReturn("PrepareUpdateAAIVfModule")
163 when(mockExecution.getProcessInstanceId()).thenReturn("PrepareUpdateAAIVfModule")
164 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
165 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)