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
32 import org.junit.runner.RunWith
33 import org.mockito.ArgumentCaptor
34 import org.mockito.Captor
35 import org.mockito.Mockito
36 import org.mockito.MockitoAnnotations
37 import org.mockito.runners.MockitoJUnitRunner
38 import org.onap.so.bpmn.common.scripts.utils.XmlComparator
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.mock.FileUtil
42 import static com.github.tomakehurst.wiremock.client.WireMock.*
43 import static org.mockito.Mockito.*
45 @RunWith(MockitoJUnitRunner.class)
46 class DoDeleteVfModuleTest {
49 public WireMockRule wireMockRule = new WireMockRule(28090);
52 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
55 public void init() throws IOException {
56 MockitoAnnotations.initMocks(this);
60 public void testPrepSDNCAdapterRequest() {
61 ExecutionEntity mockExecution = setupMock()
62 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
63 when(mockExecution.getVariable("testReqId")).thenReturn("testReqId")
64 when(mockExecution.getVariable("requestId")).thenReturn("12345")
65 when(mockExecution.getVariable("source")).thenReturn("VID")
66 when(mockExecution.getVariable("serviceId")).thenReturn("12345")
67 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
68 when(mockExecution.getVariable("tenantId")).thenReturn("19123c2924c648eb8e42a3c1f14b7682")
69 when(mockExecution.getVariable("vfModuleId")).thenReturn("12345")
70 when(mockExecution.getVariable("DoDVfMod_serviceInstanceIdToSdnc")).thenReturn("123456789")
71 when(mockExecution.getVariable("vfModuleName")).thenReturn("vfModuleName_test")
72 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
74 DoDeleteVfModule obj = new DoDeleteVfModule()
75 obj.prepSDNCAdapterRequest(mockExecution, 'release')
77 String expectedValue = FileUtil.readResourceFile("__files/DoDeleteVfModule/sdncAdapterWorkflowRequest.xml")
78 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
79 XmlComparator.assertXMLEquals(expectedValue, captor.getValue())
84 void testDeleteNetworkPoliciesFromAAI() {
85 ExecutionEntity mockExecution = setupMock()
86 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
87 when(mockExecution.getVariable("mso.workflow.DoDeleteVfModule.aai.network-policy.uri")).thenReturn("/aai/v8/network/network-policies/network-policy")
88 when(mockExecution.getVariable("mso.workflow.custom.DoDeleteVfModule.aai.version")).thenReturn("8")
89 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
90 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
91 List fqdnList = new ArrayList()
93 when(mockExecution.getVariable("DoDVfMod_contrailNetworkPolicyFqdnList")).thenReturn(fqdnList)
95 DoDeleteVfModule obj = new DoDeleteVfModule()
96 obj.deleteNetworkPoliciesFromAAI(mockExecution)
98 Mockito.verify(mockExecution).setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
103 void testQueryAAIVfModuleForStatus() {
104 ExecutionEntity mockExecution = setupMock()
105 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
106 when(mockExecution.getVariable("DCVFM_vnfId")).thenReturn("12345")
107 when(mockExecution.getVariable("DCVFM_vfModuleName")).thenReturn("module-0")
108 when(mockExecution.getVariable("mso.workflow.DoDeleteVfModule.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf")
109 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
110 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
113 DoCreateVfModule obj = new DoCreateVfModule()
114 obj.queryAAIVfModuleForStatus(mockExecution)
116 Mockito.verify(mockExecution).setVariable("DCVFM_queryAAIVfModuleForStatusResponseCode", 200)
121 private ExecutionEntity setupMock() {
123 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
124 when(mockProcessDefinition.getKey()).thenReturn("DoDeleteVfModule")
125 RepositoryService mockRepositoryService = mock(RepositoryService.class)
126 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
127 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoDeleteVfModule")
128 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
129 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
130 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
132 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
133 // Initialize prerequisite variables
135 when(mockExecution.getId()).thenReturn("100")
136 when(mockExecution.getProcessDefinitionId()).thenReturn("DoDeleteVfModule")
137 when(mockExecution.getProcessInstanceId()).thenReturn("DoDeleteVfModule")
138 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
139 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
145 private static void mockData() {
146 stubFor(get(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy\\?network-policy-fqdn=.*"))
147 .willReturn(aResponse()
149 .withHeader("Content-Type", "text/xml")
150 .withBodyFile("VfModularity/QueryNetworkPolicy_AAIResponse_Success.xml")))
152 stubFor(delete(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy/.*"))
153 .willReturn(aResponse()
156 stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345/vf-modules/vf-module[?]vf-module-name=module-0"))
157 .willReturn(aResponse()
158 .withStatus(200).withHeader("Content-Type", "text/xml")
159 .withBodyFile("DoDeleteVfModule/getGenericVnfResponse.xml")))