01e37f0cd71b61fc7ec214bdda04002a5c4c6828
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / MsoGroovyTest.groovy
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
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 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
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========================================================= 
19  */ 
20
21 package org.onap.so.bpmn.common.scripts
22
23 import static org.mockito.Mockito.*
24
25 import org.camunda.bpm.engine.ProcessEngineServices
26 import org.camunda.bpm.engine.RepositoryService
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import org.camunda.bpm.engine.repository.ProcessDefinition
29
30 abstract class MsoGroovyTest {
31         
32         protected ExecutionEntity setupMock(String procName) {
33                 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
34                 when(mockProcessDefinition.getKey()).thenReturn(procName)
35                 
36                 RepositoryService mockRepositoryService = mock(RepositoryService.class)
37                 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
38                 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(procName)
39                 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
40                 
41                 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
42                 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
43                 
44                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
45                 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
46                 
47                 return mockExecution
48         }
49         
50         protected ExecutionEntity setupMockWithPrefix(String procName, String prefix) {
51                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
52
53                 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
54
55                 ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class)
56                 RepositoryService repositoryService = mock(RepositoryService.class)
57                 ProcessDefinition processDefinition = mock(ProcessDefinition.class)
58
59                 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices)
60                 when(processEngineServices.getRepositoryService()).thenReturn(repositoryService)
61                 when(repositoryService.getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(processDefinition)
62                 when(processDefinition.getKey()).thenReturn(procName)
63                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
64                 return mockExecution
65         }
66         
67         
68 }