19638f42da845cd86e355e90629bd45abdeb12a8
[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 import org.junit.Rule
30 import org.junit.rules.ExpectedException
31 import org.junit.runner.RunWith
32 import org.mockito.runners.MockitoJUnitRunner
33 import org.onap.so.client.aai.AAIResourcesClient
34
35 @RunWith(MockitoJUnitRunner.class)
36 abstract class MsoGroovyTest {
37
38     @Rule
39     public ExpectedException thrown = ExpectedException.none()
40         protected ExecutionEntity mockExecution
41         protected AAIResourcesClient client
42
43         protected void init(String procName){
44                 mockExecution = setupMock(procName)
45                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
46                 client = mock(AAIResourcesClient.class)
47         }
48
49         protected ExecutionEntity setupMock(String procName) {
50                 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
51                 when(mockProcessDefinition.getKey()).thenReturn(procName)
52                 RepositoryService mockRepositoryService = mock(RepositoryService.class)
53                 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
54                 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(procName)
55                 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
56                 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
57                 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
58                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
59                 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
60                 return mockExecution
61         }
62 }