1 package org.openecomp.mso.bpmn.common.scripts
\r
3 import static org.mockito.Mockito.*
\r
4 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutServiceInstance;
\r
6 import org.camunda.bpm.engine.ProcessEngineServices
\r
7 import org.camunda.bpm.engine.RepositoryService
\r
8 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
9 import org.camunda.bpm.engine.repository.ProcessDefinition
\r
10 import org.junit.Before
\r
11 import org.junit.Ignore
\r
12 import org.junit.Rule
\r
13 import org.junit.Test
\r
14 import org.junit.runner.RunWith
\r
15 import org.mockito.MockitoAnnotations
\r
16 import org.mockito.internal.debugging.MockitoDebuggerImpl
\r
17 import org.mockito.runners.MockitoJUnitRunner
\r
19 import com.github.tomakehurst.wiremock.client.WireMock
\r
20 import com.github.tomakehurst.wiremock.junit.WireMockRule
\r
21 import org.apache.commons.lang3.*
\r
23 @RunWith(MockitoJUnitRunner.class)
\r
24 class GenericPutServiceTest {
\r
27 public WireMockRule wireMockRule = new WireMockRule(8090);
\r
32 MockitoAnnotations.initMocks(this)
\r
37 public void preProcessRequest() {
\r
40 println "************ preProcessRequest ************* "
\r
42 ExecutionEntity mockExecution = setupMock()
\r
44 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
45 when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26")
\r
46 when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
\r
47 when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET")
\r
48 when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
49 when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance")
\r
51 GenericPutService putServiceInstance= new GenericPutService()
\r
52 putServiceInstance.preProcessRequest(mockExecution)
\r
54 // check the sequence of variable invocation
\r
55 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
\r
56 //preDebugger.printInvocations(mockExecution)
\r
58 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")
\r
59 verify(mockExecution).setVariable("prefix", "GENPS_")
\r
61 // execution.getVariable("isDebugLogEnabled")
\r
63 verify(mockExecution).setVariable("GENPS_SuccessIndicator", false)
\r
64 // verify(mockExecution).setVariable("globalSubscriberId", "1604-MVM-26")
\r
65 // verify(mockExecution).setVariable("serviceInstanceId", "MIS%2F1604%2F0026%2FSW_INTERNET")
\r
66 // verify(mockExecution).setVariable("serviceType", "SDN-ETHERNET-INTERNET")
\r
67 // verify(mockExecution).setVariable("ServiceInstanceData", "f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
75 public void putServiceInstance() {
\r
76 println "************ putServiceInstance ************* "
\r
80 MockPutServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericPutServiceInstance/GenericPutServiceInstance_PutServiceInstance_AAIResponse_Success.xml");
\r
81 ExecutionEntity mockExecution = setupMock()
\r
83 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
84 when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26")
\r
85 when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
\r
86 when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET")
\r
87 when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
88 when(mockExecution.getVariable("URN_aai_endpoint")).thenReturn("http://localhost:8090")
\r
89 when(mockExecution.getVariable("URN_mso_workflow_PutServiceInstance_aai_business_customer_uri")).thenReturn("/aai/v7/business/customers/customer")
\r
90 when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
91 when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance")
\r
92 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/')
\r
93 when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn("7")
\r
94 when(mockExecution.getVariable("URN_mso_workflow_default_aai_v7_customer_uri")).thenReturn("/aai/v7/business/customers/customer")
\r
95 when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
\r
96 when(mockExecution.getVariable("URN_aai_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
\r
98 GenericPutService serviceInstance= new GenericPutService()
\r
99 serviceInstance.putServiceInstance(mockExecution)
\r
101 // check the sequence of variable invocation
\r
102 MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
\r
103 preDebugger.printInvocations(mockExecution)
\r
105 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")
\r
106 verify(mockExecution).setVariable("prefix", "GENPS_")
\r
108 // execution.getVariable("isDebugLogEnabled")
\r
109 // verify(mockExecution).setVariable("GENPSI_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
111 String servicePayload = """<service-instance xmlns="http://org.openecomp.aai.inventory/v7">f70e927b-6087-4974-9ef8-c5e4d5847ca4</service-instance>""" as String
\r
112 verify(mockExecution).setVariable("GENPS_serviceInstancePayload",servicePayload)
\r
114 String serviceAaiPath = "http://localhost:28090/aai/v7/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET"
\r
115 verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceAaiPath)
\r
117 int responseCode = 200
\r
118 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode)
\r
120 String aaiResponse = """<rest:RESTResponse xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
\r
123 <rest:header name="Date" value="Thu,10 Mar 2016 00:01:18 GMT"/>
\r
124 <rest:header name="Content-Length" value="0"/>
\r
125 <rest:header name="Expires" value="Thu,01 Jan 1970 00:00:00 UTC"/>
\r
126 <rest:header name="X-AAI-TXID" value="mtcnjv9aaas03-20160310-00:01:18:551-132672"/>
\r
127 <rest:header name="Server" value="Apache-Coyote/1.1"/>
\r
128 <rest:header name="Cache-Control" value="private"/>
\r
130 </rest:RESTResponse>"""
\r
132 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse)
\r
134 verify(mockExecution).setVariable("GENPS_SuccessIndicator", true)
\r
139 public void putServiceInstance_404() {
\r
142 println "************ putServiceInstance ************* "
\r
146 ExecutionEntity mockExecution = setupMock()
\r
148 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
149 when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26")
\r
150 when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
\r
151 when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET")
\r
152 when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
153 when(mockExecution.getVariable("URN_aai_endpoint")).thenReturn("http://localhost:8090")
\r
154 when(mockExecution.getVariable("URN_mso_workflow_PutServiceInstance_aai_business_customer_uri")).thenReturn("/aai/v7/business/customers/customer")
\r
155 when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
157 GenericPutService serviceInstance= new GenericPutService()
\r
158 serviceInstance.putServiceInstance(mockExecution)
\r
160 // check the sequence of variable invocation
\r
161 MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
\r
162 preDebugger.printInvocations(mockExecution)
\r
164 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")
\r
165 verify(mockExecution).setVariable("prefix", "GENPS_")
\r
167 // execution.getVariable("isDebugLogEnabled")
\r
170 verify(mockExecution).setVariable("GENPS_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
172 String serviceInstancepayload = """<service-instance xmlns="http://org.openecomp.mso.aai.inventory/v7">f70e927b-6087-4974-9ef8-c5e4d5847ca4
\r
173 </service-instance>""" as String
\r
174 verify(mockExecution).setVariable("GENPS_serviceInstancePayload",serviceInstancepayload)
\r
176 String serviceInstanceAaiPath = "http://localhost:8090/aai/v7/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET"
\r
177 verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceInstanceAaiPath)
\r
179 int responseCode = 404
\r
180 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode)
\r
182 String aaiResponse = ""
\r
183 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse)
\r
185 verify(mockExecution).setVariable("GENPS_SuccessIndicator", false)
\r
191 private ExecutionEntity setupMock() {
\r
193 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
\r
194 when(mockProcessDefinition.getKey()).thenReturn("PutServiceInstance")
\r
195 RepositoryService mockRepositoryService = mock(RepositoryService.class)
\r
196 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
\r
197 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PutServiceInstance")
\r
198 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
\r
199 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
\r
200 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
\r
202 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
203 // Initialize prerequisite variables
\r
205 when(mockExecution.getId()).thenReturn("100")
\r
206 when(mockExecution.getProcessDefinitionId()).thenReturn("PutServiceInstance")
\r
207 when(mockExecution.getProcessInstanceId()).thenReturn("PutServiceInstance")
\r
208 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
\r
209 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
\r
211 return mockExecution
\r