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.common.scripts.utils.XmlComparator
40 import org.onap.so.bpmn.core.WorkflowException
41 import org.onap.so.bpmn.mock.FileUtil
43 import static com.github.tomakehurst.wiremock.client.WireMock.*
44 import static org.mockito.Mockito.*
46 @RunWith(MockitoJUnitRunner.class)
47 class UpdateVfModuleVolumeInfraV1Test {
49 def prefix = "UPDVfModVol_"
51 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
54 public WireMockRule wireMockRule = new WireMockRule(28090);
59 MockitoAnnotations.initMocks(this)
63 void testQueryAAIForVfModule() {
64 ExecutionEntity mockExecution = setupMock()
65 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
66 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
67 when(mockExecution.getVariable("UPDVfModVol_relatedVfModuleLink")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf/12345/vf-modules/vf-module/12345")
68 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
69 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
70 when(mockExecution.getVariable("aai.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
73 UpdateVfModuleVolumeInfraV1 obj = new UpdateVfModuleVolumeInfraV1()
74 obj.queryAAIForVfModule(mockExecution, "true")
76 Mockito.verify(mockExecution, atLeastOnce()).setVariable("UPDVfModVol_personaModelId", "ff5256d2-5a33-55df-13ab-12abad84e7ff")
80 void testPrepVnfAdapterRest() {
81 ExecutionEntity mockExecution = setupMock()
82 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
83 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
84 when(mockExecution.getVariable(prefix + "aicCloudRegion")).thenReturn("RDM2WAGPLCP")
85 when(mockExecution.getVariable(prefix + "tenantId")).thenReturn("")
86 when(mockExecution.getVariable(prefix + "aaiVolumeGroupResponse")).thenReturn(FileUtil.readResourceFile("__files/UpdateVfModuleVolumeInfraV1/queryVolumeId_AAIResponse_Success.xml"))
87 when(mockExecution.getVariable(prefix + "vnfType")).thenReturn("vnf1")
88 when(mockExecution.getVariable(prefix + "vnfVersion")).thenReturn("1")
89 when(mockExecution.getVariable(prefix + "AAIQueryGenericVfnResponse")).thenReturn(FileUtil.readResourceFile("__files/GenericFlows/getGenericVnfByNameResponse.xml"))
90 when(mockExecution.getVariable(prefix + "requestId")).thenReturn("12345")
91 when(mockExecution.getVariable(prefix + "serviceId")).thenReturn("12345")
92 when(mockExecution.getVariable("mso-request-id")).thenReturn("12345")
93 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn('http://localhost:28080/mso/WorkflowMessage')
94 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
97 UpdateVfModuleVolumeInfraV1 obj = new UpdateVfModuleVolumeInfraV1()
98 obj.prepVnfAdapterRest(mockExecution, "true")
100 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
101 def updateVolumeGroupRequest = captor.getValue()
102 String expectedValue = FileUtil.readResourceFile("__files/UpdateVfModuleVolumeInfraV1/updateVolumeGroupRequest.xml")
103 XmlComparator.assertXMLEquals(expectedValue, updateVolumeGroupRequest, "messageId", "notificationUrl")
107 private static ExecutionEntity setupMock() {
108 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
109 when(mockProcessDefinition.getKey()).thenReturn("UpdateVfModuleVolumeInfraV1")
110 RepositoryService mockRepositoryService = mock(RepositoryService.class)
111 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
112 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("UpdateVfModuleVolumeInfraV1")
113 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
114 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
115 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
117 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
118 // Initialize prerequisite variables
119 when(mockExecution.getId()).thenReturn("100")
120 when(mockExecution.getProcessDefinitionId()).thenReturn("UpdateVfModuleVolumeInfraV1")
121 when(mockExecution.getProcessInstanceId()).thenReturn("UpdateVfModuleVolumeInfraV1")
122 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
123 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
128 private static void mockData() {
129 stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345/vf-modules/vf-module/.*"))
130 .willReturn(aResponse()
131 .withStatus(200).withHeader("Content-Type", "text/xml")
132 .withBodyFile("UpdateVfModuleVolumeInfraV1/vf_module_aai_response.xml")))