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.vcpe.scripts
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.runner.RunWith
29 import org.mockito.Mock
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.mockito.runners.MockitoJUnitRunner
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
34 import org.onap.so.bpmn.core.UrnPropertiesReader
35 import org.onap.so.client.aai.AAIResourcesClient
36 import static org.mockito.Mockito.*
38 @RunWith(MockitoJUnitRunner.class)
39 class GroovyTestBase {
41 static final int PORT = 28090
42 static final String LOCAL_URI = "http://localhost:" + PORT
44 static final String CUST = "SDN-ETHERNET-INTERNET"
45 static final String SVC = "123456789"
46 static final String INST = "MIS%252F1604%252F0026%252FSW_INTERNET"
47 static final String ARID = "arId-1"
48 static final String VERS = "myvers"
50 static final String DBGFLAG = "isDebugLogEnabled"
52 static String aaiUriPfx
56 AllottedResourceUtils allottedResourceUtils_MOCK
59 AAIResourcesClient client_MOCK
61 public static void setUpBeforeClass() {
62 aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint")
65 public GroovyTestBase(String processName) {
66 this.processName = processName
69 public boolean doBpmnError(def func) {
75 } catch(BpmnError e) {
80 public ExecutionEntity setupMock() {
82 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
83 when(mockProcessDefinition.getKey()).thenReturn(processName)
84 RepositoryService mockRepositoryService = mock(RepositoryService.class)
85 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
86 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(processName)
87 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
88 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
89 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
91 ExecutionEntity mex = mock(ExecutionEntity.class)
93 when(mex.getId()).thenReturn("100")
94 when(mex.getProcessDefinitionId()).thenReturn(processName)
95 when(mex.getProcessInstanceId()).thenReturn(processName)
96 when(mex.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
97 when(mex.getProcessEngineServices().getRepositoryService().getProcessDefinition(mex.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
99 when(mex.getVariable("isAsyncProcess")).thenReturn("true")
100 when(mex.getVariable(processName+"WorkflowResponseSent")).thenReturn("false")
105 public Map<String,Object> setupMap(ExecutionEntity mex) {
106 MapSetter mapset = new MapSetter();
107 doAnswer(mapset).when(mex).setVariable(any(), any())
108 return mapset.getMap();
112 allottedResourceUtils_MOCK = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)))
113 when(allottedResourceUtils_MOCK.getAAIClient()).thenReturn(client_MOCK)