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.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.runners.MockitoJUnitRunner
38 import org.onap.so.bpmn.core.WorkflowException
40 import static com.github.tomakehurst.wiremock.client.WireMock.*
41 import static org.mockito.Mockito.*
43 @RunWith(MockitoJUnitRunner.class)
45 class GenerateVfModuleNameTest {
48 ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class);
52 public WireMockRule wireMockRule = new WireMockRule(8090);
55 public void testQueryAAI() {
56 ExecutionEntity mockExecution = setupMock()
57 when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090')
58 when(mockExecution.getVariable("vnfId")).thenReturn('skask')
59 when(mockExecution.getVariable("personaModelId")).thenReturn('personaModelId_test')
60 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
61 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
62 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf')
63 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
64 when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn('8')
67 GenerateVfModuleName obj = new GenerateVfModuleName()
68 obj.queryAAI(mockExecution)
70 Mockito.verify(mockExecution).setVariable("GVFMN_queryAAIVfModuleResponseCode", 200)
74 public void testQueryAAIEndpointNull() {
75 ExecutionEntity mockExecution = setupMock()
76 when(mockExecution.getVariable("aai.endpoint")).thenReturn(null)
77 when(mockExecution.getVariable("vnfId")).thenReturn('skask')
78 when(mockExecution.getVariable("personaModelId")).thenReturn('personaModelId_test')
79 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
80 when(mockExecution.getVariable("mso.workflow.global.default.aai.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("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
83 when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn('8')
87 GenerateVfModuleName obj = new GenerateVfModuleName()
88 obj.queryAAI(mockExecution)
89 } catch (Exception ex) {
90 println " Test End - Handle catch-throw BpmnError()! "
93 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
94 WorkflowException workflowException = captor.getValue()
95 Assert.assertEquals(1002, workflowException.getErrorCode())
96 Assert.assertEquals("AAI GET Failed:org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage())
100 private void mockData() {
101 stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf.*"))
102 .willReturn(aResponse()
103 .withStatus(200).withHeader("Content-Type", "text/xml")
104 .withBodyFile("GenericFlows/getGenericVnfResponse.xml")))
107 private ExecutionEntity setupMock() {
109 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
110 when(mockProcessDefinition.getKey()).thenReturn("GenerateVfModuleName")
111 RepositoryService mockRepositoryService = mock(RepositoryService.class)
112 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
113 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("GenerateVfModuleName")
114 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
115 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
116 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
117 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
118 when(mockExecution.getId()).thenReturn("100")
119 when(mockExecution.getProcessDefinitionId()).thenReturn("GenerateVfModuleName")
120 when(mockExecution.getProcessInstanceId()).thenReturn("GenerateVfModuleName")
121 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
122 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)