[VID-3] Setting docker image tag
[vid.git] / vid / src / main / java / org / openecomp / vid / controller / test / TestMsoController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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.openecomp.vid.controller.test;
22
23 import java.io.IOException;
24 import java.util.stream.Collectors;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.codehaus.jackson.map.ObjectMapper;
30 import org.openecomp.vid.model.ExceptionResponse;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.web.bind.annotation.ExceptionHandler;
34 import org.springframework.web.bind.annotation.PathVariable;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestMethod;
37 import org.springframework.web.bind.annotation.RestController;
38
39 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
40
41 /*
42  * The "TestMsoController" class is primarily designed to help test "msoCommitController.js"
43  * 
44  * This class expects and receives JSON data in the same format as expected
45  * in the "real" application version of this code. However, string versions of JSON are
46  * maintained internally here instead of marshalled / unmarshalled JSON objects.
47  * The primary reasons for this were to encapsulate all the test code in this single file and
48  * minimize the time required to support initial test cases.
49  * 
50  * The non-test equivalent of this controller could alternatively incorporate POJO objects
51  * instead of strings. However, the same data format sent to / received from the browser
52  * JavaScript code would still be expected.
53  * 
54  * Two specific mechanisms used in this test class may be useful to the application version:
55  * 
56  *              1) The use of "{variable}" elements in @RequestMappings along with the corresponding
57  *              @PathVariable declarations.
58  * 
59  *              2) The use of @ExceptionHandler for general purpose exception handler.
60  *              (See @ExceptionHandler comments)
61  *
62  * This class is intended to be used in either:
63  * 
64  *              A) Eclipse environments
65  *      OR
66  *              B) Linux environments with ONLY a single user running tests.
67  *              The "quick and dirty" error simulation approach used here makes use of static states for some
68  *              scenarios. Thus multiple users simultaneously testing in Linux environments
69  *              may have contention issues.
70  */
71
72 /**
73  * The Class TestMsoController.
74  */
75 @RestController
76 @RequestMapping("testmso")
77 public class TestMsoController extends RestrictedBaseController {
78
79         /*
80          * Artificial delay (in milliseconds) added before responding to create /
81          * delete requests
82          */
83
84         /** The Constant TEST_DELAY_SHORT_MSEC. */
85         private final static int TEST_DELAY_SHORT_MSEC = 1000;
86
87         /*
88          * Long delay to simulate non-responsive server test
89          */
90
91         /** The Constant TEST_DELAY_LONG_MSEC. */
92         private final static int TEST_DELAY_LONG_MSEC = 15000;
93
94         /*
95          * Default number of polls expected before transaction complete.
96          */
97
98         /** The Constant MAXIMUM_POLLS_DEFAULT. */
99         private final static int MAXIMUM_POLLS_DEFAULT = 4;
100
101         /*
102          * Number of polls to simulate "maximum polls exceeded" test.
103          */
104
105         /** The Constant MAXIMUM_POLLS_LARGE. */
106         private final static int MAXIMUM_POLLS_LARGE = 10;
107
108         /*
109          * Simulated error types. The GUI front end is expected to set these values
110          * in the "modelName" field of the "mso_create_svc_instance" request.
111          */
112
113         /** The Constant ERROR_POLICY_EXCEPTION. */
114         private final static String ERROR_POLICY_EXCEPTION = "ERROR_POLICY_EXCEPTION";
115         
116         /** The Constant ERROR_SERVICE_EXCEPTION. */
117         private final static String ERROR_SERVICE_EXCEPTION = "ERROR_SERVICE_EXCEPTION";
118         
119         /** The Constant ERROR_POLL_FAILURE. */
120         private final static String ERROR_POLL_FAILURE = "ERROR_POLL_FAILURE";
121         
122         /** The Constant ERROR_INVALID_FIELD_INITIAL. */
123         private final static String ERROR_INVALID_FIELD_INITIAL = "ERROR_INVALID_FIELD_INITIAL";
124         
125         /** The Constant ERROR_INVALID_FIELD_POLL. */
126         private final static String ERROR_INVALID_FIELD_POLL = "ERROR_INVALID_FIELD_POLL";
127         
128         /** The Constant ERROR_GENERAL_SERVER_EXCEPTION. */
129         private final static String ERROR_GENERAL_SERVER_EXCEPTION = "ERROR_GENERAL_SERVER_EXCEPTION";
130         
131         /** The Constant ERROR_MAX_POLLS. */
132         private final static String ERROR_MAX_POLLS = "ERROR_MAX_POLLS";
133         
134         /** The Constant ERROR_SERVER_TIMEOUT_INITIAL. */
135         private final static String ERROR_SERVER_TIMEOUT_INITIAL = "ERROR_SERVER_TIMEOUT_INITIAL";
136         
137         /** The Constant ERROR_SERVER_TIMEOUT_POLL. */
138         private final static String ERROR_SERVER_TIMEOUT_POLL = "ERROR_SERVER_TIMEOUT_POLL";
139
140         /** The simulated error. */
141         private String simulatedError = "";
142         
143         /** The maximum polls. */
144         private int maximumPolls = 0;
145         
146         /** The attempt count. */
147         private int attemptCount = 0;
148
149         /**
150          * Creates the svc instance.
151          *
152          * @param request the request
153          * @return the response entity
154          * @throws Exception the exception
155          */
156         @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)
157         public ResponseEntity<String> createSvcInstance(HttpServletRequest request) throws Exception {
158                 readAndLogRequest("CREATE SERVICE INSTANCE", request);
159                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
160                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
161                 attemptCount = 0;
162
163                 /*
164                  * This block of code simulates various errors and would NOT be expected
165                  * in a non-test method
166                  */
167                 System.err.println("simulatedError: " + simulatedError);
168
169                 if (simulatedError.equals(ERROR_POLICY_EXCEPTION)) {
170                         return new ResponseEntity<String>(policyExceptionResponse, HttpStatus.OK);
171                 }
172                 if (simulatedError.equals(ERROR_SERVICE_EXCEPTION)) {
173                         return new ResponseEntity<String>(serviceExceptionResponse, HttpStatus.OK);
174                 }
175                 if (simulatedError.equals(ERROR_INVALID_FIELD_INITIAL)) {
176                         /*
177                          * Force invalid response field name. Return
178                          * "XXXXXrequestReferences" instead of "requestReferences"
179                          */
180                         return new ResponseEntity<String>(acceptResponse.replace("requestReferences", "XXXXXrequestReferences"),
181                                         HttpStatus.OK);
182                 }
183
184                 if (simulatedError.equals(ERROR_GENERAL_SERVER_EXCEPTION)) {
185                         throw new IOException("an example of an IO exception");
186                 }
187
188                 if (simulatedError.equals(ERROR_SERVER_TIMEOUT_INITIAL)) {
189                         Thread.sleep(TEST_DELAY_LONG_MSEC);
190                 }
191
192                 if (simulatedError.equals(ERROR_MAX_POLLS)) {
193                         maximumPolls = MAXIMUM_POLLS_LARGE;
194                 }
195
196                 /*
197                  * End of block of simulated error code.
198                  */
199
200                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
201         }
202
203         /**
204          * Delete svc instance.
205          *
206          * @param serviceInstanceId the service instance id
207          * @param request the request
208          * @return the response entity
209          * @throws Exception the exception
210          */
211         @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
212         public ResponseEntity<String> deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
213                         HttpServletRequest request) throws Exception {
214                 readAndLogRequest("DELETE SERVICE INSTANCE: serviceInstanceId: " + serviceInstanceId, request);
215                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
216                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
217                 attemptCount = 0;
218                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
219         }
220
221         /**
222          * Creates the vnf instance.
223          *
224          * @param serviceInstanceId the service instance id
225          * @param request the request
226          * @return the response entity
227          * @throws Exception the exception
228          */
229         @RequestMapping(value = "/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
230         public ResponseEntity<String> createVnfInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
231                         HttpServletRequest request) throws Exception {
232                 readAndLogRequest("CREATE VNF INSTANCE: serviceInstanceId: " + serviceInstanceId, request);
233                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
234                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
235                 attemptCount = 0;
236                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
237         }
238
239         /**
240          * Delete vnf instance.
241          *
242          * @param serviceInstanceId the service instance id
243          * @param vnfInstanceId the vnf instance id
244          * @param request the request
245          * @return the response entity
246          * @throws Exception the exception
247          */
248         @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
249         public ResponseEntity<String> deleteVnfInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
250                         @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request) throws Exception {
251                 readAndLogRequest(
252                                 "DELETE VNF INSTANCE: serviceInstanceId: " + serviceInstanceId + " vnfInstanceId: " + vnfInstanceId,
253                                 request);
254                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
255                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
256                 attemptCount = 0;
257                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
258         }
259
260         /**
261          * Creates the vf module instance.
262          *
263          * @param serviceInstanceId the service instance id
264          * @param vnfInstanceId the vnf instance id
265          * @param request the request
266          * @return the response entity
267          * @throws Exception the exception
268          */
269         // /serviceInstances/v2/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-ff1b-adb2-eb6b9e5460ff/vfModules
270         @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
271         public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
272                         @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request) throws Exception {
273                 readAndLogRequest("CREATE VF MODULE INSTANCE: serviceInstanceId: " + serviceInstanceId + " vnfInstanceId: "
274                                 + vnfInstanceId, request);
275                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
276                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
277                 attemptCount = 0;
278                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
279         }
280
281         /**
282          * Delete vf module instance.
283          *
284          * @param serviceInstanceId the service instance id
285          * @param vnfInstanceId the vnf instance id
286          * @param vfModuleInstanceId the vf module instance id
287          * @param request the request
288          * @return the response entity
289          * @throws Exception the exception
290          */
291         // /serviceInstances/v2/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-ff1b-adb2-eb6b9e5460ff/vfModules/ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff
292         @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleInstanceId}", method = RequestMethod.POST)
293         public ResponseEntity<String> deleteVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
294                         @PathVariable("vnfInstanceId") String vnfInstanceId,
295                         @PathVariable("vfModuleInstanceId") String vfModuleInstanceId, HttpServletRequest request)
296                         throws Exception {
297                 readAndLogRequest("DELETE VF MODULE INSTANCE: serviceInstanceId: " + serviceInstanceId + " vnfInstanceId: "
298                                 + vnfInstanceId + " vfModuleInstanceId: " + vfModuleInstanceId, request);
299                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
300                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
301                 attemptCount = 0;
302                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
303         }
304
305         // POST
306         /**
307          * Creates the volume group instance.
308          *
309          * @param serviceInstanceId the service instance id
310          * @param vnfInstanceId the vnf instance id
311          * @param request the request
312          * @return the response entity
313          * @throws Exception the exception
314          */
315         // /serviceInstances/v2/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups
316         @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
317         public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
318                         @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request) throws Exception {
319                 readAndLogRequest("CREATE VOLUME GROUP INSTANCE: seviceInstanceId: " + serviceInstanceId + " vnfInstanceId: "
320                                 + vnfInstanceId, request);
321                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
322                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
323                 attemptCount = 0;
324                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
325         }
326
327         /**
328          * Delete volume group instance.
329          *
330          * @param serviceInstanceId the service instance id
331          * @param vnfInstanceId the vnf instance id
332          * @param volumeGroupInstanceId the volume group instance id
333          * @param request the request
334          * @return the response entity
335          * @throws Exception the exception
336          */
337         // /serviceInstances/v2/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-ff1b-cdb2-eb6b9e5460ff
338         @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupInstanceId}", method = RequestMethod.POST)
339         public ResponseEntity<String> deleteVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
340                         @PathVariable("vnfInstanceId") String vnfInstanceId,
341                         @PathVariable("volumeGroupInstanceId") String volumeGroupInstanceId, HttpServletRequest request)
342                         throws Exception {
343                 readAndLogRequest("DELETE NW INSTANCE: serviceInstanceId: " + serviceInstanceId + " vnfInstanceId: "
344                                 + vnfInstanceId + " volumeGroupInstanceId: " + volumeGroupInstanceId, request);
345                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
346                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
347                 attemptCount = 0;
348                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
349         }
350
351         /**
352          * Creates the nw instance.
353          *
354          * @param serviceInstanceId the service instance id
355          * @param request the request
356          * @return the response entity
357          * @throws Exception the exception
358          */
359         @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
360         public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
361                         HttpServletRequest request) throws Exception {
362                 readAndLogRequest("CREATE NW INSTANCE: serviceInstanceId: " + serviceInstanceId, request);
363                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
364                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
365                 attemptCount = 0;
366                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
367         }
368
369         /**
370          * Delete nw instance.
371          *
372          * @param serviceInstanceId the service instance id
373          * @param networkInstanceId the network instance id
374          * @param request the request
375          * @return the response entity
376          * @throws Exception the exception
377          */
378         @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)
379         public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
380                         @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request) throws Exception {
381                 readAndLogRequest("DELETE NW INSTANCE: serviceInstanceId: " + serviceInstanceId + " networkInstanceId: "
382                                 + networkInstanceId, request);
383                 Thread.sleep(TEST_DELAY_SHORT_MSEC);
384                 maximumPolls = MAXIMUM_POLLS_DEFAULT; // Simulates MSO polling behavior
385                 attemptCount = 0;
386                 return new ResponseEntity<String>(acceptResponse, HttpStatus.OK);
387         }
388
389         /**
390          * Gets the orchestration request.
391          *
392          * @param requestId the request id
393          * @param request the request
394          * @return the orchestration request
395          * @throws Exception the exception
396          */
397         @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)
398         public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,
399                         HttpServletRequest request) throws Exception {
400
401                 System.err.println("GET ORCHESTRATION REQUEST: requestId: " + requestId);
402
403                 /*
404                  * This block of code simulates various errors and would NOT be expected
405                  * in a non-test method
406                  */
407
408                 if (simulatedError.equals(ERROR_INVALID_FIELD_POLL)) {
409                         /*
410                          * Force invalid response field name. Return "XXXXXrequestStatus"
411                          * instead of "requestStatus"
412                          */
413                         return new ResponseEntity<String>(inProgressResponse.replace("requestStatus", "XXXXXrequestStatus"),
414                                         HttpStatus.OK);
415                 }
416
417                 if (simulatedError.equals(ERROR_POLL_FAILURE)) {
418                         /*
419                          * Force status field with "Failure"
420                          */
421                         return new ResponseEntity<String>(inProgressResponse.replace("InProgress", "Failure"), HttpStatus.OK);
422                 }
423
424                 if (simulatedError.equals(ERROR_SERVER_TIMEOUT_POLL)) {
425                         Thread.sleep(TEST_DELAY_LONG_MSEC);
426                 }
427
428                 /*
429                  * End of block of simulated error code.
430                  */
431
432                 /*
433                  * This logic simulates how MSO might behave ... i.e. return different
434                  * results depending on the value of 'maximumPolls'.
435                  *
436                  */
437                 int percentProgress = (++attemptCount * 100) / maximumPolls;
438
439                 System.err.println("attempts: " + attemptCount + " max: " + maximumPolls + " percent: " + percentProgress);
440
441                 String response = inProgressResponse.replace("\"50\"", "\"" + Integer.toString(percentProgress) + "\"");
442
443                 if (attemptCount < maximumPolls) {
444                         if (attemptCount > 1) {
445                                 response = response.replace("vLan setup", "setup step " + Integer.toString(attemptCount));
446                         }
447                         return new ResponseEntity<String>(response, HttpStatus.OK);
448                 } else {
449                         return new ResponseEntity<String>(
450                                         response.replace("InProgress", "Complete").replace("vLan setup complete", ""), HttpStatus.OK);
451                 }
452         }
453
454         /**
455          * Gets the orchestration requests.
456          *
457          * @param filterString the filter string
458          * @param request the request
459          * @return the orchestration requests
460          * @throws Exception the exception
461          */
462         @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)
463         public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,
464                         HttpServletRequest request) throws Exception {
465
466                 System.err.println("GET ORCHESTRATION REQUESTS: filterString: " + filterString);
467
468                 return new ResponseEntity<String>(getOrchestrationRequestsResponse, HttpStatus.OK);
469
470         }
471
472         /*
473          * General purpose exception handler that could be used in application code.
474          * 
475          * The method returns exceptions as error code 500. Both the exception type
476          * and message are written as a JSON object.
477          * 
478          * See the following references:
479          * 
480          * 1) The ExceptionResponse POJO.
481          * 
482          * 2) The "getHttpErrorMessage" function in "utilityService.js" - an example
483          * of how the browser JavaScript code can interpret this response.
484          */
485
486         /**
487          * Exception.
488          *
489          * @param e the e
490          * @param response the response
491          * @throws IOException Signals that an I/O exception has occurred.
492          */
493         @ExceptionHandler(Exception.class)
494         private void exception(Exception e, HttpServletResponse response) throws IOException {
495
496                 /*
497                  * This logging step should preferably be replaced with an appropriate
498                  * logging method consistent whatever logging mechanism the rest of the
499                  * application code uses.
500                  */
501
502                 e.printStackTrace(System.err);
503
504                 response.setContentType("application/json; charset=UTF-8");
505                 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
506
507                 ExceptionResponse exceptionResponse = new ExceptionResponse();
508                 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
509                 exceptionResponse.setMessage(e.getMessage());
510
511                 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
512
513                 response.flushBuffer();
514
515         }
516
517         /*
518          * 'readAndLogRequest' only intended to be used for testing.
519          * 
520          * The method reads JSON from the input stream and thus prevents other
521          * mechanisms from reading the input.
522          */
523
524         /**
525          * Read and log request.
526          *
527          * @param label the label
528          * @param request the request
529          * @throws Exception the exception
530          */
531         private void readAndLogRequest(String label, HttpServletRequest request) throws Exception {
532                 String input = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
533
534                 ObjectMapper mapper = new ObjectMapper();
535                 Object json = mapper.readValue(input, Object.class);
536
537                 System.err.println(label + "\n" + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
538
539                 /*
540                  * Only needed for error simulation ...
541                  */
542                 if (input.matches("^.*modelName.*$")) {
543                         simulatedError = input.replaceAll("^.*\"modelName\":\"", "").replaceAll("\".*$", "");
544                 }
545         }
546
547         /*
548          * Various test responses:
549          */
550
551         // @formatter:off
552
553         /** The accept response. */
554         /*
555          * Sample responses to initial create / delete transaction
556          */
557         private String acceptResponse =
558            "{" +
559             "  \"status\": 202," +
560             "  \"entity\": {" +
561             "      \"requestReferences\": {" +
562             "         \"instanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\"," +
563             "         \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e331\"" +
564             "      }" +
565             "  }" +
566             "}";
567         
568         /** The policy exception response. */
569         private String policyExceptionResponse = 
570                 "{" + 
571                 "  \"status\": 400," + 
572                 "  \"entity\": { " + 
573                 "    \"requestError\": {" + 
574                 "      \"policyException\": {" + 
575                 "        \"messageId\": \"POL9003\"," + 
576                 "        \"text\": \"Message content size exceeds the allowable limit\"" + 
577                 "      }" + 
578                 "    }" + 
579                 "  }" + 
580                 "}";
581
582         /** The service exception response. */
583         private String serviceExceptionResponse =
584                 "{" + 
585                 "  \"status\": 400," + 
586                 "  \"entity\": { " + 
587                 "    \"requestError\": {" + 
588                 "      \"serviceException\": {" + 
589                 "        \"messageId\": \"SVC2000\"," + 
590                 "        \"text\": \"Missing Parameter: %1. Error code is %2\"," + 
591                 "        \"variables\": [" + 
592                 "          \"severity\"," + 
593                 "          \"400\"" + 
594                 "        ]" + 
595                 "      }" + 
596                 "    }" + 
597                 "  }" + 
598                 "}" + 
599                 "";
600         
601         /** The in progress response. */
602         /*
603          * Sample response to subsequent getOrchestrationRequest
604          */
605         private String inProgressResponse =
606                 "{" +
607                 "   \"status\": 200," +
608                 "   \"entity\": {" +
609                 "      \"request\": {" +
610                 "         \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e333\"," +
611                 "         \"startTime\": \"Thu, 04 Jun 2009 02:51:59 GMT\"," +
612                 "         \"instanceIds\": {" +
613                 "            \"serviceInstanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\"" +
614                 "         }," +
615                 "         \"requestScope\": \"service\"," +
616                 "         \"requestType\": \"createInstance\"," +
617                 "         \"requestDetails\": {" +
618                 "            \"modelInfo\": {" +
619                 "               \"modelType\": \"service\"," +
620                 "               \"modelId\": \"sn5256d1-5a33-55df-13ab-12abad84e764\"," +
621                 "               \"modelNameVersionId\": \"ab6478e4-ea33-3346-ac12-ab121484a333\"," +
622                 "               \"modelName\": \"WanBonding\"," +
623                 "               \"modelVersion\": \"1\"" +
624                 "            }," +
625                 "            \"subscriberInfo\": {" +
626                 "                \"globalSubscriberId\": \"C12345\"," +
627                 "                \"subscriberName\": \"General Electric Division 12\"" +
628                 "            }," +
629                 "            \"requestParameters\": {" +
630                 "               \"vpnId\": \"1a2b3c4d5e6f\"," +
631                 "               \"productName\": \"Trinity\"," +
632                 "               \"customerId\": \"icore9883749\"" +
633                 "            }" +
634                 "         }," +
635                 "         \"requestStatus\": {" +
636                 "            \"timestamp\": \"Thu, 04 Jun 2009 02:53:39 GMT\"," +
637                 "            \"requestState\": \"InProgress\"," +
638                 "            \"statusMessage\": \"vLan setup complete\"," +
639                 "            \"percentProgress\": \"50\"" +
640                 "         }" +
641                 "      }" +
642                 "   }" +
643                 "}";
644         
645         /*
646          * Sample response to subsequent getOrchestrationRequests
647          */
648         
649         /** The get orchestration requests response. */
650         private String getOrchestrationRequestsResponse = 
651                 "{" +
652                 "   \"status\": 200," +
653                 "   \"entity\": {" +
654                 "      \"requestList\": [" +
655                 "         {" +
656                 "            \"request\": {" +
657                 "               \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e333\"," +
658                 "               \"startTime\": \"Thu, 04 Jun 2009 02:51:59 GMT\"," +
659                 "               \"finishTime\": \"Thu, 04 Jun 2009 02:55:59 GMT\"," +
660                 "               \"instanceReferences\": {" +
661                 "                  \"serviceInstanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\"" +
662                 "               }," +
663                 "               \"requestScope\": \"service\"," +
664                 "               \"requestType\": \"createInstance\"," +
665                 "               \"requestDetails\": {" +
666                 "                  \"modelInfo\": {" +
667                 "                     \"modelType\": \"service\"," +
668                 "                     \"modelId\": \"sn5256d1-5a33-55df-13ab-12abad84e764\"," +
669                 "                     \"modelNameVersionId\": \"ab6478e4-ea33-3346-ac12-ab121484a333\"," +
670                 "                     \"modelName\": \"WanBonding\"," +
671                 "                     \"modelVersion\": \"1\"" +
672                 "                  }," +
673                 "                  \"subscriberInfo\": {" +
674                 "                      \"globalSubscriberId\": \"C12345\"," +
675                 "                      \"subscriberName\": \"General Electric Division 12\"" +
676                 "                  }," +
677                 "                  \"requestParameters\": {" +
678                 "                     \"vpnId\": \"1a2b3c4d5e6f\"," +
679                 "                     \"productName\": \"Trinity\"," +
680                 "                     \"customerId\": \"icore9883749\"" +
681                 "                  }" +
682                 "               }," +
683                 "               \"requestStatus\": {" +
684                 "                  \"timestamp\": \"Thu, 04 Jun 2009 02:54:49 GMT\"," +
685                 "                  \"requestState\": \"complete\"," +
686                 "                  \"statusMessage\": \"Resource Created\"," +
687                 "                  \"percentProgress\": \"100\"" +
688                 "               }" +
689                 "            }" +
690                 "         }," +
691                 "         {" +
692                 "            \"request\": {" +
693                 "               \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e334\"," +
694                 "               \"startTime\": \"Thu, 04 Jun 2009 03:52:59 GMT\"," +
695                 "               \"instanceReferences\": {" +
696                 "                  \"serviceInstanceId\": \"bc305d54-75b4-431b-adb2-eb6b9e546014\"" +
697                 "               }," +
698                 "               \"requestScope\": \"service\"," +
699                 "               \"requestType\": \"updateInstance\"," +
700                 "               \"requestDetails\": {" +
701                 "                  \"modelInfo\": {" +
702                 "                     \"modelType\": \"service\"," +
703                 "                     \"modelId\": \"sn5256d1-5a33-55df-13ab-12abad84e764\"," +
704                 "                     \"modelNameVersionId\": \"ab6478e4-ea33-3346-ac12-ab121484a333\"," +
705                 "                     \"modelName\": \"WanBonding\"," +
706                 "                     \"modelVersion\": \"1\"" +
707                 "                  }," +
708                 "                  \"subscriberInfo\": {" +
709                 "                      \"globalSubscriberId\": \"C12345\"," +
710                 "                      \"subscriberName\": \"General Electric Division 12\"" +
711                 "                  }," +
712                 "                  \"requestParameters\": {" +
713                 "                     \"vpnId\": \"1a2b3c4d5e70\"," +
714                 "                     \"productName\": \"Trinity\"," +
715                 "                     \"customerId\": \"icore9883749\"" +
716                 "                  }" +
717                 "               }," +
718                 "               \"requestStatus\": {" +
719                 "                  \"timestamp\": \"Thu, 04 Jun 2009 03:53:39 GMT\"," +
720                 "                  \"requestState\": \"InProgress\"," +
721                 "                  \"statusMessage\": \"vLan setup complete\"," +
722                 "                  \"percentProgress\": \"50\"" +
723                 "               }" +
724                 "            }" +
725                 "         }" +
726                 "      ]" +
727                 "   }" +
728                 "}";
729 }