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.generated.fluentbuilders.AAIFluentTypeBuilder
46 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
47 import org.onap.aaiclient.client.graphinventory.entities.uri.Depth
48 import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException
49 import static com.github.tomakehurst.wiremock.client.WireMock.*
50 import static org.mockito.Mockito.*
52 @RunWith(MockitoJUnitRunner.class)
53 public class DoDeleteVnfAndModulesTest extends MsoGroovyTest{
56 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
59 DoDeleteVnfAndModules doDeleteVnfAndModules
61 String cloudConfiguration = "{ " +
62 "\"lcpCloudRegionId\": \"mdt1\"," +
63 "\"tenantId\": \"88a6ca3ee0394ade9403f075db23167e\"" + "}";
66 public void init() throws IOException {
67 super.init("DoDeleteVnfAndModules")
68 MockitoAnnotations.initMocks(this);
69 when(doDeleteVnfAndModules.getAAIClient()).thenReturn(client)
73 public void testPreProcessRequestTest() {
74 ExecutionEntity mockExecution = setupMock()
75 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
76 when(mockExecution.getVariable("cloudConfiguration")).thenReturn(cloudConfiguration)
77 when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
78 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("serviceInstanceId")
79 when(mockExecution.getVariable("sdncVersion")).thenReturn("1702")
80 when(mockExecution.getVariable("productFamilyId")).thenReturn("productFamilyId")
81 when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("mdt1")
82 when(mockExecution.getVariable("tenantId")).thenReturn("19123c2924c648eb8e42a3c1f14b7682")
83 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_test")
84 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
86 DoDeleteVnfAndModules obj = new DoDeleteVnfAndModules()
87 obj.preProcessRequest(mockExecution)
89 Mockito.verify(mockExecution).setVariable("prefix", "DDVAM_")
90 Mockito.verify(mockExecution).setVariable("requestId", "12345")
91 Mockito.verify(mockExecution).setVariable("mso-request-id", "12345")
92 Mockito.verify(mockExecution).setVariable("DDVAM_source", "VID")
93 Mockito.verify(mockExecution).setVariable("DDVAM_isVidRequest", "true")
94 Mockito.verify(mockExecution).setVariable("DDVAM_sdncVersion", "1702")
95 Mockito.verify(mockExecution).setVariable("DDVAM_isVidRequest", "true")
96 Mockito.verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:8090/SDNCAdapterCallback")
102 public void testQueryAAIVfModuleNullEndPoint() {
103 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
104 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("12345")).depth(Depth.ONE)
105 doThrow(new GraphInventoryUriComputationException("Error in AAI")).when(client).get(GenericVnf.class,uri)
107 doDeleteVnfAndModules.queryAAIVfModule(mockExecution)
108 } catch (Exception ex) {
109 println " Test End - Handle catch-throw BpmnError()! "
111 Mockito.verify(mockExecution,atLeastOnce()).setVariable(captor.capture(),captor.capture())
112 WorkflowException workflowException = captor.getValue()
113 Assert.assertEquals("AAI GET Failed:Error in AAI", workflowException.getErrorMessage())
114 Assert.assertEquals(1002, workflowException.getErrorCode())
118 public void testQueryAAIVfModule() {
119 ExecutionEntity mockExecution = setupMock()
120 when(mockExecution.getVariable("vnfId")).thenReturn("12345")
121 mockAAIGenericVnf("12345","__files/AAI/GenericVnfVfModule.json")
122 doDeleteVnfAndModules.queryAAIVfModule(mockExecution)
123 Mockito.verify(mockExecution).setVariable("DCVFM_queryAAIVfModuleResponseCode", 200)
126 private ExecutionEntity setupMock() {
128 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
129 when(mockProcessDefinition.getKey()).thenReturn("DoDeleteVnfAndModules")
130 RepositoryService mockRepositoryService = mock(RepositoryService.class)
131 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
132 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoDeleteVnfAndModules")
133 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
134 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
135 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
137 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
138 // Initialize prerequisite variables
140 when(mockExecution.getId()).thenReturn("100")
141 when(mockExecution.getProcessDefinitionId()).thenReturn("DoDeleteVnfAndModules")
142 when(mockExecution.getProcessInstanceId()).thenReturn("DoDeleteVnfAndModules")
143 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
144 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
150 private void mockData() {
152 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345[?]depth=1"))
153 .willReturn(aResponse()
155 .withHeader("Content-Type", "text/xml")
156 .withBodyFile("GenericFlows/getGenericVnfResponse_hasRelationships.xml")));