831a7897119402f3039820cffa7735f1787b5ef7
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.openecomp.mso.apihandlerinfra;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.sql.Timestamp;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33
34 import javax.ws.rs.core.Response;
35
36 import org.apache.http.HttpResponse;
37 import org.apache.http.ProtocolVersion;
38 import org.apache.http.client.ClientProtocolException;
39 import org.apache.http.entity.BasicHttpEntity;
40 import org.apache.http.message.BasicHttpResponse;
41 import org.hibernate.HibernateException;
42 import org.hibernate.Session;
43 import org.hibernate.criterion.Criterion;
44 import org.hibernate.criterion.Order;
45 import org.hibernate.internal.SessionFactoryImpl;
46 import org.junit.BeforeClass;
47 import org.junit.Test;
48 import org.junit.Ignore;
49 import org.mockito.Mockito;
50 import org.openecomp.mso.apihandler.common.CamundaClient;
51 import org.openecomp.mso.apihandler.common.RequestClient;
52 import org.openecomp.mso.apihandler.common.RequestClientFactory;
53 import org.openecomp.mso.db.catalog.CatalogDatabase;
54 import org.openecomp.mso.db.catalog.beans.Service;
55 import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
56 import org.openecomp.mso.properties.MsoDatabaseException;
57 import org.openecomp.mso.properties.MsoJavaProperties;
58 import org.openecomp.mso.properties.MsoPropertiesFactory;
59 import org.openecomp.mso.requestsdb.InfraActiveRequests;
60 import org.openecomp.mso.requestsdb.OperationStatus;
61 import org.openecomp.mso.requestsdb.RequestsDatabase;
62
63 import mockit.Mock;
64 import mockit.MockUp;
65
66 public class E2EServiceInstancesTest {
67
68         String jsonBody = "{" +
69                         "\"service\": {" +
70                         "\"name\": \"so_test4\"," +
71                         "\"description\": \"so_test2\"," +
72                         "\"serviceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561519\"," +
73                         "\"serviceUuid\": \"592f9437-a9c0-4303-b9f6-c445bb7e9814\"," +
74                         "\"globalSubscriberId\": \"123457\"," +
75                         "\"serviceType\": \"voLTE\"," +
76                         "\"parameters\": {" +
77                         "\"resources\": [" +
78                         "{" +
79                         "\"resourceName\": \"vIMS\"," +
80                         "\"resourceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561516\"," +
81                         "\"resourceUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561512\"," +
82                         "\"parameters\": {" +
83                         "\"locationConstraints\": [" +
84                         "{" +
85                         "\"vnfProfileId\": \"zte-vBAS-1.0\"," +
86                         "\"locationConstraints\": {" +
87                         "\"vimId\": \"4050083f-465f-4838-af1e-47a545222ad0\"" +
88                         "}" +
89                         "}," +
90                         "{" +
91                         "\"vnfProfileId\": \"zte-vMME-1.0\"," +
92                         "\"locationConstraints\": {" +
93                         "\"vimId\": \"4050083f-465f-4838-af1e-47a545222ad0\"" +
94                         "}" +
95                         "}" +
96                         "]" +
97                         "}" +
98                         "}," +
99                         "{" +
100                         "\"resourceName\": \"vEPC\"," +
101                         "\"resourceInvariantUuid\": \"61c3e96e-0970-4871-b6e0-3b6de7561516\"," +
102                         "\"resourceUuid\": \"62c3e96e-0970-4871-b6e0-3b6de7561512\"," +
103                         "\"parameters\": {" +
104                         "\"locationConstraints\": [" +
105                         "{" +
106                         "\"vnfProfileId\": \"zte-CSCF-1.0\"," +
107                         "\"locationConstraints\": {" +
108                         "\"vimId\": \"4050083f-465f-4838-af1e-47a545222ad1\"" +
109                         "}" +
110                         "}" +
111                         "]" +
112                         "}" +
113                         "}," +
114                         "{" +
115                         "\"resourceName\": \"underlayvpn\"," +
116                         "\"resourceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561513\"," +
117                         "\"resourceUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561514\"," +
118                         "\"parameters\": {" +
119                         "\"locationConstraints\": []" +
120                         "}" +
121                         "}," +
122                         "{" +
123                         "\"resourceName\": \"overlayvpn\"," +
124                         "\"resourceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561517\"," +
125                         "\"resourceUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561518\"," +
126                         "\"parameters\": {" +
127                         "\"locationConstraints\": []" +
128                         "}" +
129                         "}" +
130                         "]," +
131                         "\"requestInputs\": {" +
132                         "\"externalDataNetworkName\": \"Flow_out_net\"," +
133                         "\"m6000_mng_ip\": \"181.18.20.2\"," +
134                         "\"externalCompanyFtpDataNetworkName\": \"Flow_out_net\"," +
135                         "\"externalPluginManageNetworkName\": \"plugin_net_2014\"," +
136                         "\"externalManageNetworkName\": \"mng_net_2017\"," +
137                         "\"sfc_data_network\": \"sfc_data_net_2016\"," +
138                         "\"NatIpRange\": \"210.1.1.10-210.1.1.20\"," +
139                         "\"location\": \"4050083f-465f-4838-af1e-47a545222ad0\"," +
140                         "\"sdncontroller\": \"9b9f02c0-298b-458a-bc9c-be3692e4f35e\"" +
141                         "}" +
142                         "}" +
143                         "}" +
144                         "}";
145
146     private final String compareModelsRequest = "{" +
147             "\"globalSubscriberId\": \"60c3e96e-0970-4871-b6e0-3b6de7561519\"," +
148             "\"serviceType\": \"vnf\"," +
149             "\"modelInvariantIdTarget\": \"60c3e96e-0970-4871-b6e0-3b6de1234567\"," +
150             "\"modelVersionIdTarget\": \"modelVersionIdTarget\"" +
151             "}";
152
153     @BeforeClass
154     public static void setUp() throws Exception {
155
156         MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
157         msoPropertiesFactory.removeAllMsoProperties();
158         msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
159     }
160
161         @Test
162         public void createE2EServiceInstanceTestSuccess() {
163                 new MockUp<RequestsDatabase>() {
164                         @Mock
165                         public OperationStatus getOperationStatusByServiceName(
166                                         String serviceName) {
167                                 OperationStatus operationStatus = new OperationStatus();
168                                 return operationStatus;
169                         }
170                 };
171                 new MockUp<E2EServiceInstances>() {
172                         @Mock
173                         private void createOperationStatusRecordForError(Action action,
174                                         String requestId) throws MsoDatabaseException {
175
176                         }
177                 };
178                 new MockUp<CatalogDatabase>() {
179                         @Mock
180                         public Service getServiceByModelName(String modelName) {
181                                 Service svc = new Service();
182                                 return svc;
183                         }
184                 };
185
186                 new MockUp<CatalogDatabase>() {
187                         @Mock
188                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
189                                         String action) {
190                                 ServiceRecipe rec = new ServiceRecipe();
191                                 return rec;
192                         }
193                 };
194
195                 new MockUp<RequestClientFactory>() {
196                         @Mock
197                         public RequestClient getRequestClient(String orchestrationURI,
198                                         MsoJavaProperties props) throws IllegalStateException {
199                                 RequestClient client = new CamundaClient();
200                                 client.setUrl("/test/url");
201                                 return client;
202                         }
203                 };
204
205                 new MockUp<CamundaClient>() {
206                         @Mock
207                         public HttpResponse post(String requestId, boolean isBaseVfModule,
208                                         int recipeTimeout, String requestAction,
209                                         String serviceInstanceId, String vnfId, String vfModuleId,
210                                         String volumeGroupId, String networkId, String configurationId, String serviceType,
211                                         String vnfType, String vfModuleType, String networkType,
212                                         String requestDetails, String recipeParamXsd) {
213                                 ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
214                                 HttpResponse resp = new BasicHttpResponse(pv, 202,
215                                                 "test response");
216                                 BasicHttpEntity entity = new BasicHttpEntity();
217                                 String body = "{\"response\":\"success\",\"message\":\"success\"}";
218                                 InputStream instream = new ByteArrayInputStream(body.getBytes());
219                                 entity.setContent(instream);
220                                 resp.setEntity(entity);
221                                 return resp;
222                         }
223                 };
224
225                 E2EServiceInstances instance = new E2EServiceInstances();
226                 String request = jsonBody;
227                 Response resp = instance.createE2EServiceInstance(request, "v3");
228                 String respStr = resp.getEntity().toString();
229                 assertTrue(respStr.contains("SVC2000"));
230         }
231
232         @Test
233         public void createE2EServiceInstanceTestBpelHTTPException() {
234                 new MockUp<RequestsDatabase>() {
235                         @Mock
236                         public OperationStatus getOperationStatusByServiceName(
237                                         String serviceName) {
238                                 OperationStatus operationStatus = new OperationStatus();
239                                 return operationStatus;
240                         }
241                 };
242                 new MockUp<E2EServiceInstances>() {
243                         @Mock
244                         private void createOperationStatusRecordForError(Action action,
245                                         String requestId) throws MsoDatabaseException {
246
247                         }
248                 };
249                 new MockUp<CatalogDatabase>() {
250                         @Mock
251                         public Service getServiceByModelName(String modelName) {
252                                 Service svc = new Service();
253                                 return svc;
254                         }
255                 };
256
257                 new MockUp<CatalogDatabase>() {
258                         @Mock
259                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
260                                         String action) {
261                                 ServiceRecipe rec = new ServiceRecipe();
262                                 return rec;
263                         }
264                 };
265
266                 new MockUp<RequestClientFactory>() {
267                         @Mock
268                         public RequestClient getRequestClient(String orchestrationURI,
269                                         MsoJavaProperties props) throws IllegalStateException {
270                                 RequestClient client = new CamundaClient();
271                                 client.setUrl("/test/url");
272                                 return client;
273                         }
274                 };
275
276                 new MockUp<CamundaClient>() {
277                         @Mock
278                         public HttpResponse post(String requestId, boolean isBaseVfModule,
279                                         int recipeTimeout, String requestAction,
280                                         String serviceInstanceId, String vnfId, String vfModuleId,
281                                         String volumeGroupId, String networkId, String configurationId, String serviceType,
282                                         String vnfType, String vfModuleType, String networkType,
283                                         String requestDetails, String recipeParamXsd) {
284                                 ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
285                                 HttpResponse resp = new BasicHttpResponse(pv, 500,
286                                                 "test response");
287                                 BasicHttpEntity entity = new BasicHttpEntity();
288                                 String body = "{\"response\":\"success\",\"message\":\"success\"}";
289                                 InputStream instream = new ByteArrayInputStream(body.getBytes());
290                                 entity.setContent(instream);
291                                 resp.setEntity(entity);
292                                 return resp;
293                         }
294                 };
295
296                 E2EServiceInstances instance = new E2EServiceInstances();
297                 String request = jsonBody;
298                 Response resp = instance.createE2EServiceInstance(request, "v3");
299                 String respStr = resp.getEntity().toString();
300                 assertTrue(respStr.contains("SVC2000"));
301         }
302
303         @Test
304         public void createE2EServiceInstanceTestBpelHTTPExceptionWithNullREsponseBody() {
305                 new MockUp<RequestsDatabase>() {
306                         @Mock
307                         public OperationStatus getOperationStatusByServiceName(
308                                         String serviceName) {
309                                 OperationStatus operationStatus = new OperationStatus();
310                                 return operationStatus;
311                         }
312                 };
313                 new MockUp<E2EServiceInstances>() {
314                         @Mock
315                         private void createOperationStatusRecordForError(Action action,
316                                         String requestId) throws MsoDatabaseException {
317
318                         }
319                 };
320                 new MockUp<CatalogDatabase>() {
321                         @Mock
322                         public Service getServiceByModelName(String modelName) {
323                                 Service svc = new Service();
324                                 return svc;
325                         }
326                 };
327
328                 new MockUp<CatalogDatabase>() {
329                         @Mock
330                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
331                                         String action) {
332                                 ServiceRecipe rec = new ServiceRecipe();
333                                 return rec;
334                         }
335                 };
336
337                 new MockUp<RequestClientFactory>() {
338                         @Mock
339                         public RequestClient getRequestClient(String orchestrationURI,
340                                         MsoJavaProperties props) throws IllegalStateException {
341                                 RequestClient client = new CamundaClient();
342                                 client.setUrl("/test/url");
343                                 return client;
344                         }
345                 };
346
347                 new MockUp<CamundaClient>() {
348                         @Mock
349                         public HttpResponse post(String requestId, boolean isBaseVfModule,
350                                         int recipeTimeout, String requestAction,
351                                         String serviceInstanceId, String vnfId, String vfModuleId,
352                                         String volumeGroupId, String networkId, String configurationId, String serviceType,
353                                         String vnfType, String vfModuleType, String networkType,
354                                         String requestDetails, String recipeParamXsd) {
355                                 ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
356                                 HttpResponse resp = new BasicHttpResponse(pv, 500,
357                                                 "test response");
358                                 BasicHttpEntity entity = new BasicHttpEntity();
359                                 String body = "{\"response\":\"\",\"message\":\"success\"}";
360                                 InputStream instream = new ByteArrayInputStream(body.getBytes());
361                                 entity.setContent(instream);
362                                 resp.setEntity(entity);
363                                 return resp;
364                         }
365                 };
366
367                 E2EServiceInstances instance = new E2EServiceInstances();
368                 String request = jsonBody;
369                 Response resp = instance.createE2EServiceInstance(request, "v3");
370                 String respStr = resp.getEntity().toString();
371                 assertTrue(respStr.contains("SVC2000"));
372         }
373
374         @Test
375         public void createE2EServiceInstanceTestNullBPELResponse() {
376                 new MockUp<RequestsDatabase>() {
377                         @Mock
378                         public OperationStatus getOperationStatusByServiceName(
379                                         String serviceName) {
380                                 OperationStatus operationStatus = new OperationStatus();
381                                 return operationStatus;
382                         }
383                 };
384                 new MockUp<E2EServiceInstances>() {
385                         @Mock
386                         private void createOperationStatusRecordForError(Action action,
387                                         String requestId) throws MsoDatabaseException {
388
389                         }
390                 };
391                 new MockUp<CatalogDatabase>() {
392                         @Mock
393                         public Service getServiceByModelName(String modelName) {
394                                 Service svc = new Service();
395                                 return svc;
396                         }
397                 };
398
399                 new MockUp<CatalogDatabase>() {
400                         @Mock
401                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
402                                         String action) {
403                                 ServiceRecipe rec = new ServiceRecipe();
404                                 return rec;
405                         }
406                 };
407
408                 new MockUp<RequestClientFactory>() {
409                         @Mock
410                         public RequestClient getRequestClient(String orchestrationURI,
411                                         MsoJavaProperties props) throws IllegalStateException {
412                                 RequestClient client = new CamundaClient();
413                                 client.setUrl("/test/url");
414                                 return client;
415                         }
416                 };
417
418                 new MockUp<CamundaClient>() {
419                         @Mock
420                         public HttpResponse post(String requestId, boolean isBaseVfModule,
421                                         int recipeTimeout, String requestAction,
422                                         String serviceInstanceId, String vnfId, String vfModuleId,
423                                         String volumeGroupId, String networkId, String configurationId, String serviceType,
424                                         String vnfType, String vfModuleType, String networkType,
425                                         String requestDetails, String recipeParamXsd) {
426                                 HttpResponse resp = null;
427                                 return resp;
428                         }
429                 };
430
431                 E2EServiceInstances instance = new E2EServiceInstances();
432                 String request = jsonBody;
433                 Response resp = instance.createE2EServiceInstance(request, "v3");
434                 String respStr = resp.getEntity().toString();
435                 assertTrue(respStr.contains("SVC2000"));
436         }
437
438         @Test
439         public void createE2EServiceInstanceTestBPMNNullREsponse() {
440                 new MockUp<RequestsDatabase>() {
441                         @Mock
442                         public OperationStatus getOperationStatusByServiceName(
443                                         String serviceName) {
444                                 OperationStatus operationStatus = new OperationStatus();
445                                 return operationStatus;
446                         }
447                 };
448                 new MockUp<E2EServiceInstances>() {
449                         @Mock
450                         private void createOperationStatusRecordForError(Action action,
451                                         String requestId) throws MsoDatabaseException {
452
453                         }
454                 };
455                 new MockUp<CatalogDatabase>() {
456                         @Mock
457                         public Service getServiceByModelName(String modelName) {
458                                 Service svc = new Service();
459                                 return svc;
460                         }
461                 };
462
463                 new MockUp<CatalogDatabase>() {
464                         @Mock
465                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
466                                         String action) {
467                                 ServiceRecipe rec = new ServiceRecipe();
468                                 return rec;
469                         }
470                 };
471
472                 new MockUp<RequestClientFactory>() {
473                         @Mock
474                         public RequestClient getRequestClient(String orchestrationURI,
475                                         MsoJavaProperties props) throws IllegalStateException {
476                                 RequestClient client = new CamundaClient();
477                                 client.setUrl("/test/url");
478                                 return client;
479                         }
480                 };
481
482                 new MockUp<CamundaClient>() {
483                         @Mock
484                         public HttpResponse post(String camundaReqXML, String requestId,
485                                         String requestTimeout, String schemaVersion,
486                                         String serviceInstanceId, String action) {
487                                 HttpResponse resp = null;
488                                 return resp;
489                         }
490                 };
491                 E2EServiceInstances instance = new E2EServiceInstances();
492                 String request = jsonBody;
493                 Response resp = instance.createE2EServiceInstance(request, "v3");
494                 String respStr = resp.getEntity().toString();
495                 assertTrue(respStr.contains("SVC2000"));
496         }
497
498         @Test
499         public void createE2EServiceInstanceTestNullBpmn() {
500                 new MockUp<RequestsDatabase>() {
501                         @Mock
502                         public OperationStatus getOperationStatusByServiceName(
503                                         String serviceName) {
504                                 OperationStatus operationStatus = new OperationStatus();
505                                 return operationStatus;
506                         }
507                 };
508
509                 new MockUp<E2EServiceInstances>() {
510                         @Mock
511                         private void createOperationStatusRecordForError(Action action,
512                                         String requestId) throws MsoDatabaseException {
513
514                         }
515                 };
516                 new MockUp<CatalogDatabase>() {
517                         @Mock
518                         public Service getServiceByModelName(String modelName) {
519                                 Service svc = new Service();
520                                 return svc;
521                         }
522                 };
523
524                 new MockUp<CatalogDatabase>() {
525                         @Mock
526                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
527                                         String action) {
528                                 ServiceRecipe rec = new ServiceRecipe();
529                                 return rec;
530                         }
531                 };
532                 E2EServiceInstances instance = new E2EServiceInstances();
533                 String request = jsonBody;;
534                 Response resp = instance.createE2EServiceInstance(request, "v3");
535                 String respStr = resp.getEntity().toString();
536                 assertTrue(respStr.contains("SVC2000"));
537         }
538
539         @Test
540         public void createE2EServiceInstanceTestNullReceipe() {
541                 new MockUp<RequestsDatabase>() {
542                         @Mock
543                         public OperationStatus getOperationStatusByServiceName(
544                                         String serviceName) {
545                                 OperationStatus operationStatus = new OperationStatus();
546                                 return operationStatus;
547                         }
548                 };
549                 new MockUp<E2EServiceInstances>() {
550                         @Mock
551                         private void createOperationStatusRecordForError(Action action,
552                                         String requestId) throws MsoDatabaseException {
553
554                         }
555                 };
556
557                 E2EServiceInstances instance = new E2EServiceInstances();
558                 String request = jsonBody;
559                 Response resp = instance.createE2EServiceInstance(request, "v3");
560                 String respStr = resp.getEntity().toString();
561                 assertTrue(respStr.contains("SVC2000"));
562         }
563
564         @Test
565         public void createE2EServiceInstanceTestNullDBResponse() {
566
567                 new MockUp<RequestsDatabase>() {
568                         @Mock
569                         public OperationStatus getOperationStatusByServiceName(
570                                         String serviceName) {
571                                 OperationStatus operationStatus = new OperationStatus();
572                                 return operationStatus;
573                         }
574                 };
575                 new MockUp<E2EServiceInstances>() {
576                         @Mock
577                         private void createOperationStatusRecordForError(Action action,
578                                         String requestId) throws MsoDatabaseException {
579
580                         }
581                 };
582
583                 E2EServiceInstances instance = new E2EServiceInstances();
584                 String request = jsonBody;
585                 Response resp = instance.createE2EServiceInstance(request, "v3");
586                 String respStr = resp.getEntity().toString();
587                 assertTrue(respStr.contains("SVC2000"));
588         }
589
590         @Test
591         public void createE2EServiceInstanceTestInvalidRequest() {
592                 new MockUp<RequestsDatabase>() {
593                         @Mock
594                         public OperationStatus getOperationStatusByServiceName(
595                                         String serviceName) {
596                                 OperationStatus operationStatus = new OperationStatus();
597                                 return operationStatus;
598                         }
599                 };
600
601                 new MockUp<E2EServiceInstances>() {
602                         @Mock
603                         private void createOperationStatusRecordForError(Action action,
604                                         String requestId) throws MsoDatabaseException {
605
606                         }
607                 };
608                 E2EServiceInstances instance = new E2EServiceInstances();
609                 String request = jsonBody;
610                 Response resp = instance.createE2EServiceInstance(request, "v3");
611                 String respStr = resp.getEntity().toString();
612                 assertTrue(respStr.contains("SVC2000"));
613         }
614
615         @Test
616         public void createE2EServiceInstanceTestEmptyDBQuery() {
617                 new MockUp<E2EServiceInstances>() {
618                         @Mock
619                         private void createOperationStatusRecordForError(Action action,
620                                         String requestId) throws MsoDatabaseException {
621
622                         }
623                 };
624
625                 E2EServiceInstances instance = new E2EServiceInstances();
626                 String request = jsonBody;
627                 Response resp = instance.createE2EServiceInstance(request, "v3");
628                 String respStr = resp.getEntity().toString();
629                 assertTrue(respStr.contains("SVC2000"));
630                 // assertTrue(true);
631         }
632
633         @Test
634         public void createE2EServiceInstanceTestDBQueryFail() {
635                 new MockUp<RequestsDatabase>() {
636                         @Mock
637                         public OperationStatus getOperationStatusByServiceName(
638                                         String serviceName) {
639                                 OperationStatus operationStatus = new OperationStatus();
640                                 return operationStatus;
641                         }
642                 };
643
644                 new MockUp<E2EServiceInstances>() {
645                         @Mock
646                         private void createOperationStatusRecordForError(Action action,
647                                         String requestId) throws MsoDatabaseException {
648
649                         }
650                 };
651                 E2EServiceInstances instance = new E2EServiceInstances();
652                 String request = jsonBody;
653                 Response resp = instance.createE2EServiceInstance(request, "v3");
654                 String respStr = resp.getEntity().toString();
655                 assertTrue(respStr.contains("SVC2000"));
656         }
657
658         @Test
659         public void createE2EServiceInstanceTestForEmptyRequest() {
660
661                 new MockUp<E2EServiceInstances>() {
662                         @Mock
663                         private void createOperationStatusRecordForError(Action action,
664                                         String requestId) throws MsoDatabaseException {
665
666                         }
667                 };
668                 E2EServiceInstances instance = new E2EServiceInstances();
669                 String request = "";
670                 Response resp = instance.createE2EServiceInstance(request, "v3");
671                 String respStr = resp.getEntity().toString();
672                 assertTrue(respStr
673             .contains("Mapping of request to JSON object failed.  No content to map due to end-of-input"));
674         }
675
676         @Ignore // 1802 merge
677         @Test
678         public void deleteE2EServiceInstanceTestNormal() {
679                 E2EServiceInstances instance = new E2EServiceInstances();
680                 String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
681                 Response resp = instance.deleteE2EServiceInstance(request, "v3",
682                                 "12345678");
683                 String respStr = resp.getEntity().toString();
684                 assertTrue(respStr.contains("SVC1000"));
685         }
686
687         @Test
688         public void getE2EServiceInstanceTest() {
689
690                 new MockUp<RequestsDatabase>() {
691                         @Mock
692                         public OperationStatus getOperationStatus(String serviceId,
693                                         String operationId) {
694                                 OperationStatus os = new OperationStatus();
695                                 os.setOperation("");
696                                 os.setOperationContent("");
697                                 os.setOperationId("123456");
698                                 os.setProgress("");
699                                 os.setServiceId("12345");
700                                 os.setServiceName("VoLTE");
701                                 os.setReason("");
702                                 os.setResult("");
703                                 os.setUserId("");
704                                 return os;
705                         }
706                 };
707
708                 E2EServiceInstances instance = new E2EServiceInstances();
709                 Response resp = instance
710                                 .getE2EServiceInstances("12345", "v3", "123456");
711
712         }
713         
714         @Test
715         public void updateE2EServiceInstanceTestNormal() {
716                 new MockUp<RequestsDatabase>() {
717                         @Mock
718                         public OperationStatus getOperationStatusByServiceId(
719                                         String serviceID) {
720                                 OperationStatus operationStatus = new OperationStatus();
721                                 operationStatus.setProgress("100");
722                                 operationStatus.setResult("finish");
723                                 return operationStatus;
724                         }
725                 };
726                 new MockUp<E2EServiceInstances>() {
727                         @Mock
728                         private void createOperationStatusRecordForError(Action action,
729                                         String requestId) throws MsoDatabaseException {
730
731                         }
732                 };
733                 new MockUp<CatalogDatabase>() {
734                         @Mock
735                         public Service getServiceByModelName(String modelName) {
736                                 Service svc = new Service();
737                                 return svc;
738                         }
739                 };
740
741                 new MockUp<CatalogDatabase>() {
742                         @Mock
743                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
744                                         String action) {
745                                 ServiceRecipe rec = new ServiceRecipe();
746                                 return rec;
747                         }
748                 };
749
750                 new MockUp<RequestClientFactory>() {
751                         @Mock
752                         public RequestClient getRequestClient(String orchestrationURI,
753                                         MsoJavaProperties props) throws IllegalStateException {
754                                 RequestClient client = new CamundaClient();
755                                 client.setUrl("/test/url");
756                                 return client;
757                         }
758                 };
759
760                 new MockUp<CamundaClient>() {
761                         @Mock
762                         public HttpResponse post(String requestId, boolean isBaseVfModule,
763                                         int recipeTimeout, String requestAction,
764                                         String serviceInstanceId, String vnfId, String vfModuleId,
765                                         String volumeGroupId, String networkId, String configurationId, String serviceType,
766                                         String vnfType, String vfModuleType, String networkType,
767                                         String requestDetails, String recipeParamXsd) {
768                                 ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
769                                 HttpResponse resp = new BasicHttpResponse(pv, 202,
770                                                 "test response");
771                                 BasicHttpEntity entity = new BasicHttpEntity();
772                                 String body = "{\"response\":\"success\",\"message\":\"success\"}";
773                                 InputStream instream = new ByteArrayInputStream(body.getBytes());
774                                 entity.setContent(instream);
775                                 resp.setEntity(entity);
776                                 return resp;
777                         }
778                 };
779
780                 E2EServiceInstances instance = new E2EServiceInstances();
781                 String request = jsonBody;
782                 Response resp = instance.updateE2EServiceInstance(request, "v3", "12345");
783                 String respStr = resp.getEntity().toString();
784                 assertTrue(respStr.contains("success"));
785         }
786         
787         @Test
788         public void updateE2EServiceInstanceTestChkStatusFalse() {
789                 new MockUp<RequestsDatabase>() {
790                         @Mock
791                         public OperationStatus getOperationStatusByServiceId(
792                                         String serviceID) {
793                                 OperationStatus operationStatus = new OperationStatus();
794                                 operationStatus.setResult("processing");
795                                 return operationStatus;
796                         }
797                 };
798                 new MockUp<E2EServiceInstances>() {
799                         @Mock
800                         private void createOperationStatusRecordForError(Action action,
801                                         String requestId) throws MsoDatabaseException {
802
803                         }
804                 };
805                 new MockUp<CatalogDatabase>() {
806                         @Mock
807                         public Service getServiceByModelName(String modelName) {
808                                 Service svc = new Service();
809                                 return svc;
810                         }
811                 };
812
813                 new MockUp<CatalogDatabase>() {
814                         @Mock
815                         public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
816                                         String action) {
817                                 ServiceRecipe rec = new ServiceRecipe();
818                                 return rec;
819                         }
820                 };
821
822                 new MockUp<RequestClientFactory>() {
823                         @Mock
824                         public RequestClient getRequestClient(String orchestrationURI,
825                                         MsoJavaProperties props) throws IllegalStateException {
826                                 RequestClient client = new CamundaClient();
827                                 client.setUrl("/test/url");
828                                 return client;
829                         }
830                 };
831
832                 new MockUp<CamundaClient>() {
833                         @Mock
834                         public HttpResponse post(String requestId, boolean isBaseVfModule,
835                                         int recipeTimeout, String requestAction,
836                                         String serviceInstanceId, String vnfId, String vfModuleId,
837                                         String volumeGroupId, String networkId, String configurationId, String serviceType,
838                                         String vnfType, String vfModuleType, String networkType,
839                                         String requestDetails, String recipeParamXsd) {
840                                 ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
841                                 HttpResponse resp = new BasicHttpResponse(pv, 202,
842                                                 "test response");
843                                 BasicHttpEntity entity = new BasicHttpEntity();
844                                 String body = "{\"response\":\"success\",\"message\":\"success\"}";
845                                 InputStream instream = new ByteArrayInputStream(body.getBytes());
846                                 entity.setContent(instream);
847                                 resp.setEntity(entity);
848                                 return resp;
849                         }
850                 };
851
852                 E2EServiceInstances instance = new E2EServiceInstances();
853                 String request = jsonBody;
854                 Response resp = instance.updateE2EServiceInstance(request, "v3", "12345");
855                 String respStr = resp.getEntity().toString();
856                 assertTrue(respStr.contains("SVC2000"));
857         }
858
859     @Test
860     public void compareModelwithTargetVersionBadRequest(){
861
862         E2EServiceInstances instance = new E2EServiceInstances();
863         Response response = instance.compareModelwithTargetVersion("", "12345", "v3");
864
865         assertNotNull(response);
866         assertTrue(response.getEntity().toString().contains("Mapping of request to JSON object failed."));
867
868     }
869     @Test
870     public void compareModelwithTargetVersionFailedBPMNCall(){
871
872         new MockUp<CamundaClient>() {
873             @Mock
874             public HttpResponse post(String requestId, boolean isBaseVfModule,
875                  int recipeTimeout, String requestAction, String serviceInstanceId,
876                  String vnfId, String vfModuleId, String volumeGroupId, String networkId, String configurationId,
877                  String serviceType, String vnfType, String vfModuleType, String networkType,
878                  String requestDetails, String recipeParamXsd)
879                     throws ClientProtocolException, IOException {
880
881                 throw new ClientProtocolException();
882             }
883         };
884
885         E2EServiceInstances instance = new E2EServiceInstances();
886         Response response = instance.compareModelwithTargetVersion(compareModelsRequest, "12345", "v3");
887
888         assertNotNull(response);
889         assertTrue(response.getEntity().toString().contains("Failed calling bpmn"));
890
891     }
892
893     @Test
894     public void compareModelwithTargetVersionSuccess(){
895
896         new MockUp<CamundaClient>() {
897             @Mock
898             public HttpResponse post(String requestId, boolean isBaseVfModule,
899                                      int recipeTimeout, String requestAction, String serviceInstanceId,
900                                      String vnfId, String vfModuleId, String volumeGroupId, String networkId, String configurationId,
901                                      String serviceType, String vnfType, String vfModuleType, String networkType,
902                                      String requestDetails, String recipeParamXsd)
903                     throws ClientProtocolException, IOException {
904
905                 ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
906                 HttpResponse resp = new BasicHttpResponse(pv, 202,
907                         "compareModelwithTargetVersion, test response");
908                 BasicHttpEntity entity = new BasicHttpEntity();
909                 String body = "{\"response\":\"success\",\"message\":\"success\"}";
910                 InputStream instream = new ByteArrayInputStream(body.getBytes());
911                 entity.setContent(instream);
912                 resp.setEntity(entity);
913
914                 return resp;
915             }
916         };
917
918         E2EServiceInstances instance = new E2EServiceInstances();
919         Response response = instance.compareModelwithTargetVersion(compareModelsRequest, "12345", "v3");
920
921         assertNotNull(response);
922         assertTrue(response.getStatus()==202);
923
924     }
925 }