1 package org.openecomp.restclient.client;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertNull;
7 import javax.ws.rs.core.MediaType;
8 import javax.ws.rs.core.MultivaluedMap;
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;
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;
22 public class RestfulClientTest {
24 private RestClientBuilder mockClientBuilder;
25 private Client mockedClient;
28 * Test case initialization
30 * @throws Exception the exception
33 public void init() throws Exception {
34 mockClientBuilder = Mockito.mock( RestClientBuilder.class );
35 mockedClient = Mockito.mock( Client.class );
39 public void validateConstructors() {
41 RestClient restClient = new RestClient();
42 assertNotNull(restClient);
45 restClient = new RestClient( mockClientBuilder );
46 assertNotNull(restClient);
51 public void validateBasicClientConstruction() throws Exception {
53 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
55 RestClient restClient = new RestClient( mockClientBuilder );
56 assertNotNull(restClient);
58 Client client = restClient.authenticationMode(RestAuthenticationMode.HTTP_NOAUTH)
59 .connectTimeoutMs(1000).readTimeoutMs(500).getClient();
61 assertNotNull(client);
66 public void validateClientWithSslBasicAuthConstruction() throws Exception {
68 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
70 RestClient restClient = new RestClient( mockClientBuilder );
71 assertNotNull(restClient);
73 Client client = restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC)
74 .connectTimeoutMs(1000).readTimeoutMs(500).basicAuthPassword("password")
75 .basicAuthUsername("username").getClient();
77 assertNotNull(client);
82 public void validateClientWithSslCertConstruction() throws Exception {
84 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
86 RestClient restClient = new RestClient( mockClientBuilder );
87 assertNotNull(restClient);
90 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
91 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password").getClient();
93 assertNotNull(client);
96 client = restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
97 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password")
98 .validateServerCertChain(true).validateServerHostname(true).getClient();
100 assertNotNull(client);
103 client = restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
104 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password")
105 .trustStore("truststore").getClient();
107 assertNotNull(client);
112 public void validateSuccessfulPut() throws Exception {
114 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
116 WebResource mockedWebResource = Mockito.mock(WebResource.class);
117 Builder mockedBuilder = Mockito.mock(Builder.class);
118 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
125 * Finally the elements we want to validate
128 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
129 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
130 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
132 RestClient restClient = new RestClient( mockClientBuilder );
134 assertNotNull(restClient);
137 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
138 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
140 assertNotNull(restClient);
142 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
144 OperationResult result = restClient.put("http://localhost:9000/aai/v7", "", headers, MediaType.APPLICATION_JSON_TYPE,
145 MediaType.APPLICATION_JSON_TYPE);
147 assertEquals(200, result.getResultCode());
148 assertNotNull(result.getResult());
149 assertNull(result.getFailureCause());
154 public void validateSuccessfulPost() throws Exception {
156 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
158 WebResource mockedWebResource = Mockito.mock(WebResource.class);
159 Builder mockedBuilder = Mockito.mock(Builder.class);
160 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
167 * Finally the elements we want to validate
170 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
171 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
172 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
174 RestClient restClient = new RestClient( mockClientBuilder );
176 assertNotNull(restClient);
179 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
180 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
182 assertNotNull(restClient);
184 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
186 OperationResult result = restClient.post("http://localhost:9000/aai/v7", "", headers, MediaType.APPLICATION_JSON_TYPE,
187 MediaType.APPLICATION_JSON_TYPE);
189 assertEquals(200, result.getResultCode());
190 assertNotNull(result.getResult());
191 assertNull(result.getFailureCause());
196 public void validateSuccessfulGet() throws Exception {
198 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
200 WebResource mockedWebResource = Mockito.mock(WebResource.class);
201 Builder mockedBuilder = Mockito.mock(Builder.class);
202 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
209 * Finally the elements we want to validate
212 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
213 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
214 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
216 RestClient restClient = new RestClient( mockClientBuilder );
218 assertNotNull(restClient);
221 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
222 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
224 assertNotNull(restClient);
226 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
228 OperationResult result =
229 restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
231 assertEquals(200, result.getResultCode());
232 assertNotNull(result.getResult());
233 assertNull(result.getFailureCause());
238 public void validateSuccessfulGetWithBasicAuth() throws Exception {
240 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
242 WebResource mockedWebResource = Mockito.mock(WebResource.class);
243 Builder mockedBuilder = Mockito.mock(Builder.class);
244 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
251 * Finally the elements we want to validate
254 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
255 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
256 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
258 RestClient restClient = new RestClient( mockClientBuilder );
260 assertNotNull(restClient);
263 restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC).connectTimeoutMs(1000)
264 .readTimeoutMs(500).basicAuthUsername("username").basicAuthUsername("password");
266 assertNotNull(restClient);
268 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
270 OperationResult result =
271 restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
273 assertEquals(200, result.getResultCode());
274 assertNotNull(result.getResult());
275 assertNull(result.getFailureCause());
280 public void validateResourceNotFoundGet() throws Exception {
282 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
284 WebResource mockedWebResource = Mockito.mock(WebResource.class);
285 Builder mockedBuilder = Mockito.mock(Builder.class);
286 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
293 * Finally the elements we want to validate
296 Mockito.when(mockedClientResponse.getStatus()).thenReturn(404);
297 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("RNF");
298 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
300 RestClient restClient = new RestClient( mockClientBuilder );
302 assertNotNull(restClient);
305 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
306 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
308 assertNotNull(restClient);
310 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
312 OperationResult result =
313 restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
315 assertEquals(404, result.getResultCode());
316 assertNull(result.getResult());
317 assertNotNull(result.getFailureCause());
322 public void validateHealthCheck() throws Exception {
324 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
326 WebResource mockedWebResource = Mockito.mock(WebResource.class);
327 Builder mockedBuilder = Mockito.mock(Builder.class);
328 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
335 * Finally the elements we want to validate
338 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
339 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
340 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
342 RestClient restClient = new RestClient( mockClientBuilder );
344 assertNotNull(restClient);
347 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
348 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
350 assertNotNull(restClient);
352 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
354 boolean targetServiceHealthy =
355 restClient.healthCheck("http://localhost:9000/aai/util/echo", "startSerice", "targetService");
357 assertEquals(true, targetServiceHealthy);
362 public void validateHealthCheckFailureWith403() throws Exception {
364 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
366 WebResource mockedWebResource = Mockito.mock(WebResource.class);
367 Builder mockedBuilder = Mockito.mock(Builder.class);
368 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
375 * Finally the elements we want to validate
378 Mockito.when(mockedClientResponse.getStatus()).thenReturn(403);
379 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
380 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
382 RestClient restClient = new RestClient( mockClientBuilder );
384 assertNotNull(restClient);
387 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
388 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
390 assertNotNull(restClient);
392 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
394 boolean targetServiceHealthy =
395 restClient.healthCheck("http://localhost:9000/aai/util/echo", "startSerice", "targetService");
397 assertEquals(false, targetServiceHealthy);
402 public void validateHealthCheckFailureWithThrownException() throws Exception {
404 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
406 WebResource mockedWebResource = Mockito.mock(WebResource.class);
407 Builder mockedBuilder = Mockito.mock(Builder.class);
408 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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"));
415 * Finally the elements we want to validate
418 /* Mockito.when(mockedClientResponse.getStatus()).thenReturn(403);
419 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
420 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());*/
422 RestClient restClient = new RestClient( mockClientBuilder );
424 assertNotNull(restClient);
427 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
428 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
430 assertNotNull(restClient);
432 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
434 boolean targetServiceHealthy =
435 restClient.healthCheck("http://localhost:9000/aai/util/echo", "startSerice", "targetService");
437 assertEquals(false, targetServiceHealthy);
441 public void validateSuccessfulGetWithRetries() throws Exception {
443 RestClientBuilder myClientBuilder = Mockito.mock(RestClientBuilder.class);
444 Client myClient = Mockito.mock(Client.class);
446 Mockito.when(myClientBuilder.getClient()).thenReturn(myClient).thenReturn(myClient);
448 WebResource mockedWebResource = Mockito.mock(WebResource.class);
449 Builder mockedBuilder = Mockito.mock(Builder.class);
450 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
458 * Finally the elements we want to validate
461 Mockito.when(mockedClientResponse.getStatus()).thenReturn(408).thenReturn(200);
463 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("error").thenReturn("ok");
465 MultivaluedMap<String, String> emptyHeaderMap = new MultivaluedMapImpl();
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);
471 RestClient restClient = new RestClient( myClientBuilder );
473 assertNotNull(restClient);
476 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
477 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
479 assertNotNull(restClient);
481 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
483 OperationResult result =
484 restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE, 3);
486 assertEquals(200, result.getResultCode());
487 assertNotNull(result.getResult());
488 assertNull(result.getFailureCause());
494 public void validateFailedGetWithRetriesCausedByResourceNotFound() throws Exception {
496 RestClientBuilder myClientBuilder = Mockito.mock(RestClientBuilder.class);
497 Client myClient = Mockito.mock(Client.class);
499 Mockito.when(myClientBuilder.getClient()).thenReturn(myClient).thenReturn(myClient);
501 WebResource mockedWebResource = Mockito.mock(WebResource.class);
502 Builder mockedBuilder = Mockito.mock(Builder.class);
503 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
511 * Finally the elements we want to validate
514 Mockito.when(mockedClientResponse.getStatus()).thenReturn(404);
516 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("error").thenReturn("ok");
518 MultivaluedMap<String, String> emptyHeaderMap = new MultivaluedMapImpl();
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);
524 RestClient restClient = new RestClient( myClientBuilder );
526 assertNotNull(restClient);
529 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
530 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
532 assertNotNull(restClient);
534 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
536 OperationResult result =
537 restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE, 3);
539 assertEquals(404, result.getResultCode());
540 assertNull(result.getResult());
541 assertNotNull(result.getFailureCause());
546 public void validateFailedGetAfterMaxRetries() throws Exception {
548 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
550 WebResource mockedWebResource = Mockito.mock(WebResource.class);
551 Builder mockedBuilder = Mockito.mock(Builder.class);
552 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
554 Mockito.when( mockedClient.resource(Mockito.anyString())).thenReturn( mockedWebResource );
555 Mockito.when(mockedWebResource.accept(Mockito.<MediaType>anyVararg())).thenReturn( mockedBuilder );
557 Mockito.when(mockedBuilder.get(Mockito.any(Class.class))).thenReturn(null);
560 * Finally the elements we want to validate
563 Mockito.when(mockedClientResponse.getStatus()).thenReturn(500).thenReturn(500).thenReturn(500);
565 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("error")
566 .thenReturn("error").thenReturn("error");
568 MultivaluedMap<String, String> emptyHeaderMap = new MultivaluedMapImpl();
570 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(emptyHeaderMap)
571 .thenReturn(emptyHeaderMap).thenReturn(emptyHeaderMap);
573 RestClient restClient = new RestClient( mockClientBuilder );
575 assertNotNull(restClient);
578 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
579 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
581 assertNotNull(restClient);
583 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
585 OperationResult result =
586 restClient.get("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE, 3);
589 assertEquals(504, result.getResultCode());
590 assertNull(result.getResult());
591 assertNotNull(result.getFailureCause());
596 public void validateSuccessfulDelete() throws Exception {
598 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
600 WebResource mockedWebResource = Mockito.mock(WebResource.class);
601 Builder mockedBuilder = Mockito.mock(Builder.class);
602 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
609 * Finally the elements we want to validate
612 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
613 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
614 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
616 RestClient restClient = new RestClient( mockClientBuilder );
618 assertNotNull(restClient);
621 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
622 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
624 assertNotNull(restClient);
626 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
628 OperationResult result = restClient.delete("http://localhost:9000/aai/v7", headers,
629 MediaType.APPLICATION_JSON_TYPE);
631 assertEquals(200, result.getResultCode());
632 assertNotNull(result.getResult());
633 assertNull(result.getFailureCause());
638 public void validateSuccessfulHead() throws Exception {
640 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
642 WebResource mockedWebResource = Mockito.mock(WebResource.class);
643 Builder mockedBuilder = Mockito.mock(Builder.class);
644 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
651 * Finally the elements we want to validate
654 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
655 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
656 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
658 RestClient restClient = new RestClient( mockClientBuilder );
660 assertNotNull(restClient);
663 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
664 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
666 assertNotNull(restClient);
668 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
670 OperationResult result =
671 restClient.head("http://localhost:9000/aai/v7", headers, MediaType.APPLICATION_JSON_TYPE);
673 assertEquals(200, result.getResultCode());
674 assertNotNull(result.getResult());
675 assertNull(result.getFailureCause());
680 public void validateSuccessfulPatch() throws Exception {
682 Mockito.when( mockClientBuilder.getClient() ).thenReturn(mockedClient);
684 WebResource mockedWebResource = Mockito.mock(WebResource.class);
685 Builder mockedBuilder = Mockito.mock(Builder.class);
686 ClientResponse mockedClientResponse = Mockito.mock(ClientResponse.class);
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);
693 * Finally the elements we want to validate
696 Mockito.when(mockedClientResponse.getStatus()).thenReturn(200);
697 Mockito.when(mockedClientResponse.getEntity(String.class)).thenReturn("hello");
698 Mockito.when(mockedClientResponse.getHeaders()).thenReturn(new MultivaluedMapImpl());
700 RestClient restClient = new RestClient( mockClientBuilder );
702 assertNotNull(restClient);
705 restClient.authenticationMode(RestAuthenticationMode.SSL_CERT).connectTimeoutMs(1000)
706 .readTimeoutMs(500).clientCertFile("cert").clientCertPassword("password");
708 assertNotNull(restClient);
710 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
712 OperationResult result = restClient.patch("http://localhost:9000/aai/v7", "", headers, MediaType.APPLICATION_JSON_TYPE,
713 MediaType.APPLICATION_JSON_TYPE);
715 assertEquals(200, result.getResultCode());
716 assertNotNull(result.getResult());
717 assertNull(result.getFailureCause());