Update rest-client with additional operations
[aai/rest-client.git] / src / test / java / org / openecomp / restclient / client / RestfulClientTest.java
1 package org.openecomp.restclient.client;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertNull;
6
7 import javax.ws.rs.core.MediaType;
8 import javax.ws.rs.core.MultivaluedMap;
9
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.mockito.Mockito;
13 import org.openecomp.restclient.enums.RestAuthenticationMode;
14 import org.openecomp.restclient.rest.RestClientBuilder;
15
16 import com.sun.jersey.api.client.Client;
17 import com.sun.jersey.api.client.ClientResponse;
18 import com.sun.jersey.api.client.WebResource;
19 import com.sun.jersey.api.client.WebResource.Builder;
20 import com.sun.jersey.core.util.MultivaluedMapImpl;
21
22 public class RestfulClientTest {
23
24   private RestClientBuilder mockClientBuilder;
25   private Client mockedClient;
26   
27   /**
28    * Test case initialization
29    * 
30    * @throws Exception the exception
31    */
32   @Before
33   public void init() throws Exception {
34     mockClientBuilder = Mockito.mock( RestClientBuilder.class );
35     mockedClient = Mockito.mock( Client.class );
36   }
37   
38   @Test
39   public void validateConstructors() {
40     
41     RestClient restClient = new RestClient();
42     assertNotNull(restClient);
43     
44     restClient = null;
45     restClient = new RestClient( mockClientBuilder );
46     assertNotNull(restClient);
47     
48   }
49   
50   @Test
51   public void validateBasicClientConstruction() throws Exception {
52     
53     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
54     
55     RestClient restClient = new RestClient( mockClientBuilder );
56     assertNotNull(restClient);
57     
58     Client client = restClient.authenticationMode(RestAuthenticationMode.HTTP_NOAUTH)
59         .connectTimeoutMs(1000).readTimeoutMs(500).getClient();
60    
61     assertNotNull(client);
62     
63   }
64   
65   @Test
66   public void validateClientWithSslBasicAuthConstruction() throws Exception {
67
68     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
69     
70     RestClient restClient = new RestClient( mockClientBuilder );
71     assertNotNull(restClient);
72     
73     Client client = restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC)
74         .connectTimeoutMs(1000).readTimeoutMs(500).basicAuthPassword("password")
75         .basicAuthUsername("username").getClient();
76    
77     assertNotNull(client);
78     
79   }
80   
81   @Test
82   public void validateClientWithSslCertConstruction() throws Exception {
83     
84     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
85     
86     RestClient restClient = new RestClient( mockClientBuilder );
87     assertNotNull(restClient);
88     
89     Client client =
90         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
91             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password").getClient();
92    
93     assertNotNull(client);
94     
95     client = null;
96     client = restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
97         .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password")
98         .validateServerCertChain(true).validateServerHostname(true).getClient();
99
100     assertNotNull(client);
101
102     client = null;
103     client = restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
104         .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password")
105         .trustStore("truststore").getClient();
106
107     assertNotNull(client);
108     
109   }
110   
111   @Test
112   public void validateSuccessfulPut() throws Exception {
113     
114     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
115     
116     WebResource mockedWebResource = Mockito.mock(WebResource.class);
117     Builder mockedBuilder = Mockito.mock(Builder.class);
118     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
119     
120     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
121     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
122     Mockito.when(mockedBuilder.put(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
123
124     /*
125      * Finally the elements we want to validate
126      */
127     
128     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
129     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
130     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
131
132     RestClient restClient = new RestClient( mockClientBuilder );
133     
134     assertNotNull(restClient);
135     
136     restClient =
137         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
138             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
139     
140     assertNotNull(restClient);
141     
142     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
143
144     OperationResult result = restClient.put("http://localhost:9000/aai/v7", "", headers, MediaType.APPLICATION_JSON_TYPE,
145         MediaType.APPLICATION_JSON_TYPE);
146     
147     assertEquals(200, result.getResultCode());
148     assertNotNull(result.getResult());
149     assertNull(result.getFailureCause());
150     
151   }
152   
153   @Test
154   public void validateSuccessfulPost() throws Exception {
155     
156     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
157     
158     WebResource mockedWebResource = Mockito.mock(WebResource.class);
159     Builder mockedBuilder = Mockito.mock(Builder.class);
160     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
161     
162     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
163     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
164     Mockito.when(mockedBuilder.post(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
165
166     /*
167      * Finally the elements we want to validate
168      */
169     
170     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
171     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
172     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
173
174     RestClient restClient = new RestClient( mockClientBuilder );
175     
176     assertNotNull(restClient);
177     
178     restClient =
179         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
180             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
181     
182     assertNotNull(restClient);
183     
184     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
185
186     OperationResult result = restClient.post("http://localhost:9000/aai/v7", "", headers, MediaType.APPLICATION_JSON_TYPE,
187         MediaType.APPLICATION_JSON_TYPE);
188     
189     assertEquals(200, result.getResultCode());
190     assertNotNull(result.getResult());
191     assertNull(result.getFailureCause());
192     
193   }
194   
195   @Test
196   public void validateSuccessfulGet() throws Exception {
197     
198     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
199     
200     WebResource mockedWebResource = Mockito.mock(WebResource.class);
201     Builder mockedBuilder = Mockito.mock(Builder.class);
202     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
203     
204     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
205     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
206     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
207
208     /*
209      * Finally the elements we want to validate
210      */
211     
212     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
213     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
214     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
215
216     RestClient restClient = new RestClient( mockClientBuilder );
217     
218     assertNotNull(restClient);
219     
220     restClient =
221         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
222             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
223     
224     assertNotNull(restClient);
225     
226     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
227
228     OperationResult result =
229         restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
230     
231     assertEquals(200, result.getResultCode());
232     assertNotNull(result.getResult());
233     assertNull(result.getFailureCause());
234     
235   }
236   
237   @Test
238   public void validateSuccessfulGetWithBasicAuth() throws Exception {
239     
240     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
241     
242     WebResource mockedWebResource = Mockito.mock(WebResource.class);
243     Builder mockedBuilder = Mockito.mock(Builder.class);
244     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
245     
246     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
247     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
248     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
249
250     /*
251      * Finally the elements we want to validate
252      */
253     
254     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
255     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
256     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
257
258     RestClient restClient = new RestClient( mockClientBuilder );
259     
260     assertNotNull(restClient);
261     
262     restClient =
263         restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC).connectTimeoutMs(1000)
264             .readTimeoutMs(500).basicAuthUsername("username").basicAuthUsername("password");
265     
266     assertNotNull(restClient);
267     
268     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
269
270     OperationResult result =
271         restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
272     
273     assertEquals(200, result.getResultCode());
274     assertNotNull(result.getResult());
275     assertNull(result.getFailureCause());
276     
277   }
278   
279   @Test
280   public void validateResourceNotFoundGet() throws Exception {
281     
282     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
283     
284     WebResource mockedWebResource = Mockito.mock(WebResource.class);
285     Builder mockedBuilder = Mockito.mock(Builder.class);
286     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
287     
288     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
289     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
290     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
291
292     /*
293      * Finally the elements we want to validate
294      */
295     
296     Mockito.when(mockedClientResponse.getStatus()).thenReturn(404);
297     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("RNF");
298     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
299
300     RestClient restClient = new RestClient( mockClientBuilder );
301     
302     assertNotNull(restClient);
303     
304     restClient =
305         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
306             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
307     
308     assertNotNull(restClient);
309     
310     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
311
312     OperationResult result =
313         restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
314     
315     assertEquals(404, result.getResultCode());
316     assertNull(result.getResult());
317     assertNotNull(result.getFailureCause());
318     
319   }
320   
321   @Test
322   public void validateHealthCheck() throws Exception {
323     
324     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
325     
326     WebResource mockedWebResource = Mockito.mock(WebResource.class);
327     Builder mockedBuilder = Mockito.mock(Builder.class);
328     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
329     
330     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
331     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
332     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
333
334     /*
335      * Finally the elements we want to validate
336      */
337     
338     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
339     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
340     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
341
342     RestClient restClient = new RestClient( mockClientBuilder );
343     
344     assertNotNull(restClient);
345     
346     restClient =
347         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
348             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
349     
350     assertNotNull(restClient);
351     
352     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
353
354     boolean targetServiceHealthy =
355         restClient.healthCheck("http://localhost:9000/aai/util/echo", "startSerice", "targetService");
356     
357     assertEquals(true, targetServiceHealthy);
358     
359   }
360   
361   @Test
362   public void validateHealthCheckFailureWith403() throws Exception {
363     
364     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
365     
366     WebResource mockedWebResource = Mockito.mock(WebResource.class);
367     Builder mockedBuilder = Mockito.mock(Builder.class);
368     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
369     
370     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
371     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
372     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
373
374     /*
375      * Finally the elements we want to validate
376      */
377     
378     Mockito.when(mockedClientResponse.getStatus()).thenReturn(403);
379     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
380     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
381
382     RestClient restClient = new RestClient( mockClientBuilder );
383     
384     assertNotNull(restClient);
385     
386     restClient =
387         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
388             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
389     
390     assertNotNull(restClient);
391     
392     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
393
394     boolean targetServiceHealthy =
395         restClient.healthCheck("http://localhost:9000/aai/util/echo", "startSerice", "targetService");
396     
397     assertEquals(false, targetServiceHealthy);
398     
399   }
400   
401   @Test
402   public void validateHealthCheckFailureWithThrownException() throws Exception {
403
404     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
405     
406     WebResource mockedWebResource = Mockito.mock(WebResource.class);
407     Builder mockedBuilder = Mockito.mock(Builder.class);
408     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
409     
410     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
411     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
412     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenThrow(new IllegalArgumentException("error"));
413
414     /*
415      * Finally the elements we want to validate
416      */
417     
418 /*    Mockito.when(mockedClientResponse.getStatus()).thenReturn(403);
419     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
420     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());*/
421
422     RestClient restClient = new RestClient( mockClientBuilder );
423     
424     assertNotNull(restClient);
425     
426     restClient =
427         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
428             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
429     
430     assertNotNull(restClient);
431     
432     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
433
434     boolean targetServiceHealthy =
435         restClient.healthCheck("http://localhost:9000/aai/util/echo", "startSerice", "targetService");
436     
437     assertEquals(false, targetServiceHealthy);
438     
439   }
440   @Test  
441   public void validateSuccessfulGetWithRetries() throws Exception {
442     
443     RestClientBuilder myClientBuilder = Mockito.mock(RestClientBuilder.class);
444     Client myClient = Mockito.mock(Client.class);
445     
446     Mockito.when(myClientBuilder.getClient()).thenReturn(myClient).thenReturn(myClient);
447     
448     WebResource mockedWebResource = Mockito.mock(WebResource.class);
449     Builder mockedBuilder = Mockito.mock(Builder.class);
450     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
451     
452     Mockito.when( myClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
453     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
454     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
455
456     
457     /*
458      * Finally the elements we want to validate
459      */
460
461     Mockito.when(mockedClientResponse.getStatus()).thenReturn(408).thenReturn(200);
462
463     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("error").thenReturn("ok");
464     
465     MultivaluedMap<String, String> emptyHeaderMap = new MultivaluedMapImpl();
466     
467     // Mockito is smart, the last recorded thenReturn is repeated successively
468     // for all subsequent calls to the method.
469     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(emptyHeaderMap);
470
471     RestClient restClient = new RestClient( myClientBuilder );
472     
473     assertNotNull(restClient);
474     
475     restClient =
476         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
477             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
478     
479     assertNotNull(restClient);
480     
481     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
482
483     OperationResult result =
484         restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE, 3);
485     
486     assertEquals(200, result.getResultCode());
487     assertNotNull(result.getResult());
488     assertNull(result.getFailureCause());
489     
490   }
491   
492   
493   @Test  
494   public void validateFailedGetWithRetriesCausedByResourceNotFound() throws Exception {
495     
496     RestClientBuilder myClientBuilder = Mockito.mock(RestClientBuilder.class);
497     Client myClient = Mockito.mock(Client.class);
498     
499     Mockito.when(myClientBuilder.getClient()).thenReturn(myClient).thenReturn(myClient);
500     
501     WebResource mockedWebResource = Mockito.mock(WebResource.class);
502     Builder mockedBuilder = Mockito.mock(Builder.class);
503     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
504     
505     Mockito.when( myClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
506     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
507     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
508
509     
510     /*
511      * Finally the elements we want to validate
512      */
513
514     Mockito.when(mockedClientResponse.getStatus()).thenReturn(404);
515
516     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("error").thenReturn("ok");
517     
518     MultivaluedMap<String, String> emptyHeaderMap = new MultivaluedMapImpl();
519     
520     // Mockito is smart, the last recorded thenReturn is repeated successively
521     // for all subsequent calls to the method.
522     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(emptyHeaderMap);
523
524     RestClient restClient = new RestClient( myClientBuilder );
525     
526     assertNotNull(restClient);
527     
528     restClient =
529         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
530             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
531     
532     assertNotNull(restClient);
533     
534     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
535
536     OperationResult result =
537         restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE, 3);
538     
539     assertEquals(404, result.getResultCode());
540     assertNull(result.getResult());
541     assertNotNull(result.getFailureCause());
542     
543   }
544   
545   @Test
546   public void validateFailedGetAfterMaxRetries() throws Exception {
547     
548     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
549     
550     WebResource mockedWebResource = Mockito.mock(WebResource.class);
551     Builder mockedBuilder = Mockito.mock(Builder.class);
552     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
553     
554     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
555     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
556     
557     Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(null);
558
559     /*
560      * Finally the elements we want to validate
561      */
562     
563     Mockito.when(mockedClientResponse.getStatus()).thenReturn(500).thenReturn(500).thenReturn(500);
564
565     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("error")
566         .thenReturn("error").thenReturn("error");
567     
568     MultivaluedMap<String, String> emptyHeaderMap = new MultivaluedMapImpl();
569     
570     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(emptyHeaderMap)
571         .thenReturn(emptyHeaderMap).thenReturn(emptyHeaderMap);
572
573     RestClient restClient = new RestClient( mockClientBuilder );
574     
575     assertNotNull(restClient);
576     
577     restClient =
578         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
579             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
580     
581     assertNotNull(restClient);
582     
583     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
584
585     OperationResult result =
586         restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE, 3);
587     
588     
589     assertEquals(504, result.getResultCode());
590     assertNull(result.getResult());
591     assertNotNull(result.getFailureCause());
592     
593   }
594   
595   @Test
596   public void validateSuccessfulDelete() throws Exception {
597     
598     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
599     
600     WebResource mockedWebResource = Mockito.mock(WebResource.class);
601     Builder mockedBuilder = Mockito.mock(Builder.class);
602     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
603     
604     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
605     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
606     Mockito.when(mockedBuilder.delete(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
607
608     /*
609      * Finally the elements we want to validate
610      */
611     
612     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
613     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
614     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
615
616     RestClient restClient = new RestClient( mockClientBuilder );
617     
618     assertNotNull(restClient);
619     
620     restClient =
621         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
622             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
623     
624     assertNotNull(restClient);
625     
626     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
627
628     OperationResult result = restClient.delete("http://localhost:9000/aai/v7", headers, 
629         MediaType.APPLICATION_JSON_TYPE);
630     
631     assertEquals(200, result.getResultCode());
632     assertNotNull(result.getResult());
633     assertNull(result.getFailureCause());
634     
635   }
636   
637   @Test
638   public void validateSuccessfulHead() throws Exception {
639     
640     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
641     
642     WebResource mockedWebResource = Mockito.mock(WebResource.class);
643     Builder mockedBuilder = Mockito.mock(Builder.class);
644     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
645     
646     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
647     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
648     Mockito.when(mockedBuilder.head()).thenReturn(mockedClientResponse);
649
650     /*
651      * Finally the elements we want to validate
652      */
653     
654     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
655     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
656     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
657
658     RestClient restClient = new RestClient( mockClientBuilder );
659     
660     assertNotNull(restClient);
661     
662     restClient =
663         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
664             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
665     
666     assertNotNull(restClient);
667     
668     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
669
670     OperationResult result =
671         restClient.head("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
672     
673     assertEquals(200, result.getResultCode());
674     assertNotNull(result.getResult());
675     assertNull(result.getFailureCause());
676     
677   }
678   
679   @Test
680   public void validateSuccessfulPatch() throws Exception {
681     
682     Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
683     
684     WebResource mockedWebResource = Mockito.mock(WebResource.class);
685     Builder mockedBuilder = Mockito.mock(Builder.class);
686     ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
687     
688     Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
689     Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
690     Mockito.when(mockedBuilder.post(Mockito.any(Class.class))).thenReturn(mockedClientResponse);
691     Mockito.when(mockedBuilder.header("X-HTTP-Method-Override", "PATCH")).thenReturn(mockedBuilder);
692     /*
693      * Finally the elements we want to validate
694      */
695     
696     Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
697     Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
698     Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
699
700     RestClient restClient = new RestClient( mockClientBuilder );
701     
702     assertNotNull(restClient);
703     
704     restClient =
705         restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
706             .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
707     
708     assertNotNull(restClient);
709     
710     MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
711
712     OperationResult result = restClient.patch("http://localhost:9000/aai/v7", "", headers, MediaType.APPLICATION_JSON_TYPE,
713         MediaType.APPLICATION_JSON_TYPE);
714     
715     assertEquals(200, result.getResultCode());
716     assertNotNull(result.getResult());
717     assertNull(result.getFailureCause());
718     
719   }
720     
721 }