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