1ff098b9406112964de621e631e9fee12d878c4a
[so.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.vcpe.scripts
24
25 import org.camunda.bpm.engine.ProcessEngineServices
26 import org.camunda.bpm.engine.RepositoryService
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.engine.repository.ProcessDefinition
30 import org.junit.runner.RunWith
31 import org.mockito.Mock
32 import org.mockito.junit.MockitoJUnitRunner
33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
34 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.client.aai.AAIResourcesClient
37
38 import static org.mockito.ArgumentMatchers.any
39 import static org.mockito.Mockito.*
40
41 @RunWith(MockitoJUnitRunner.class)
42 class GroovyTestBase {
43
44     static final int PORT = 28090
45     static final String LOCAL_URI = "http://localhost:" + PORT
46
47     static final String CUST = "SDN-ETHERNET-INTERNET"
48     static final String SVC = "123456789"
49     static final String INST = "MIS%252F1604%252F0026%252FSW_INTERNET"
50     static final String ARID = "arId-1"
51     static final String VERS = "myvers"
52
53     static final String DBGFLAG = "isDebugLogEnabled"
54
55     static String aaiUriPfx
56
57     String processName
58
59     AllottedResourceUtils allottedResourceUtils_MOCK
60
61     @Mock
62     AAIResourcesClient client_MOCK
63
64     public static void setUpBeforeClass() {
65         aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint")
66     }
67
68     public GroovyTestBase(String processName) {
69         this.processName = processName
70     }
71
72     public boolean doBpmnError(def func) {
73
74         try {
75             func()
76             return false;
77
78         } catch (BpmnError e) {
79             return true;
80         }
81     }
82
83     public ExecutionEntity setupMock() {
84
85         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
86         when(mockProcessDefinition.getKey()).thenReturn(processName)
87         RepositoryService mockRepositoryService = mock(RepositoryService.class)
88         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
89         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(processName)
90         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
91         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
92
93         ExecutionEntity mex = mock(ExecutionEntity.class)
94
95         when(mex.getProcessDefinitionId()).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 initAllottedResourceMock() {
112         allottedResourceUtils_MOCK = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)))
113     }
114
115 }