Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / 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.camunda.bpm.engine.delegate.DelegateExecution
29 import org.junit.Before
30 import org.junit.BeforeClass
31 import org.junit.Rule
32 import org.junit.Test
33 import org.junit.Ignore
34 import org.mockito.MockitoAnnotations
35 import org.camunda.bpm.engine.delegate.BpmnError
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.mock.FileUtil
39 import org.springframework.beans.factory.config.YamlPropertiesFactoryBean
40 import org.springframework.core.io.ClassPathResource
41 import org.springframework.core.io.Resource
42
43 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
44 import static com.github.tomakehurst.wiremock.client.WireMock.get
45 import static com.github.tomakehurst.wiremock.client.WireMock.patch
46 import static com.github.tomakehurst.wiremock.client.WireMock.put
47 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
48 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
49 import static org.junit.Assert.*;
50 import static org.mockito.Mockito.*
51 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource
52 import org.onap.so.bpmn.core.RollbackData
53 import org.onap.so.bpmn.vcpe.scripts.MapSetter
54
55 import com.github.tomakehurst.wiremock.junit.WireMockRule
56
57 class GroovyTestBase {
58         
59         static final int PORT = 28090
60         static final String LOCAL_URI = "http://localhost:" + PORT
61         
62         static final String CUST = "SDN-ETHERNET-INTERNET"
63         static final String SVC = "123456789"
64         static final String INST = "MIS%252F1604%252F0026%252FSW_INTERNET"
65         static final String ARID = "arId-1"
66         static final String VERS = "myvers"
67         
68         static final String DBGFLAG = "isDebugLogEnabled"
69         
70         static String aaiUriPfx
71         
72         String processName
73
74         public static void setUpBeforeClass() {
75                 aaiUriPfx = UrnPropertiesReader.getVariable("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         }
92         
93         public ExecutionEntity setupMock() {
94                 
95                 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
96                 when(mockProcessDefinition.getKey()).thenReturn(processName)
97                 RepositoryService mockRepositoryService = mock(RepositoryService.class)
98                 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
99                 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(processName)
100                 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
101                 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
102                 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
103                 
104                 ExecutionEntity mex = mock(ExecutionEntity.class)
105                 
106                 when(mex.getId()).thenReturn("100")
107                 when(mex.getProcessDefinitionId()).thenReturn(processName)
108                 when(mex.getProcessInstanceId()).thenReturn(processName)
109                 when(mex.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
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")
114                 
115                 return mex
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         }
123                 
124 }