@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 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 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)); }