Merge "Reorder modifiers"
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / openecomp / mso / bpmn / common / scripts / GenericPutServiceTest.groovy
1 package org.openecomp.mso.bpmn.common.scripts\r
2 \r
3 import static org.mockito.Mockito.*\r
4 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutServiceInstance;\r
5 \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
18 \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
22 \r
23 @RunWith(MockitoJUnitRunner.class)\r
24 class GenericPutServiceTest {\r
25 \r
26         @Rule\r
27         public WireMockRule wireMockRule = new WireMockRule(8090);\r
28 \r
29         @Before\r
30         public void init()\r
31         {\r
32                 MockitoAnnotations.initMocks(this)\r
33 \r
34         }\r
35 \r
36         @Test\r
37         public void preProcessRequest() {\r
38 \r
39 \r
40                 println "************ preProcessRequest ************* "\r
41 \r
42                 ExecutionEntity mockExecution = setupMock()\r
43 \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
50 \r
51                 GenericPutService  putServiceInstance= new GenericPutService()\r
52                 putServiceInstance.preProcessRequest(mockExecution)\r
53 \r
54                 // check the sequence of variable invocation\r
55                 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()\r
56                 //preDebugger.printInvocations(mockExecution)\r
57 \r
58                 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")\r
59                 verify(mockExecution).setVariable("prefix", "GENPS_")\r
60 \r
61         //      execution.getVariable("isDebugLogEnabled")\r
62 \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
68 \r
69 \r
70         }\r
71 \r
72 \r
73         @Test\r
74         @Ignore\r
75         public void putServiceInstance() {\r
76                 println "************ putServiceInstance ************* "\r
77 \r
78                 WireMock.reset();\r
79 \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
82 \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
97 \r
98                 GenericPutService  serviceInstance= new GenericPutService()\r
99                 serviceInstance.putServiceInstance(mockExecution)\r
100 \r
101                 // check the sequence of variable invocation\r
102                 MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()\r
103                 preDebugger.printInvocations(mockExecution)\r
104 \r
105                 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")\r
106                 verify(mockExecution).setVariable("prefix", "GENPS_")\r
107 \r
108         //      execution.getVariable("isDebugLogEnabled")\r
109         //      verify(mockExecution).setVariable("GENPSI_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
110 \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
113 \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
116 \r
117                 int responseCode = 200\r
118                 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode)\r
119 \r
120                 String aaiResponse = """<rest:RESTResponse xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"\r
121                    statusCode="200">\r
122    <rest:headers>\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
129    </rest:headers>\r
130 </rest:RESTResponse>"""\r
131 \r
132                 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse)\r
133 \r
134                 verify(mockExecution).setVariable("GENPS_SuccessIndicator", true)\r
135         }\r
136 \r
137         @Test\r
138         @Ignore\r
139         public void putServiceInstance_404() {\r
140 \r
141 \r
142                 println "************ putServiceInstance ************* "\r
143 \r
144                 WireMock.reset();\r
145 \r
146                 ExecutionEntity mockExecution = setupMock()\r
147 \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
156 \r
157                 GenericPutService  serviceInstance= new GenericPutService()\r
158                 serviceInstance.putServiceInstance(mockExecution)\r
159 \r
160                 // check the sequence of variable invocation\r
161                 MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()\r
162                 preDebugger.printInvocations(mockExecution)\r
163 \r
164                 verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled")\r
165                 verify(mockExecution).setVariable("prefix", "GENPS_")\r
166 \r
167         //      execution.getVariable("isDebugLogEnabled")\r
168 \r
169 \r
170                 verify(mockExecution).setVariable("GENPS_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
171 \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
175 \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
178 \r
179                 int responseCode = 404\r
180                 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode)\r
181 \r
182                 String aaiResponse = ""\r
183                 verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse)\r
184 \r
185                 verify(mockExecution).setVariable("GENPS_SuccessIndicator", false)\r
186 \r
187 \r
188         }\r
189 \r
190 \r
191         private ExecutionEntity setupMock() {\r
192 \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
201 \r
202                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
203                 // Initialize prerequisite variables\r
204 \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
210 \r
211                 return mockExecution\r
212         }\r
213 \r
214 }