76025f3af859c227d03b08e001322b62b7349e73
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / common / restclient / TestHttpRest.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21
22 import java.io.IOException;
23 import java.lang.reflect.Field;
24
25 import org.eclipse.jetty.client.HttpClient;
26 import org.eclipse.jetty.client.HttpExchange;
27 import org.junit.After;
28 import org.junit.AfterClass;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.junit.runner.RunWith;
36
37 import mockit.Mock;
38 import mockit.MockUp;
39 import mockit.integration.junit4.JMockit;
40
41 /**
42  * <br/>
43  * <p>
44  * </p>
45  * 
46  * @author
47  * @version
48  */
49 @RunWith(JMockit.class)
50 public class TestHttpRest {
51
52     @Rule
53     public ExpectedException thrown = ExpectedException.none();
54
55     /**
56      * <br/>
57      * 
58      * @throws java.lang.Exception
59      * @since
60      */
61     @BeforeClass
62     public static void setUpBeforeClass() throws Exception {
63     }
64
65     /**
66      * <br/>
67      * 
68      * @throws java.lang.Exception
69      * @since
70      */
71     @AfterClass
72     public static void tearDownAfterClass() throws Exception {
73     }
74
75     /**
76      * <br/>
77      * 
78      * @throws java.lang.Exception
79      * @since
80      */
81     @Before
82     public void setUp() throws Exception {
83     }
84
85     /**
86      * <br/>
87      * 
88      * @throws java.lang.Exception
89      * @since
90      */
91     @After
92     public void tearDown() throws Exception {
93     }
94
95     /**
96      * <br/>
97      * 
98      * @throws Exception
99      * @since
100      */
101     @Test
102     public void testInitHttpRest() throws Exception {
103         final RestfulOptions options = new RestfulOptions();
104         new MockUp<HttpClient>() {
105
106             @Mock
107             public void doStart() {
108             }
109         };
110         final HttpRest httpRest = new HttpRest();
111         httpRest.initHttpRest(options);
112         final Field httpClient = HttpBaseRest.class.getDeclaredField("client");
113         httpClient.setAccessible(true);
114         Assert.assertNotNull(httpClient.get(httpRest));
115     }
116
117     /**
118      * <br/>
119      * 
120      * @throws NoSuchFieldException
121      * @throws Exception
122      * @since
123      */
124     @Test
125     public void testCreateRestHttpContentExchange() throws NoSuchFieldException, Exception {
126         final HttpBaseRest httpRest = new HttpRest();
127         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
128
129             @Override
130             public void callback(final RestfulResponse response) {
131
132             }
133
134             @Override
135             public void handleExcepion(final Throwable e) {
136
137             }
138
139         };
140         final RestHttpContentExchange exchange = httpRest.createRestHttpContentExchange(callback);
141         assertNotNull(exchange);
142         final Field callbackField = RestHttpContentExchange.class.getDeclaredField("callback");
143         assertNotNull(callbackField);
144     }
145
146     /**
147      * <br/>
148      * 
149      * @throws Exception
150      * @since
151      */
152     @Test
153     public void testGetStringRestfulParametes() throws Exception {
154         final RestfulOptions options = new RestfulOptions();
155
156         final HttpRest httpRest = getHttpRest(options);
157         new MockUp<RestHttpContentExchange>() {
158
159             @Mock
160             public int waitForDone() {
161                 return HttpExchange.STATUS_COMPLETED;
162             }
163
164             @Mock
165             public RestfulResponse getResponse() throws IOException {
166                 final RestfulResponse response = new RestfulResponse();
167                 response.setStatus(HttpExchange.STATUS_COMPLETED);
168                 return response;
169             }
170
171         };
172         final RestfulParametes parametes = new RestfulParametes();
173         parametes.put("id", "1234");
174         parametes.put("name", "some-name");
175         parametes.put("address", null);
176         parametes.putHttpContextHeader("Content-Type", "application/json");
177         parametes.putHttpContextHeader("Accept-Encoding", "*/*");
178         final RestfulResponse response = httpRest.get("path/to/service", parametes);
179         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
180
181     }
182
183     /**
184      * <br/>
185      * 
186      * @throws Exception
187      * @since
188      */
189     @Test
190     public void testGetStringRestfulParametesRestfulOptions() throws Exception {
191         final RestfulOptions options = new RestfulOptions();
192
193         final HttpRest httpRest = getHttpRest(options);
194         new MockUp<RestHttpContentExchange>() {
195
196             @Mock
197             public int waitForDone() {
198                 return HttpExchange.STATUS_COMPLETED;
199             }
200
201             @Mock
202             public RestfulResponse getResponse() throws IOException {
203                 final RestfulResponse response = new RestfulResponse();
204                 response.setStatus(HttpExchange.STATUS_COMPLETED);
205                 return response;
206             }
207
208         };
209         final RestfulResponse response = httpRest.get("path/to/service", new RestfulParametes(), options);
210         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
211     }
212
213     /**
214      * <br/>
215      * 
216      * @throws Exception
217      * @since
218      */
219     @Test
220     public void testHeadStringRestfulParametes() throws Exception {
221         final RestfulOptions options = new RestfulOptions();
222
223         final HttpRest httpRest = getHttpRest(options);
224         new MockUp<RestHttpContentExchange>() {
225
226             @Mock
227             public int waitForDone() {
228                 return HttpExchange.STATUS_COMPLETED;
229             }
230
231             @Mock
232             public RestfulResponse getResponse() throws IOException {
233                 final RestfulResponse response = new RestfulResponse();
234                 response.setStatus(HttpExchange.STATUS_COMPLETED);
235                 return response;
236             }
237
238         };
239         final RestfulParametes parametes = new RestfulParametes();
240         parametes.put("id", "1234");
241         parametes.put("name", "some-name");
242         parametes.put("address", null);
243         parametes.putHttpContextHeader("Content-Type", "");
244         parametes.putHttpContextHeader("Accept-Encoding", "");
245         final RestfulResponse response = httpRest.head("path/to/service", parametes);
246         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
247     }
248
249     /**
250      * <br/>
251      * 
252      * @throws Exception
253      * @since
254      */
255     @Test
256     public void testHeadStringRestfulParametesRestfulOptions() throws Exception {
257         final RestfulOptions options = new RestfulOptions();
258
259         final HttpRest httpRest = getHttpRest(options);
260         new MockUp<RestHttpContentExchange>() {
261
262             @Mock
263             public int waitForDone() {
264                 return HttpExchange.STATUS_COMPLETED;
265             }
266
267             @Mock
268             public RestfulResponse getResponse() throws IOException {
269                 final RestfulResponse response = new RestfulResponse();
270                 response.setStatus(HttpExchange.STATUS_COMPLETED);
271                 return response;
272             }
273
274         };
275         final RestfulParametes parametes = new RestfulParametes();
276         parametes.put("id", "1234");
277         parametes.put("name", "some-name");
278         parametes.put("address", null);
279         parametes.putHttpContextHeader("Content-Type", "");
280         parametes.putHttpContextHeader("Accept-Encoding", "");
281         final RestfulResponse response = httpRest.head("path/to/service", parametes, options);
282         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
283     }
284
285     /**
286      * <br/>
287      * 
288      * @param options
289      * @return
290      * @throws ServiceException
291      * @since
292      */
293     private HttpRest getHttpRest(final RestfulOptions options) throws ServiceException {
294         final HttpRest httpRest = new HttpRest();
295         {
296             new MockUp<HttpClient>() {
297
298                 @Mock
299                 public void doStart() {
300                 }
301
302                 @Mock
303                 public void send(final HttpExchange exchange) throws IOException {
304                 }
305             };
306             httpRest.initHttpRest(options);
307
308         }
309         return httpRest;
310     }
311
312     /**
313      * <br/>
314      * 
315      * @throws Exception
316      * @since
317      */
318     @Test
319     public void testAsyncGetStringRestfulParametesRestfulAsyncCallback() throws Exception {
320         final RestfulOptions options = new RestfulOptions();
321
322         final HttpRest httpRest = getHttpRest(options);
323         new MockUp<RestHttpContentExchange>() {
324
325             @Mock
326             public int waitForDone() {
327                 return HttpExchange.STATUS_COMPLETED;
328             }
329
330             @Mock
331             public RestfulResponse getResponse() throws IOException {
332                 final RestfulResponse response = new RestfulResponse();
333                 response.setStatus(HttpExchange.STATUS_COMPLETED);
334                 return response;
335             }
336
337         };
338
339         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
340
341             @Override
342             public void callback(final RestfulResponse response) {
343
344             }
345
346             @Override
347             public void handleExcepion(final Throwable e) {
348
349             }
350
351         };
352         httpRest.asyncGet("path/to/service", new RestfulParametes(), callback);
353         httpRest.asyncGet("path/to/service", new RestfulParametes(), null);
354     }
355
356     /**
357      * <br/>
358      * 
359      * @throws ServiceException
360      * @since
361      */
362     @Test
363     public void testAsyncGetStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
364         final RestfulOptions options = new RestfulOptions();
365
366         final HttpRest httpRest = getHttpRest(options);
367         new MockUp<RestHttpContentExchange>() {
368
369             @Mock
370             public int waitForDone() {
371                 return HttpExchange.STATUS_COMPLETED;
372             }
373
374             @Mock
375             public RestfulResponse getResponse() throws IOException {
376                 final RestfulResponse response = new RestfulResponse();
377                 response.setStatus(HttpExchange.STATUS_COMPLETED);
378                 return response;
379             }
380
381         };
382
383         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
384
385             @Override
386             public void callback(final RestfulResponse response) {
387
388             }
389
390             @Override
391             public void handleExcepion(final Throwable e) {
392
393             }
394
395         };
396         httpRest.asyncGet("path/to/service", new RestfulParametes(), new RestfulOptions(), callback);
397         httpRest.asyncGet("path/to/service", new RestfulParametes(), new RestfulOptions(), null);
398     }
399
400     /**
401      * <br/>
402      * 
403      * @throws ServiceException
404      * @since
405      */
406     @Test
407     public void testPutStringRestfulParametes() throws ServiceException {
408         final RestfulOptions options = new RestfulOptions();
409
410         final HttpRest httpRest = getHttpRest(options);
411         new MockUp<RestHttpContentExchange>() {
412
413             @Mock
414             public int waitForDone() {
415                 return HttpExchange.STATUS_COMPLETED;
416             }
417
418             @Mock
419             public RestfulResponse getResponse() throws IOException {
420                 final RestfulResponse response = new RestfulResponse();
421                 response.setStatus(HttpExchange.STATUS_COMPLETED);
422                 return response;
423             }
424
425         };
426         final RestfulParametes parametes = new RestfulParametes();
427         parametes.put("id", "1234");
428         parametes.put("name", "some-name");
429         parametes.put("address", null);
430         parametes.putHttpContextHeader("Content-Type", "");
431         parametes.putHttpContextHeader("Accept-Encoding", "");
432         final RestfulResponse response = httpRest.put("path/to/service", parametes);
433         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
434     }
435
436     /**
437      * <br/>
438      * 
439      * @throws ServiceException
440      * @since
441      */
442     @Test
443     public void testPutStringRestfulParametesRestfulOptions() throws ServiceException {
444
445         final RestfulOptions options = new RestfulOptions();
446
447         final HttpRest httpRest = getHttpRest(options);
448         new MockUp<RestHttpContentExchange>() {
449
450             @Mock
451             public int waitForDone() {
452                 return HttpExchange.STATUS_COMPLETED;
453             }
454
455             @Mock
456             public RestfulResponse getResponse() throws IOException {
457                 final RestfulResponse response = new RestfulResponse();
458                 response.setStatus(HttpExchange.STATUS_COMPLETED);
459                 return response;
460             }
461
462         };
463         final RestfulParametes parametes = new RestfulParametes();
464         parametes.put("id", "1234");
465         parametes.put("name", "some-name");
466         parametes.put("address", null);
467         parametes.putHttpContextHeader("Content-Type", "");
468         parametes.putHttpContextHeader("Accept-Encoding", "");
469         final RestfulResponse response = httpRest.put("path/to/service", parametes, null);
470         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
471     }
472
473     /**
474      * <br/>
475      * 
476      * @throws ServiceException
477      * @since
478      */
479     @Test
480     public void testAsyncPutStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
481         final RestfulOptions options = new RestfulOptions();
482
483         final HttpRest httpRest = getHttpRest(options);
484         new MockUp<RestHttpContentExchange>() {
485
486             @Mock
487             public int waitForDone() {
488                 return HttpExchange.STATUS_COMPLETED;
489             }
490
491             @Mock
492             public RestfulResponse getResponse() throws IOException {
493                 final RestfulResponse response = new RestfulResponse();
494                 response.setStatus(HttpExchange.STATUS_COMPLETED);
495                 return response;
496             }
497
498         };
499
500         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
501
502             @Override
503             public void callback(final RestfulResponse response) {
504
505             }
506
507             @Override
508             public void handleExcepion(final Throwable e) {
509
510             }
511
512         };
513         httpRest.asyncPut("path/to/service", new RestfulParametes(), callback);
514         httpRest.asyncPut("path/to/service", new RestfulParametes(), null);
515     }
516
517     /**
518      * <br/>
519      * 
520      * @throws Exception
521      * @since
522      */
523     @Test
524     public void testAsyncPutStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws Exception {
525         final RestfulOptions options = new RestfulOptions();
526
527         final HttpRest httpRest = getHttpRest(options);
528         new MockUp<RestHttpContentExchange>() {
529
530             @Mock
531             public int waitForDone() {
532                 return HttpExchange.STATUS_COMPLETED;
533             }
534
535             @Mock
536             public RestfulResponse getResponse() throws IOException {
537                 final RestfulResponse response = new RestfulResponse();
538                 response.setStatus(HttpExchange.STATUS_COMPLETED);
539                 return response;
540             }
541
542         };
543
544         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
545
546             @Override
547             public void callback(final RestfulResponse response) {
548
549             }
550
551             @Override
552             public void handleExcepion(final Throwable e) {
553
554             }
555
556         };
557         httpRest.asyncPut("path/to/service", new RestfulParametes(), new RestfulOptions(), callback);
558         httpRest.asyncPut("path/to/service", new RestfulParametes(), new RestfulOptions(), null);
559     }
560
561     /**
562      * <br/>
563      * 
564      * @throws Exception
565      * @since
566      */
567     @Test
568     public void testAsyncPostStringRestfulParametesRestfulAsyncCallback() throws Exception {
569         final RestfulOptions options = new RestfulOptions();
570         options.setRestTimeout(10);
571
572         final HttpBaseRest httpRest = getHttpRest(options);
573         new MockUp<RestHttpContentExchange>() {
574
575             @Mock
576             public int waitForDone() {
577                 return 99;
578             }
579
580             @Mock
581             public RestfulResponse getResponse() throws IOException {
582                 final RestfulResponse response = new RestfulResponse();
583                 response.setStatus(HttpExchange.STATUS_EXCEPTED);
584                 return response;
585             }
586
587         };
588
589         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
590
591             @Override
592             public void callback(final RestfulResponse response) {
593
594             }
595
596             @Override
597             public void handleExcepion(final Throwable e) {
598
599             }
600
601         };
602         httpRest.asyncPost("path/to/service", new RestfulParametes(), options, callback);
603         httpRest.asyncPost("path/to/service", new RestfulParametes(), options, null);
604     }
605
606     /**
607      * <br/>
608      * 
609      * @throws ServiceException
610      * @since
611      */
612     @Test
613     public void testAsyncPostStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
614         final RestfulOptions options = new RestfulOptions();
615         options.setRestTimeout(10);
616
617         final HttpBaseRest httpRest = getHttpRest(options);
618         new MockUp<RestHttpContentExchange>() {
619
620             @Mock
621             public int waitForDone() {
622                 return HttpExchange.STATUS_COMPLETED;
623             }
624
625             @Mock
626             public RestfulResponse getResponse() throws IOException {
627                 final RestfulResponse response = new RestfulResponse();
628                 response.setStatus(HttpExchange.STATUS_COMPLETED);
629                 return response;
630             }
631
632         };
633
634         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
635
636             @Override
637             public void callback(final RestfulResponse response) {
638
639             }
640
641             @Override
642             public void handleExcepion(final Throwable e) {
643
644             }
645
646         };
647         httpRest.asyncPost("path/to/service", new RestfulParametes(), options, callback);
648         httpRest.asyncPost("path/to/service", new RestfulParametes(), options, null);
649     }
650
651     /**
652      * <br/>
653      * 
654      * @throws ServiceException
655      * @since
656      */
657     @Test
658     public void testDeleteStringRestfulParametes() throws ServiceException {
659         final RestfulOptions options = new RestfulOptions();
660
661         final HttpBaseRest httpRest = getHttpRest(options);
662
663         final RestfulResponse response = httpRest.delete("path/to/service", null);
664         assertEquals(-1, response.getStatus());
665     }
666
667     /**
668      * <br/>
669      * 
670      * @throws ServiceException
671      * @since
672      */
673     @Test
674     public void testDeleteStringRestfulParametesRestfulOptions() throws ServiceException {
675         final RestfulOptions options = new RestfulOptions();
676
677         final HttpBaseRest httpRest = getHttpRest(options);
678         new MockUp<RestHttpContentExchange>() {
679
680             @Mock
681             public int waitForDone() {
682                 return HttpExchange.STATUS_COMPLETED;
683             }
684
685             @Mock
686             public RestfulResponse getResponse() throws IOException {
687                 final RestfulResponse response = new RestfulResponse();
688                 response.setStatus(HttpExchange.STATUS_COMPLETED);
689                 return response;
690             }
691
692         };
693         final RestfulParametes parameters = new RestfulParametes();
694         parameters.put("id", "1234");
695         parameters.put("name", "some-name");
696         parameters.put("address", null);
697         parameters.setRawData("{ \"data\"=\"sample JSON data\"");
698         parameters.putHttpContextHeader("Content-Type", "");
699         parameters.putHttpContextHeader("Accept-Encoding", "");
700         final RestfulResponse response = httpRest.delete("path/to/service", parameters, options);
701         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
702     }
703
704     /**
705      * <br/>
706      * 
707      * @throws ServiceException
708      * @since
709      */
710     @Test
711     public void testAsyncDeleteStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
712         final RestfulOptions options = new RestfulOptions();
713         options.setRestTimeout(10);
714
715         final HttpBaseRest httpRest = getHttpRest(options);
716         new MockUp<RestHttpContentExchange>() {
717
718             @Mock
719             public int waitForDone() {
720                 return HttpExchange.STATUS_COMPLETED;
721             }
722
723             @Mock
724             public RestfulResponse getResponse() throws IOException {
725                 final RestfulResponse response = new RestfulResponse();
726                 response.setStatus(HttpExchange.STATUS_COMPLETED);
727                 return response;
728             }
729
730         };
731
732         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
733
734             @Override
735             public void callback(final RestfulResponse response) {
736
737             }
738
739             @Override
740             public void handleExcepion(final Throwable e) {
741
742             }
743
744         };
745         httpRest.asyncDelete("path/to/service", new RestfulParametes(), callback);
746         httpRest.asyncDelete("path/to/service", new RestfulParametes(), null);
747     }
748
749     /**
750      * <br/>
751      * 
752      * @throws ServiceException
753      * @since
754      */
755     @Test
756     public void testAsyncDeleteStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
757         final RestfulOptions options = new RestfulOptions();
758         options.setRestTimeout(10);
759
760         final HttpBaseRest httpRest = getHttpRest(options);
761         new MockUp<RestHttpContentExchange>() {
762
763             @Mock
764             public int waitForDone() {
765                 return HttpExchange.STATUS_COMPLETED;
766             }
767
768             @Mock
769             public RestfulResponse getResponse() throws IOException {
770                 final RestfulResponse response = new RestfulResponse();
771                 response.setStatus(HttpExchange.STATUS_COMPLETED);
772                 return response;
773             }
774
775         };
776
777         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
778
779             @Override
780             public void callback(final RestfulResponse response) {
781
782             }
783
784             @Override
785             public void handleExcepion(final Throwable e) {
786
787             }
788
789         };
790         httpRest.asyncDelete("path/to/service", new RestfulParametes(), options, callback);
791         httpRest.asyncDelete("path/to/service", new RestfulParametes(), options, null);
792     }
793
794     /**
795      * <br/>
796      * 
797      * @throws ServiceException
798      * @since
799      */
800     @Test
801     public void testPatchStringRestfulParametes() throws ServiceException {
802         final RestfulOptions options = new RestfulOptions();
803
804         final HttpBaseRest httpRest = getHttpRest(options);
805         new MockUp<RestHttpContentExchange>() {
806
807             @Mock
808             public int waitForDone() {
809                 return HttpExchange.STATUS_COMPLETED;
810             }
811
812             @Mock
813             public RestfulResponse getResponse() throws IOException {
814                 final RestfulResponse response = new RestfulResponse();
815                 response.setStatus(HttpExchange.STATUS_COMPLETED);
816                 return response;
817             }
818
819         };
820         final RestfulParametes parameters = new RestfulParametes();
821         parameters.put("id", "1234");
822         parameters.put("name", "some-name");
823         parameters.put("address", null);
824         parameters.setRawData("{ \"data\"=\"sample JSON data\"");
825         parameters.putHttpContextHeader("Content-Type", "");
826         parameters.putHttpContextHeader("Accept-Encoding", "");
827         final RestfulResponse response = httpRest.patch("path/to/service", parameters);
828         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
829     }
830
831     /**
832      * <br/>
833      * 
834      * @throws ServiceException
835      * @since
836      */
837     @Test
838     public void testPatchStringRestfulParametesRestfulOptions() throws ServiceException {
839         final RestfulOptions options = new RestfulOptions();
840
841         final HttpBaseRest httpRest = getHttpRest(options);
842         new MockUp<RestHttpContentExchange>() {
843
844             @Mock
845             public int waitForDone() {
846                 return HttpExchange.STATUS_COMPLETED;
847             }
848
849             @Mock
850             public RestfulResponse getResponse() throws IOException {
851                 final RestfulResponse response = new RestfulResponse();
852                 response.setStatus(HttpExchange.STATUS_COMPLETED);
853                 return response;
854             }
855
856         };
857         final RestfulParametes parameters = new RestfulParametes();
858         parameters.put("id", "1234");
859         parameters.put("name", "some-name");
860         parameters.put("address", null);
861         parameters.setRawData("{ \"data\"=\"sample JSON data\"");
862         parameters.putHttpContextHeader("Content-Type", "");
863         parameters.putHttpContextHeader("Accept-Encoding", "");
864         final RestfulResponse response = httpRest.patch("path/to/service", parameters, options);
865         assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
866     }
867
868     /**
869      * <br/>
870      * 
871      * @throws ServiceException
872      * @since
873      */
874     @Test
875     public void testAsyncPatchStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
876         final RestfulOptions options = new RestfulOptions();
877         options.setRestTimeout(10);
878
879         final HttpBaseRest httpRest = getHttpRest(options);
880         new MockUp<RestHttpContentExchange>() {
881
882             @Mock
883             public int waitForDone() {
884                 return HttpExchange.STATUS_COMPLETED;
885             }
886
887             @Mock
888             public RestfulResponse getResponse() throws IOException {
889                 final RestfulResponse response = new RestfulResponse();
890                 response.setStatus(HttpExchange.STATUS_COMPLETED);
891                 return response;
892             }
893
894         };
895
896         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
897
898             @Override
899             public void callback(final RestfulResponse response) {
900
901             }
902
903             @Override
904             public void handleExcepion(final Throwable e) {
905
906             }
907
908         };
909         httpRest.asyncPatch("path/to/service", new RestfulParametes(), callback);
910         httpRest.asyncPatch("path/to/service", new RestfulParametes(), null);
911     }
912
913     /**
914      * <br/>
915      * 
916      * @throws ServiceException
917      * @since
918      */
919     @Test
920     public void testAsyncPatchStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
921         final RestfulOptions options = new RestfulOptions();
922         options.setRestTimeout(10);
923
924         final HttpBaseRest httpRest = getHttpRest(options);
925         new MockUp<RestHttpContentExchange>() {
926
927             @Mock
928             public int waitForDone() {
929                 return HttpExchange.STATUS_COMPLETED;
930             }
931
932             @Mock
933             public RestfulResponse getResponse() throws IOException {
934                 final RestfulResponse response = new RestfulResponse();
935                 response.setStatus(HttpExchange.STATUS_COMPLETED);
936                 return response;
937             }
938
939         };
940
941         final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
942
943             @Override
944             public void callback(final RestfulResponse response) {
945
946             }
947
948             @Override
949             public void handleExcepion(final Throwable e) {
950
951             }
952
953         };
954         httpRest.asyncPatch("path/to/service", new RestfulParametes(), options, callback);
955         httpRest.asyncPatch("path/to/service", new RestfulParametes(), options, null);
956     }
957
958 }