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.infrastructure.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.Assert
29 import org.junit.Before
30 import org.junit.Ignore
33 import org.junit.runner.RunWith
34 import org.mockito.ArgumentCaptor
35 import org.mockito.Captor
36 import org.mockito.Mockito
37 import org.mockito.MockitoAnnotations
38 import org.mockito.runners.MockitoJUnitRunner
39 import org.onap.so.bpmn.core.WorkflowException
41 import static com.github.tomakehurst.wiremock.client.WireMock.*
42 import static org.mockito.Mockito.*
44 @RunWith(MockitoJUnitRunner.class)
45 class DoUpdateVnfAndModulesTest {
48 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
51 public WireMockRule wireMockRule = new WireMockRule(28090);
55 MockitoAnnotations.initMocks(this)
59 void testQueryAAIVfModule() {
60 ExecutionEntity mockExecution = setupMock()
61 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
62 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
63 when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn("8")
64 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
65 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
66 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
69 DoUpdateVnfAndModules obj = new DoUpdateVnfAndModules()
70 obj.queryAAIVfModule(mockExecution)
71 Mockito.verify(mockExecution).setVariable("DUVAM_queryAAIVfModuleResponseCode", 200)
76 void testQueryAAIVfModuleEndpointNull() {
77 ExecutionEntity mockExecution = setupMock()
78 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
79 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
80 when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn("8")
81 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
82 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
83 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
87 DoUpdateVnfAndModules obj = new DoUpdateVnfAndModules()
88 obj.queryAAIVfModule(mockExecution)
89 } catch (Exception ex) {
90 println " Test End - Handle catch-throw BpmnError()! "
92 Mockito.verify(mockExecution, atLeastOnce()).setVariable(captor.capture(), captor.capture())
93 WorkflowException workflowException = captor.getValue()
94 Assert.assertEquals(1002, workflowException.getErrorCode())
95 Assert.assertEquals("AAI GET Failed:org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage())
98 private static ExecutionEntity setupMock() {
99 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
100 when(mockProcessDefinition.getKey()).thenReturn("DoUpdateVfModule")
101 RepositoryService mockRepositoryService = mock(RepositoryService.class)
102 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
103 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoUpdateVfModule")
104 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
105 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
106 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
108 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
109 // Initialize prerequisite variables
110 when(mockExecution.getId()).thenReturn("100")
111 when(mockExecution.getProcessDefinitionId()).thenReturn("DoUpdateVfModule")
112 when(mockExecution.getProcessInstanceId()).thenReturn("DoUpdateVfModule")
113 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
114 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
119 private static void mockData() {
120 stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345[?]depth=1"))
121 .willReturn(aResponse()
122 .withStatus(200).withHeader("Content-Type", "text/xml")
123 .withBodyFile("DoUpdateVfModule/getGenericVnfResponse.xml")))