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.Spy
38 import org.mockito.runners.MockitoJUnitRunner
39 import org.onap.aai.domain.yang.GenericVnf
40 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
41 import org.onap.so.bpmn.core.WorkflowException
42 import org.onap.aaiclient.client.aai.AAIObjectType
43 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
44 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
45 import org.onap.aaiclient.client.graphinventory.entities.uri.Depth
46 import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException
47 import static com.github.tomakehurst.wiremock.client.WireMock.*
48 import static org.mockito.Mockito.*
50 @RunWith(MockitoJUnitRunner.class)
51 public class DoDeleteVnfAndModulesTest extends MsoGroovyTest{
54 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
57 DoDeleteVnfAndModules doDeleteVnfAndModules
59 String cloudConfiguration = "{ " +
60 "\"lcpCloudRegionId\": \"mdt1\"," +
61 "\"tenantId\": \"88a6ca3ee0394ade9403f075db23167e\"" + "}";
64 public void init() throws IOException {
65 super.init("DoDeleteVnfAndModules")
66 MockitoAnnotations.initMocks(this);
67 when(doDeleteVnfAndModules.getAAIClient()).thenReturn(client)
71 public void testPreProcessRequestTest() {
72 ExecutionEntity mockExecution = setupMock()
73 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
74 when(mockExecution.getVariable("cloudConfiguration")).thenReturn(cloudConfiguration)
75 when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
76 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
77 when(mockExecution.getVariable("sdncVersion")).thenReturn("1702")
78 when(mockExecution.getVariable("productFamilyId")).thenReturn("productFamilyId")
79 when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("mdt1")
80 when(mockExecution.getVariable("tenantId")).thenReturn("19123c2924c648eb8e42a3c1f14b7682")
81 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_test")
82 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
84 DoDeleteVnfAndModules obj = new DoDeleteVnfAndModules()
85 obj.preProcessRequest(mockExecution)
87 Mockito.verify(mockExecution).setVariable("prefix", "DDVAM_")
88 Mockito.verify(mockExecution).setVariable("requestId", "12345")
89 Mockito.verify(mockExecution).setVariable("mso-request-id", "12345")
90 Mockito.verify(mockExecution).setVariable("DDVAM_source", "VID")
91 Mockito.verify(mockExecution).setVariable("DDVAM_isVidRequest", "true")
92 Mockito.verify(mockExecution).setVariable("DDVAM_sdncVersion", "1702")
93 Mockito.verify(mockExecution).setVariable("DDVAM_isVidRequest", "true")
94 Mockito.verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:8090/SDNCAdapterCallback")
100 public void testQueryAAIVfModuleNullEndPoint() {
101 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
102 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "12345").depth(Depth.ONE)
103 doThrow(new GraphInventoryUriComputationException("Error in AAI")).when(client).get(GenericVnf.class,uri)
105 doDeleteVnfAndModules.queryAAIVfModule(mockExecution)
106 } catch (Exception ex) {
107 println " Test End - Handle catch-throw BpmnError()! "
109 Mockito.verify(mockExecution,atLeastOnce()).setVariable(captor.capture(),captor.capture())
110 WorkflowException workflowException = captor.getValue()
111 Assert.assertEquals("AAI GET Failed:Error in AAI", workflowException.getErrorMessage())
112 Assert.assertEquals(1002, workflowException.getErrorCode())
116 public void testQueryAAIVfModule() {
117 ExecutionEntity mockExecution = setupMock()
118 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
119 mockAAIGenericVnf("12345","__files/AAI/GenericVnfVfModule.json")
120 doDeleteVnfAndModules.queryAAIVfModule(mockExecution)
121 Mockito.verify(mockExecution).setVariable("DCVFM_queryAAIVfModuleResponseCode", 200)
124 private ExecutionEntity setupMock() {
126 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
127 when(mockProcessDefinition.getKey()).thenReturn("DoDeleteVnfAndModules")
128 RepositoryService mockRepositoryService = mock(RepositoryService.class)
129 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
130 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoDeleteVnfAndModules")
131 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
132 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
133 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
135 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
136 // Initialize prerequisite variables
138 when(mockExecution.getId()).thenReturn("100")
139 when(mockExecution.getProcessDefinitionId()).thenReturn("DoDeleteVnfAndModules")
140 when(mockExecution.getProcessInstanceId()).thenReturn("DoDeleteVnfAndModules")
141 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
142 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
148 private void mockData() {
150 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345[?]depth=1"))
151 .willReturn(aResponse()
153 .withHeader("Content-Type", "text/xml")
154 .withBodyFile("GenericFlows/getGenericVnfResponse_hasRelationships.xml")));