@Test public void testExecuteRequest() throws Exception { when(mockResponse.getStatusLine()).thenReturn(HTTP_200_REPSONSE); doReturn(mockResponse).when(httpClient).execute(any(HttpHost.class), HttpRequestMatcher.eq(request), any(HttpClientContext.class)); final BasicRestClient restClient = BasicRestClient.create() .host(LOCALHOST) .client(httpClient) .build(); final CloseableHttpResponse response = restClient.execute(request); assertThat(response, notNullValue()); assertThat(response, sameInstance(mockResponse)); assertThat(response.getStatusLine(), sameInstance(HTTP_200_REPSONSE)); }
@Test public void testExecuteRequestStatusCodeIsNotOk() throws Exception { when(mockResponse.getStatusLine()).thenReturn(HTTP_503_STATUSLINE); doReturn(mockResponse).when(httpClient).execute(any(HttpHost.class), HttpRequestMatcher.eq(request), any(HttpClientContext.class)); final BasicRestClient restClient = BasicRestClient.create() .host(LOCALHOST) .client(httpClient) .build(); final CloseableHttpResponse response = restClient.execute(request); assertThat(response, notNullValue()); assertThat(response, sameInstance(mockResponse)); assertThat(response.getStatusLine(), sameInstance(HTTP_503_STATUSLINE)); }
@Test(expected = CloudstackRESTException.class) public void testExecuteRequestWhenClientThrowsIOException() throws Exception { final BasicRestClient restClient = BasicRestClient.create() .host(LOCALHOST) .client(HttpClientHelper.createHttpClient(5)) .build(); final CloseableHttpResponse response = restClient.execute(request); fail("A CloudstackRESTException should have been thrown by now."+ "\nWe got " + response.getStatusLine() + "\nMake sure you cannot reach '" + request.getURI() + "' by method " + request.getMethod()); }
@Test public void testExecuteRequest() throws Exception { when(mockResponse.getStatusLine()).thenReturn(HTTP_200_REPSONSE); doReturn(mockResponse).when(httpClient).execute(any(HttpHost.class), HttpRequestMatcher.eq(request), any(HttpClientContext.class)); final BasicRestClient restClient = BasicRestClient.create() .host(LOCALHOST) .client(httpClient) .build(); final CloseableHttpResponse response = restClient.execute(request); assertThat(response, notNullValue()); assertThat(response, sameInstance(mockResponse)); assertThat(response.getStatusLine(), sameInstance(HTTP_200_REPSONSE)); }
@Test public void testExecuteRequestStatusCodeIsNotOk() throws Exception { when(mockResponse.getStatusLine()).thenReturn(HTTP_503_STATUSLINE); doReturn(mockResponse).when(httpClient).execute(any(HttpHost.class), HttpRequestMatcher.eq(request), any(HttpClientContext.class)); final BasicRestClient restClient = BasicRestClient.create() .host(LOCALHOST) .client(httpClient) .build(); final CloseableHttpResponse response = restClient.execute(request); assertThat(response, notNullValue()); assertThat(response, sameInstance(mockResponse)); assertThat(response.getStatusLine(), sameInstance(HTTP_503_STATUSLINE)); }
@Test(expected = CosmicRESTException.class) public void testExecuteRequestWhenClientThrowsIOException() throws Exception { final BasicRestClient restClient = BasicRestClient.create() .host(LOCALHOST) .client(HttpClientHelper.createHttpClient(5)) .build(); final CloseableHttpResponse response = restClient.execute(request); fail("A CloudstackRESTException should have been thrown by now." + "\nWe got " + response.getStatusLine() + "\nMake sure you cannot reach '" + request.getURI() + "' by method " + request.getMethod()); } }