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
40 import org.onap.so.bpmn.mock.FileUtil
41 import org.onap.so.bpmn.vcpe.scripts.GroovyTestBase
43 import static com.github.tomakehurst.wiremock.client.WireMock.*
44 import static org.mockito.Mockito.*
46 @RunWith(MockitoJUnitRunner.class)
47 class DoDeleteServiceInstanceTest {
50 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
53 void init() throws IOException {
54 MockitoAnnotations.initMocks(this);
58 public void preProcessRequestTest() {
60 ExecutionEntity mex = setupMock()
61 when(mex.getVariable(GroovyTestBase.DBGFLAG)).thenReturn("true")
62 when(mex.getVariable("serviceInstanceId")).thenReturn("e151059a-d924-4629-845f-264db19e50b4")
63 when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("/mso/sdncadapter/")
64 when(mex.getVariable("globalSubscriberId")).thenReturn("4993921112123")
66 DoDeleteServiceInstance instance = new DoDeleteServiceInstance()
67 instance.preProcessRequest(mex)
69 Mockito.verify(mex).setVariable("sdncCallbackUrl", "/mso/sdncadapter/")
70 Mockito.verify(mex).setVariable("siParamsXml", "")
75 public void testPostProcessAAIGET() {
76 ExecutionEntity mockExecution = setupMock()
77 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
78 when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090')
79 when(mockExecution.getVariable("GENGS_FoundIndicator")).thenReturn(true)
80 when(mockExecution.getVariable("sdnc.si.svc.types")).thenReturn("")
81 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("globalSubscriberId_test")
82 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("subscriptionServiceType_test")
84 String aaiGetResponse = FileUtil.readResourceFile("__files/GenericFlows/aaiGetResponse.xml")
85 when(mockExecution.getVariable("GENGS_service")).thenReturn(aaiGetResponse)
86 when(mockExecution.getVariable("GENGS_siResourceLink")).thenReturn("/aai/v8/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/")
87 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
88 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
91 DoDeleteServiceInstance instance = new DoDeleteServiceInstance()
92 instance.postProcessAAIGET(mockExecution)
94 Mockito.verify(mockExecution).setVariable("sendToSDNC", true)
97 private static ExecutionEntity setupMock() {
98 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
99 when(mockProcessDefinition.getKey()).thenReturn("DoDeleteServiceInstance")
100 RepositoryService mockRepositoryService = mock(RepositoryService.class)
101 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
102 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoDeleteServiceInstance")
103 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
104 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
105 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
107 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
108 // Initialize prerequisite variables
109 when(mockExecution.getId()).thenReturn("100")
110 when(mockExecution.getProcessDefinitionId()).thenReturn("DoDeleteServiceInstance")
111 when(mockExecution.getProcessInstanceId()).thenReturn("DoDeleteServiceInstance")
112 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
113 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
118 private void mockData() {
119 stubFor(get(urlMatching(".*/aai/v[0-9]+/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/.*"))
120 .willReturn(aResponse()
121 .withStatus(200).withHeader("Content-Type", "text/xml")