2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.common.scripts
23 import static org.mockito.Mockito.*
24 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutServiceInstance;
26 import org.camunda.bpm.engine.ProcessEngineServices
27 import org.camunda.bpm.engine.RepositoryService
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.engine.repository.ProcessDefinition
30 import org.junit.Before
31 import org.junit.Ignore
34 import org.junit.runner.RunWith
35 import org.mockito.MockitoAnnotations
36 import org.mockito.internal.debugging.MockitoDebuggerImpl
37 import org.mockito.runners.MockitoJUnitRunner
39 import com.github.tomakehurst.wiremock.client.WireMock
40 import com.github.tomakehurst.wiremock.junit.WireMockRule
41 import org.apache.commons.lang3.*
43 @RunWith(MockitoJUnitRunner.class)
45 class GenericPutServiceTest {
48 public WireMockRule wireMockRule = new WireMockRule(8090);
53 MockitoAnnotations.initMocks(this)
58 public void preProcessRequest() {
61 println "************ preProcessRequest ************* "
63 ExecutionEntity mockExecution = setupMock()
65 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
66 when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26")
67 when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
68 when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET")
69 when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
70 when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance")
72 GenericPutService putServiceInstance= new GenericPutService()
73 putServiceInstance.preProcessRequest(mockExecution)
75 // check the sequence of variable invocation
76 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
77 //preDebugger.printInvocations(mockExecution)
79 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")
80 verify(mockExecution).setVariable("prefix", "GENPS_")
82 // execution.getVariable("isDebugLogEnabled")
84 verify(mockExecution).setVariable("GENPS_SuccessIndicator", false)
85 // verify(mockExecution).setVariable("globalSubscriberId", "1604-MVM-26")
86 // verify(mockExecution).setVariable("serviceInstanceId", "MIS%2F1604%2F0026%2FSW_INTERNET")
87 // verify(mockExecution).setVariable("serviceType", "SDN-ETHERNET-INTERNET")
88 // verify(mockExecution).setVariable("ServiceInstanceData", "f70e927b-6087-4974-9ef8-c5e4d5847ca4")
96 public void putServiceInstance() {
97 println "************ putServiceInstance ************* "
101 MockPutServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericPutServiceInstance/GenericPutServiceInstance_PutServiceInstance_AAIResponse_Success.xml");
102 ExecutionEntity mockExecution = setupMock()
104 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
105 when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26")
106 when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
107 when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET")
108 when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
109 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:8090")
110 when(mockExecution.getVariable("mso.workflow.PutServiceInstance.aai.business.customer.uri")).thenReturn("/aai/v7/business/customers/customer")
111 when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
112 when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance")
113 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
114 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn("7")
115 when(mockExecution.getVariable("mso.workflow.default.aai.v7.customer.uri")).thenReturn("/aai/v7/business/customers/customer")
116 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
117 when(mockExecution.getVariable("aai.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
119 GenericPutService serviceInstance= new GenericPutService()
120 serviceInstance.putServiceInstance(mockExecution)
122 // check the sequence of variable invocation
123 MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
124 preDebugger.printInvocations(mockExecution)
126 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")
127 verify(mockExecution).setVariable("prefix", "GENPS_")
129 // execution.getVariable("isDebugLogEnabled")
130 // verify(mockExecution).setVariable("GENPSI_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4")
132 String servicePayload = """<service-instance xmlns="http://org.openecomp.aai.inventory/v7">f70e927b-6087-4974-9ef8-c5e4d5847ca4</service-instance>""" as String
133 verify(mockExecution).setVariable("GENPS_serviceInstancePayload",servicePayload)
135 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"
136 verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceAaiPath)
138 int responseCode = 200
139 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode)
141 String aaiResponse = """<rest:RESTResponse xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
144 <rest:header name="Date" value="Thu,10 Mar 2016 00:01:18 GMT"/>
145 <rest:header name="Content-Length" value="0"/>
146 <rest:header name="Expires" value="Thu,01 Jan 1970 00:00:00 UTC"/>
147 <rest:header name="X-AAI-TXID" value="mtcnjv9aaas03-20160310-00:01:18:551-132672"/>
148 <rest:header name="Server" value="Apache-Coyote/1.1"/>
149 <rest:header name="Cache-Control" value="private"/>
151 </rest:RESTResponse>"""
153 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse)
155 verify(mockExecution).setVariable("GENPS_SuccessIndicator", true)
160 public void putServiceInstance_404() {
163 println "************ putServiceInstance ************* "
167 ExecutionEntity mockExecution = setupMock()
169 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
170 when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26")
171 when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET")
172 when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET")
173 when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
174 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:8090")
175 when(mockExecution.getVariable("mso.workflow.PutServiceInstance.aai.business.customer_uri")).thenReturn("/aai/v7/business/customers/customer")
176 when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
178 GenericPutService serviceInstance= new GenericPutService()
179 serviceInstance.putServiceInstance(mockExecution)
181 // check the sequence of variable invocation
182 MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
183 preDebugger.printInvocations(mockExecution)
185 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")
186 verify(mockExecution).setVariable("prefix", "GENPS_")
188 // execution.getVariable("isDebugLogEnabled")
191 verify(mockExecution).setVariable("GENPS_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4")
193 String serviceInstancepayload = """<service-instance xmlns="http://org.onap.so.aai.inventory/v7">f70e927b-6087-4974-9ef8-c5e4d5847ca4
194 </service-instance>""" as String
195 verify(mockExecution).setVariable("GENPS_serviceInstancePayload",serviceInstancepayload)
197 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"
198 verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceInstanceAaiPath)
200 int responseCode = 404
201 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode)
203 String aaiResponse = ""
204 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse)
206 verify(mockExecution).setVariable("GENPS_SuccessIndicator", false)
212 private ExecutionEntity setupMock() {
214 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
215 when(mockProcessDefinition.getKey()).thenReturn("PutServiceInstance")
216 RepositoryService mockRepositoryService = mock(RepositoryService.class)
217 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
218 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PutServiceInstance")
219 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
220 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
221 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
223 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
224 // Initialize prerequisite variables
226 when(mockExecution.getId()).thenReturn("100")
227 when(mockExecution.getProcessDefinitionId()).thenReturn("PutServiceInstance")
228 when(mockExecution.getProcessInstanceId()).thenReturn("PutServiceInstance")
229 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
230 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)