List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine
public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str)
From source file:com.comcast.video.dawg.house.DawgHouseClientTest.java
@Test public void testDeleteByIdsWithNullIds() throws HttpException { RestClient mockClient = EasyMock.createMock(RestClient.class); DawgHouseClient client = new DawgHouseClient(); client.setClient(mockClient);//from w w w . ja va 2s . co m RestResponse response = new RestResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 200, null)); EasyMock.expect(mockClient.execute((RestRequest) EasyMock.anyObject())).andReturn(response); EasyMock.replay(mockClient); Collection<String> ids = null; try { client.deleteByIds(ids); } catch (Exception e) { Assert.fail("deleteByIds threw " + e); } }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPollTest.java
@Test public void testResponseStatusCodeOf401ThrowsExpectedException() throws Exception { expectedException.expect(LaunchKeyException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())/*from w w w . ja v a 2 s . c o m*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 401, "Expected Message")); transport.poll(new PollRequest(null, 0L, null, null)); }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportUsersTest.java
@Test public void testResponseStatusCodeOf401ThrowsExpectedException() throws Exception { expectedException.expect(LaunchKeyException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())//from ww w . jav a2 s. c o m .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 401, "Expected Message")); transport.users(new UsersRequest(null, 0L, null)); }
From source file:org.sentilo.common.test.rest.RESTClientImplTest.java
@Test public void put() throws Exception { final String path = "/data"; final String body = "body"; final String responseContent = "Lorem ipsum"; final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, ""); when(httpClient.execute(notNull(HttpPut.class))).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(httpResponse.getEntity()).thenReturn(new StringEntity(responseContent)); final String result = restClient.put(path, body); verify(httpClient).execute(any(HttpPut.class)); Assert.assertEquals(responseContent, result); }
From source file:org.finra.dm.tools.common.databridge.DataBridgeWebClientTest.java
@Test public void testGetBusinessObjectData400Throws() throws Exception { int expectedStatusCode = 400; String expectedReasonPhrase = "testReasonPhrase"; String expectedErrorMessage = "testErrorMessage"; ErrorInformation errorInformation = new ErrorInformation(); errorInformation.setStatusCode(expectedStatusCode); errorInformation.setMessage(expectedErrorMessage); errorInformation.setStatusDescription(expectedReasonPhrase); String requestContent = xmlHelper.objectToXml(errorInformation); CloseableHttpResponse httpResponse = new MockCloseableHttpResponse( new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase)); httpResponse.setEntity(new StringEntity(requestContent)); String actionDescription = "testActionDescription"; try {/*from w ww . java2 s.c o m*/ dataBridgeWebClient.getBusinessObjectData(httpResponse, actionDescription); Assert.fail("expected HttpErrorResponseException, but no exception was thrown"); } catch (Exception e) { Assert.assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass()); HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e; Assert.assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage, httpErrorResponseException.getResponseMessage()); Assert.assertEquals("httpErrorResponseException statusCode", expectedStatusCode, httpErrorResponseException.getStatusCode()); Assert.assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase, httpErrorResponseException.getStatusDescription()); Assert.assertEquals("httpErrorResponseException message", "Failed to " + actionDescription, httpErrorResponseException.getMessage()); } }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportLogsTest.java
@Test public void testResponseStatusCodeOf300ThrowsExpectedException() throws Exception { expectedException.expect(CommunicationErrorException.class); expectedException.expectMessage("Expected Message"); when(response.getStatusLine())/*w w w. j a va 2 s. c om*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 300, "Expected Message")); transport.logs(new LogsRequest("Authenticate", true, null, 0L, null, null)); }
From source file:org.wildfly.camel.test.hipchat.HipchatConsumerIntegrationTest.java
@Test public void sendInOnlyMultipleUsers() throws Exception { CamelContext camelctx = createCamelContext(); MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class); result.expectedMessageCount(1);/* ww w. j a v a 2 s. c o m*/ camelctx.start(); try { String expectedResponse = "{\n" // + " \"items\" : [\n" // + " {\n" // + " \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" // + " \"from\" : {\n" // + " \"id\" : 1647095,\n" // + " \"links\" : {\n" // + " \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" // + " },\n" // + " \"mention_name\" : \"notifier\",\n" // + " \"name\" : \"Message Notifier\"\n" // + " },\n" // + " \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" // + " \"mentions\" : [ ],\n" // + " \"message\" : \"Unit test Alert\",\n" // + " \"type\" : \"message\"\n" // + " }\n" // + " ],\n" // + " \"links\" : {\n" // + " \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" // + " },\n" // + " \"maxResults\" : 1,\n" // + " \"startIndex\" : 0\n" // + "}"; HttpEntity mockHttpEntity = mock(HttpEntity.class); when(mockHttpEntity.getContent()) .thenReturn(new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8))); when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity); when(closeableHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "")); result.assertIsSatisfied(); assertCommonResultExchange(result.getExchanges().get(0)); } finally { camelctx.stop(); } }
From source file:org.sentilo.platform.server.test.parser.SubscribeParserTest.java
@Test public void parseEmptyWriteResponse() throws Exception { final SentiloResponse response = SentiloResponse .build(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_0, 200, ""))); final List<Subscription> subscriptionList = Collections.emptyList(); parser.writeResponse(response, subscriptionList); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ((ByteArrayEntity) response.getHttpResponse().getEntity()).writeTo(baos); final String expected = "{\"subscriptions\":[]}"; assertEquals(expected, baos.toString()); }
From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackCore.java
public synchronized HttpResponse createStack(String template, String stackName) throws IOException { HttpClient httpClient = HttpClientBuilder.create().build(); HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpPost createStack = null;// ww w . j a va 2 s .c om HttpResponse response = null; String jsonTemplate = JavaStackUtils.convertYamlToJson(template); JSONObject modifiedObject = new JSONObject(); modifiedObject.put("stack_name", stackName); modifiedObject.put("template", new JSONObject(jsonTemplate)); if (this.isAuthenticated) { StringBuilder buildUrl = new StringBuilder(); buildUrl.append("http://"); buildUrl.append(this.endpoint); buildUrl.append(":"); buildUrl.append(Constants.HEAT_PORT.toString()); buildUrl.append(String.format("/%s/%s/stacks", Constants.HEAT_VERSION.toString(), tenant_id)); // Logger.debug(buildUrl.toString()); createStack = new HttpPost(buildUrl.toString()); createStack.setEntity(new StringEntity(modifiedObject.toString(), ContentType.APPLICATION_JSON)); // Logger.debug(this.token_id); createStack.addHeader(Constants.AUTHTOKEN_HEADER.toString(), this.token_id); Logger.debug("Request: " + createStack.toString()); Logger.debug("Request body: " + modifiedObject.toString()); response = httpClient.execute(createStack); int statusCode = response.getStatusLine().getStatusCode(); String responsePhrase = response.getStatusLine().getReasonPhrase(); Logger.debug("Response: " + response.toString()); Logger.debug("Response body:"); if (statusCode != 201) { BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = null; while ((line = in.readLine()) != null) Logger.debug(line); } return (statusCode == 201) ? response : factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, responsePhrase + ". Create Failed with Status: " + statusCode), null); } else { throw new IOException("You must Authenticate before issuing this request, please re-authenticate. "); } }
From source file:nl.waisda.services.EuropeanaImportServiceTest.java
private HttpResponse mockOverviewHttpResponse(String imageUrl) throws UnsupportedEncodingException { BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(100, 1), 200, null)); response.setEntity(new StringEntity( "{\"apikey\":\"test\",\"action\":\"search.json\",\"success\":true,\"requestNumber\":3713,\"itemsCount\":1,\"totalResults\":1," + "\"items\":[{\n" + " \"id\":\"/08614/6569D2A45FD1CD9ADFB0E5BA54A3BD79C9DAE0BC\",\n" + " \"provider\":[\"EFG - The European Film Gateway\"],\n" + (imageUrl != null ? " \"edmPreview\":[\"" + imageUrl + "\"],\n" : "") + " \"europeanaCompleteness\":0,\n" + " \"year\":[\"1921\"],\n" + " \"rights\":[\"http://www.europeana.eu/rights/rr-f/\"],\n" + " \"title\":[\"Opening Staten Generaal 20-9-1921\",\n" + " \"Opening States General 20-9-1921\"],\n" + " \"type\":\"VIDEO\",\n" + " \"link\":\"http://detail\",\n" + " \"guid\":\"http://preview.europeana.eu/portal/record/08614/6569D2A45FD1CD9ADFB0E5BA54A3BD79C9DAE0BC.html?utm_source=api&utm_medium=api&utm_campaign=XxxsEZoWj\",\n" + " \"dataProvider\":[\"eye Film Instituut Nederland\",\"eye Film Instituut Nederland\"]\n" + "}]}\n")); return response; }