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 DoDeleteVfModuleFromVnfTest {
48 public WireMockRule wireMockRule = new WireMockRule(28090);
51 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
54 public void init() throws IOException {
55 MockitoAnnotations.initMocks(this);
59 public void testPreProcessRequest() {
60 ExecutionEntity mockExecution = setupMock()
61 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
62 when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
63 when(mockExecution.getVariable("source")).thenReturn("VID")
64 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
65 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
66 when(mockExecution.getVariable("tenantId")).thenReturn("19123c2924c648eb8e42a3c1f14b7682")
67 when(mockExecution.getVariable("vfModuleId")).thenReturn("12345")
68 when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("12345")
69 when(mockExecution.getVariable("sdncVersion")).thenReturn("8")
70 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
72 DoDeleteVfModuleFromVnf obj = new DoDeleteVfModuleFromVnf()
73 obj.preProcessRequest(mockExecution)
75 Mockito.verify(mockExecution).setVariable("prefix", "DDVFMV_")
76 Mockito.verify(mockExecution).setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
77 Mockito.verify(mockExecution).setVariable("mso-request-id", "12345")
78 Mockito.verify(mockExecution).setVariable("requestId", "12345")
79 Mockito.verify(mockExecution).setVariable("cloudSiteId", "12345")
80 Mockito.verify(mockExecution).setVariable("source", "VID")
81 Mockito.verify(mockExecution).setVariable("isVidRequest", "true")
82 Mockito.verify(mockExecution).setVariable("srvInstId", "")
83 Mockito.verify(mockExecution).setVariable("DDVFMV_serviceInstanceIdToSdnc", "12345")
84 Mockito.verify(mockExecution).setVariable("DDVFMV_sdncVersion", "8")
85 Mockito.verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:8090/SDNCAdapterCallback")
91 void testDeleteNetworkPoliciesFromAAI() {
92 ExecutionEntity mockExecution = setupMock()
93 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
94 when(mockExecution.getVariable("mso.workflow.DoDeleteVfModuleFromVnf.aai.network-policy.uri")).thenReturn("/aai/v8/network/network-policies/network-policy")
95 when(mockExecution.getVariable("mso.workflow.custom.DoDeleteVfModuleFromVnf.aai.version")).thenReturn("8")
96 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
97 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
98 List fqdnList = new ArrayList()
100 when(mockExecution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")).thenReturn(fqdnList)
102 DoDeleteVfModuleFromVnf obj = new DoDeleteVfModuleFromVnf()
103 obj.deleteNetworkPoliciesFromAAI(mockExecution)
105 Mockito.verify(mockExecution).setVariable("prefix", 'DDVFMV_')
106 Mockito.verify(mockExecution).setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
111 void testQueryAAIForVfModule() {
112 ExecutionEntity mockExecution = setupMock()
113 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
114 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
115 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
116 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("mso.workflow.global.default.aai.namespace")
117 when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn("8")
118 when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf")
119 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
120 when(mockExecution.getVariable("aai.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
123 DoDeleteVfModuleFromVnf obj = new DoDeleteVfModuleFromVnf()
124 obj.queryAAIForVfModule(mockExecution)
126 Mockito.verify(mockExecution, atLeastOnce()).setVariable("DDVMFV_getVnfResponseCode", 200)
131 private ExecutionEntity setupMock() {
133 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
134 when(mockProcessDefinition.getKey()).thenReturn("DoDeleteVfModuleFromVnf")
135 RepositoryService mockRepositoryService = mock(RepositoryService.class)
136 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
137 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoDeleteVfModuleFromVnf")
138 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
139 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
140 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
142 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
143 // Initialize prerequisite variables
145 when(mockExecution.getId()).thenReturn("100")
146 when(mockExecution.getProcessDefinitionId()).thenReturn("DoDeleteVfModuleFromVnf")
147 when(mockExecution.getProcessInstanceId()).thenReturn("DoDeleteVfModuleFromVnf")
148 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
149 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
155 private static void mockData() {
156 stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345[?]depth=1"))
157 .willReturn(aResponse()
158 .withStatus(200).withHeader("Content-Type", "text/xml")
159 .withBodyFile("VfModularity/GenerateVfModuleName_AAIResponse_Success.xml")))
161 stubFor(get(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy\\?network-policy-fqdn=.*"))
162 .willReturn(aResponse()
164 .withHeader("Content-Type", "text/xml")
165 .withBodyFile("VfModularity/QueryNetworkPolicy_AAIResponse_Success.xml")))
167 stubFor(delete(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy/.*"))
168 .willReturn(aResponse()