Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / vcpe / scripts / GroovyTestBase.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.vcpe.scripts
22
23
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.*
37
38 @RunWith(MockitoJUnitRunner.class)
39 class GroovyTestBase {
40         
41         static final int PORT = 28090
42         static final String LOCAL_URI = "http://localhost:" + PORT
43         
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"
49         
50         static final String DBGFLAG = "isDebugLogEnabled"
51         
52         static String aaiUriPfx
53         
54         String processName
55
56     AllottedResourceUtils allottedResourceUtils_MOCK
57
58     @Mock
59     AAIResourcesClient client_MOCK
60
61         public static void setUpBeforeClass() {
62                 aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint")
63         }
64         
65         public GroovyTestBase(String processName) {
66                 this.processName = processName
67         }
68         
69         public boolean doBpmnError(def func) {
70                 
71                 try {
72                         func()
73                         return false;
74                         
75                 } catch(BpmnError e) {
76                         return true;
77                 }
78         }
79         
80         public ExecutionEntity setupMock() {
81                 
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)
90                 
91                 ExecutionEntity mex = mock(ExecutionEntity.class)
92                 
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)
98                 
99                 when(mex.getVariable("isAsyncProcess")).thenReturn("true")
100                 when(mex.getVariable(processName+"WorkflowResponseSent")).thenReturn("false")
101                 
102                 return mex
103         }
104         
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();
109         }
110
111     void init(){
112         allottedResourceUtils_MOCK = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)))
113         when(allottedResourceUtils_MOCK.getAAIClient()).thenReturn(client_MOCK)
114     }
115
116 }