AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / 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 package org.openecomp.mso.bpmn.vcpe.scripts
21
22
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.junit.Before
28 import org.junit.BeforeClass
29 import org.junit.Rule
30 import org.junit.Test
31 import org.junit.Ignore
32 import org.mockito.MockitoAnnotations
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.openecomp.mso.bpmn.core.WorkflowException
35 import org.openecomp.mso.bpmn.mock.FileUtil
36
37 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
38 import static com.github.tomakehurst.wiremock.client.WireMock.get
39 import static com.github.tomakehurst.wiremock.client.WireMock.patch
40 import static com.github.tomakehurst.wiremock.client.WireMock.put
41 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
42 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
43 import static org.junit.Assert.*;
44 import static org.mockito.Mockito.*
45 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
46 import org.openecomp.mso.bpmn.core.RollbackData
47 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
48
49 import com.github.tomakehurst.wiremock.junit.WireMockRule
50
51 class GroovyTestBase {
52         
53         static final int PORT = 28090
54         static final String LOCAL_URI = "http://localhost:" + PORT
55         
56         static final String CUST = "SDN-ETHERNET-INTERNET"
57         static final String SVC = "123456789"
58         static final String INST = "MIS%252F1604%252F0026%252FSW_INTERNET"
59         static final String ARID = "arId-1"
60         static final String VERS = "myvers"
61         
62         static final String DBGFLAG = "isDebugLogEnabled"
63         
64         static Properties urnProps = new Properties()
65         static String aaiUriPfx
66         
67         String processName
68
69         static {
70                 def fr = new FileReader("src/test/resources/mso.bpmn.urn.properties")
71                 urnProps.load(fr)
72                 fr.close()
73
74                 aaiUriPfx = urnProps.get("aai.endpoint")
75         }
76
77         public static void setUpBeforeClass() {
78                 // moved to the above static block to get the static aaiUriPfx assignment correctly.
79         }
80         
81         public GroovyTestBase(String processName) {
82                 this.processName = processName
83         }
84         
85         public boolean doBpmnError(def func) {
86                 
87                 try {
88                         func()
89                         return false;
90                         
91                 } catch(BpmnError e) {
92                         return true;
93                 }
94         }
95         
96         public ExecutionEntity setupMock() {
97                 
98                 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
99                 when(mockProcessDefinition.getKey()).thenReturn(processName)
100                 RepositoryService mockRepositoryService = mock(RepositoryService.class)
101                 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
102                 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(processName)
103                 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
104                 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
105                 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
106                 
107                 ExecutionEntity mex = mock(ExecutionEntity.class)
108                 
109                 when(mex.getId()).thenReturn("100")
110                 when(mex.getProcessDefinitionId()).thenReturn(processName)
111                 when(mex.getProcessInstanceId()).thenReturn(processName)
112                 when(mex.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
113                 when(mex.getProcessEngineServices().getRepositoryService().getProcessDefinition(mex.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
114                 
115                 when(mex.getVariable("isAsyncProcess")).thenReturn("true")
116                 when(mex.getVariable(processName+"WorkflowResponseSent")).thenReturn("false")
117                 
118                 return mex
119         }
120         
121         public Map<String,Object> setupMap(ExecutionEntity mex) {
122                 MapSetter mapset = new MapSetter();
123                 doAnswer(mapset).when(mex).setVariable(any(), any())
124                 return mapset.getMap();
125         }
126                 
127 }