List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine
public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str)
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportAuthsTest.java
@Test public void testResponseStatusCodeOf500ThrowsExpectedException() throws Exception { expectedException.expect(CommunicationErrorException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())// w w w .j av a 2 s . com .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "Expected Message")); transport.auths(new AuthsRequest(null, 0L, null, null, 0, 0)); }
From source file:com.joyent.manta.http.ApacheHttpGetResponseEntityContentContinuatorTest.java
@Test(expectedExceptions = UnknownHostException.class, expectedExceptionsMessageRegExp = ".*custom fatal exception yo.*") public void rethrowsFatalExceptions() throws Exception { final MantaApacheHttpClientContext connCtx = mock(MantaApacheHttpClientContext.class); when(connCtx.getHttpClient()).thenReturn(mock(CloseableHttpClient.class)); final HttpGet request = new HttpGet(); final HttpResponse response = prepareResponseWithHeaders(unmodifiableMap(ETAG, singleValueHeaderList(ETAG, "a"), CONTENT_LENGTH, singleValueHeaderList(CONTENT_LENGTH, "1"))); when(response.getStatusLine())/*w w w. j a va 2 s. c o m*/ .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, SC_PARTIAL_CONTENT, "")); final HttpDownloadContinuationMarker marker = HttpDownloadContinuationMarker.validateInitialExchange( extractDownloadRequestFingerprint(request), SC_OK, extractDownloadResponseFingerprint(response, true)); new ApacheHttpGetResponseEntityContentContinuator(connCtx, request, marker, INFINITE_CONTINUATIONS) .buildContinuation(new UnknownHostException("custom fatal exception yo"), 0); }
From source file:com.betfair.cougar.client.HttpClientExecutableTest.java
@Test public void testNullResponseFromServer() throws IOException { generateEV(tsd, null);/*from w ww .java 2s . c o m*/ HttpUriRequest mockMethod = mock(HttpUriRequest.class); final HttpResponse httpResponse = mock(HttpResponse.class); when(httpResponse.getEntity()).thenReturn(null); when(mockHttpClient.execute(any(HttpUriRequest.class))).thenReturn(httpResponse); when(mockMethodFactory.create(anyString(), anyString(), any(Message.class), any(Marshaller.class), anyString(), any(ClientCallContext.class), any(TimeConstraints.class))).thenReturn(mockMethod); when(mockedHttpErrorTransformer.convert(any(InputStream.class), any(ExceptionFactory.class), anyInt())) .thenReturn(new CougarClientException(ServerFaultCode.RemoteCougarCommunicationFailure, "bang")); HttpParams mockParams = mock(HttpParams.class); when(mockMethod.getParams()).thenReturn(mockParams); final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpServletResponse.SC_OK, ""); when(httpResponse.getStatusLine()).thenReturn(statusLine); ExecutionObserver mockedObserver = mock(ExecutionObserver.class); client.execute(createEC(null, null, false), TestServiceDefinition.TEST_MIXED, new Object[] { TEST_TEXT, TEST_TEXT }, mockedObserver, ev, DefaultTimeConstraints.NO_CONSTRAINTS); ArgumentCaptor<ExecutionResult> resultCaptor = ArgumentCaptor.forClass(ExecutionResult.class); verify(mockedObserver).onResult(resultCaptor.capture()); ExecutionResult actual = resultCaptor.getValue(); assertEquals(actual.getFault().getServerFaultCode(), ServerFaultCode.RemoteCougarCommunicationFailure); assertEquals(actual.getFault().getResponseCode(), ResponseCode.ServiceUnavailable); assertEquals(0, ((ClientExecutionResult) actual).getResultSize()); }
From source file:com.amazonaws.http.AmazonHttpClientRequestTimeoutTest.java
private HttpResponseProxy createHttpResponseProxySpy() throws IOException { ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); BasicStatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "mock response"); BasicHttpResponse response = new BasicHttpResponse(statusLine); HttpResponseProxy responseProxy = spy(new HttpResponseProxy(response)); doReturn(new StringEntity("mock response body")).when(responseProxy).getEntity(); return responseProxy; }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportAuthsTest.java
@Test public void testResponseStatusCodeOf400ReturnsBodyErrorValues() throws Exception { when(response.getStatusLine())/* w w w .j a v a 2 s . c o m*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Status Message")); when(response.getEntity()) .thenReturn(EntityBuilder.create() .setStream(new ByteArrayInputStream( "{\"message_code\": 60401, \"message\": \"Expected Message\"}".getBytes("UTF-8"))) .build()); expectedException.expect(InvalidRequestException.class); expectedException.expectMessage("Expected Message"); transport.auths(new AuthsRequest(null, 0L, null, null, 0, 0)); }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPollTest.java
@Test public void testResponseStatusCodeOf400ReturnsHttpValuesWhenBodyNotParseable() throws Exception { expectedException.expect(CommunicationErrorException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())/*ww w . j a v a 2s .c om*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Expected Message")); when(response.getEntity()).thenReturn(EntityBuilder.create() .setStream(new ByteArrayInputStream("Unparseable".getBytes("UTF-8"))).build()); transport.poll(new PollRequest(null, 0L, null, null)); }
From source file:org.sentilo.platform.server.test.parser.DataParserTest.java
@Test public void parseEmptyProviderWriteResponse() throws Exception { final String[] parts = { "prov1" }; when(resource.getParts()).thenReturn(parts); final List<Observation> subscriptionList = Collections.emptyList(); final SentiloResponse response = SentiloResponse .build(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_0, 200, ""))); parser.writeResponse(sentiloRequest, response, subscriptionList); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ((ByteArrayEntity) response.getHttpResponse().getEntity()).writeTo(baos); final String expected = "{\"sensors\":[]}"; assertEquals(expected, baos.toString()); }
From source file:org.onebusaway.siri.core.SiriClientTest.java
private HttpResponse createResponse() { BasicStatusLine line = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""); return new BasicHttpResponse(line); }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportLogsTest.java
@Test public void testResponseStatusCodeOf400ReturnsHttpValuesWhenBodyNotParseable() throws Exception { expectedException.expect(CommunicationErrorException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())//from www .ja v a 2 s . c o m .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Expected Message")); when(response.getEntity()).thenReturn(EntityBuilder.create() .setStream(new ByteArrayInputStream("Unparseable".getBytes("UTF-8"))).build()); transport.logs(new LogsRequest("Authenticate", true, null, 0L, null, null)); }
From source file:org.apache.hadoop.gateway.rm.dispatch.RMHaDispatchTest.java
private StatusLine getStatusLine() { ProtocolVersion p = new ProtocolVersion("HTTP", 1, 1); return new BasicStatusLine(p, 307, "Code" + 307); }