@Test public void executeShouldOrchestrateCallsToChannelFactoryWithValuesFromGivenEntityLessRequest() throws Exception { Request request = mock(Request.class); HttpResponse httpResponse= mock(HttpResponse.class); HttpChannel.Response response= mock(HttpChannel.Response.class); HttpChannelResponseHttpResource httpChannelResponseHttpResource = mock(HttpChannelResponseHttpResource.class); MethodConfig methodConfig = mock(MethodConfig.class); Iterator<EncodedPair> headers = asList( Pairs.toPreEncodedPair("h1", "v1"), Pairs.toPreEncodedPair("h2", "v2") ).iterator(); Iterator<EncodedPair> cookies = asList( Pairs.toPreEncodedPair("Cookie", "c1=v1"), Pairs.toPreEncodedPair("Cookie", "c2=v2") ).iterator(); mockStatic(HttpRequests.class); when(HttpRequests.toUrl(request)).thenReturn("some-url"); when(request.getMethodConfig()).thenReturn(methodConfig); when(methodConfig.getCharset()).thenReturn(UTF8); when(methodConfig.getType()).thenReturn(MethodType.GET); when(methodConfig.getConnectionTimeout()).thenReturn(10); when(methodConfig.getSocketTimeout()).thenReturn(11); when(methodConfig.getProduces()).thenReturn("produces"); when(methodConfig.getConsumes()).thenReturn(new String[]{"consumes1","consumes2"}); when(mockChannelFactory.open(MethodType.GET, "some-url", UTF8)).thenReturn(mockChannel); when(request.getEncodedParamsIterator(ParamType.HEADER)).thenReturn(headers); when(request.getEncodedParamsIterator(ParamType.COOKIE)).thenReturn(cookies); when(mockChannel.send()).thenReturn(response); whenNew(HttpChannelResponseHttpResource.class).withArguments(response).thenReturn(httpChannelResponseHttpResource); whenNew(HttpResponse.class).withArguments( mockBaseResponseDeserializer, mockCustomTypeResponseDeserializer, request, httpChannelResponseHttpResource ).thenReturn(httpResponse); assertSame(httpResponse, toTest.execute(request)); InOrder inOrder = inOrder(mockChannel); inOrder.verify(mockChannel).setConnectionTimeout(10); inOrder.verify(mockChannel).setSocketTimeout(11); inOrder.verify(mockChannel).setContentType("produces"); inOrder.verify(mockChannel).setAccept("consumes1,consumes2"); inOrder.verify(mockChannel).addHeader("h1", "v1"); inOrder.verify(mockChannel).addHeader("h2", "v2"); inOrder.verify(mockChannel).addHeader("Cookie", "c1=v1"); inOrder.verify(mockChannel).addHeader("Cookie", "c2=v2"); inOrder.verify(mockChannel).send(); verifyNoMoreInteractions(mockChannel); }
public Response execute(Request request) throws Exception { try { return doExecute(request); }catch(IOException e){ throw new RequestException(e); } }
HttpRequestExecutor implements RequestExecutor, Disposable { public Response execute(Request request) throws Exception { try { return doExecute(request); }catch(IOException e){ throw new RequestException(e); } } }
HttpRequestExecutor implements RequestExecutor, Disposable { public Response execute(Request request) throws Exception { try { return doExecute(request); }catch(IOException e){ throw new RequestException(e); } } HttpRequestExecutor(HttpChannelFactory channelFactory, ResponseDeserializer baseResponseDeserializer, ResponseDeserializer customTypeResponseDeserializer); }
HttpRequestExecutor implements RequestExecutor, Disposable { public Response execute(Request request) throws Exception { try { return doExecute(request); }catch(IOException e){ throw new RequestException(e); } } HttpRequestExecutor(HttpChannelFactory channelFactory, ResponseDeserializer baseResponseDeserializer, ResponseDeserializer customTypeResponseDeserializer); Response execute(Request request); void dispose(); }
HttpRequestExecutor implements RequestExecutor, Disposable { public Response execute(Request request) throws Exception { try { return doExecute(request); }catch(IOException e){ throw new RequestException(e); } } HttpRequestExecutor(HttpChannelFactory channelFactory, ResponseDeserializer baseResponseDeserializer, ResponseDeserializer customTypeResponseDeserializer); Response execute(Request request); void dispose();  }