List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine
public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str)
From source file:co.cask.cdap.client.rest.RestClientTest.java
@Test public void testNotFoundResponseCodeAnalysis() { StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_NOT_FOUND, "Not Found"); when(response.getStatusLine()).thenReturn(statusLine); TestUtils.verifyResponse(HttpStatus.SC_NOT_FOUND, response); verify(response).getStatusLine();/*from w w w. j a v a 2s .c o m*/ }
From source file:com.thoughtworks.go.agent.service.TokenRequesterTest.java
@Test public void shouldGetTokenFromServer() throws Exception { final ArgumentCaptor<HttpRequestBase> argumentCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); final CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); when(agentRegistry.uuid()).thenReturn("agent-uuid"); when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse); when(httpResponse.getEntity()).thenReturn(new StringEntity("token-from-server")); when(httpResponse.getStatusLine())/*from w w w . j a v a 2 s.c om*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), SC_OK, null)); final String token = tokenRequester.getToken(); verify(httpClient).execute(argumentCaptor.capture()); final HttpRequestBase requestBase = argumentCaptor.getValue(); final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(requestBase.getURI(), StandardCharsets.UTF_8.name()); assertThat(token, is("token-from-server")); assertThat(findParam(nameValuePairs, "uuid").getValue(), is("agent-uuid")); }
From source file:lh.api.showcase.server.util.HttpQueryUtilsTest.java
@Test(expected = HttpErrorResponseException.class) public void shouldThrowWhenFailToRefreshToken() throws ClientProtocolException, IOException, HttpErrorResponseException { Mockito.when(responseMock.getStatusLine()) .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "Unauthorized")); Mockito.when(entityMock.getContent()) .thenReturn(this.getClass().getResource("/empty_response.txt").openStream()); Mockito.when(apiAuthMock.updateAccessToken()).thenReturn(false); try {//from ww w. j a va 2 s .c om HttpQueryUtils.executeQuery(uri, apiAuthMock, null, new HttpClientFactoryTestImpl(), 1); } finally { Mockito.verify(apiAuthMock, Mockito.times(1)).updateAccessToken(); } }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportUsersTest.java
@Before public void setUp() throws Exception { httpClient = mock(HttpClient.class); response = mock(HttpResponse.class); crypto = mock(Crypto.class); when(response.getStatusLine())//from w w w. j a va 2 s .co m .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); String responseBody = "{\"response\":{\"cipher\": \"expected cipher\",\"data\":\"expected data\"}}"; when(response.getEntity()).thenReturn( EntityBuilder.create().setStream(new ByteArrayInputStream(responseBody.getBytes("UTF-8"))).build()); when(crypto.sign(any(byte[].class))).thenReturn("Expected Signature".getBytes()); transport = new ApacheHttpClientTransport(httpClient, "https://api.launchkey.com/v1", crypto); when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(response); }
From source file:com.google.android.apps.iosched.io.StubHttpClient.java
private static HttpResponse buildInternalServerError() { final StatusLine status = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_INTERNAL_SERVER_ERROR, null);/* www . j a v a2s. c o m*/ return new BasicHttpResponse(status); }
From source file:at.deder.ybr.test.server.SimpleHttpServerTest.java
/** * A simple test to check if reading the manifest is working. It creates a * manifest that contains the default values and then replies that manifest * from a mocked and injected client./*from www . j av a2 s . com*/ */ @Test public void testGetManifestDefault() throws IOException, ProtocolViolationException { ServerManifest expectedResult = new ServerManifest(); expectedResult.initDefaults(); StringWriter manifestWriter = new StringWriter(); expectedResult.writeYaml(manifestWriter); given(mockHttpClient.execute(Matchers.any(HttpGet.class))).willReturn(mockHttpResponse); given(mockHttpResponse.getEntity()).willReturn(mockHttpEntity); given(mockHttpResponse.getStatusLine()) .willReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK")); given(mockHttpEntity.getContent()) .willReturn(new ByteArrayInputStream(manifestWriter.toString().getBytes("utf-8"))); SimpleHttpServer instance = new SimpleHttpServer("none"); instance.setHttpClient(mockHttpClient); ServerManifest result = instance.getManifest(); assertEquals(expectedResult, result); }
From source file:com.joyent.manta.client.multipart.ServerSideMultipartManagerTest.java
public void canInitiateUploadSuccess() throws IOException { final UUID uploadId = UUID.randomUUID(); final String partsDirectory = "/test/uploads/a/abcdef"; final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_CREATED, "CREATED"); final String jsonResponse = String.format("{ \"id\":\"%s\", \"partsDirectory\":\"%s\" }", uploadId.toString(), partsDirectory); String path = "/test/stor/object"; ServerSideMultipartUpload serverSideUpload = initiateUploadWithAllParams(path, statusLine, jsonResponse); Assert.assertEquals(serverSideUpload.getId(), uploadId); Assert.assertEquals(serverSideUpload.getPath(), path); Assert.assertEquals(serverSideUpload.getPartsDirectory(), partsDirectory); }
From source file:org.opencastproject.workflow.handler.HttpNotificationWorkflowOperationHandlerTest.java
@Before public void setUp() throws Exception { MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder(); // test resources URI uriMP = getClass().getResource("/concat_mediapackage.xml").toURI(); mp = builder.loadFromXml(uriMP.toURL().openStream()); // set up mock trusted http client client = EasyMock.createNiceMock(TrustedHttpClient.class); HttpResponse response = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_ACCEPTED, "")); EasyMock.expect(client.execute((HttpUriRequest) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())) .andReturn(response);// w ww. jav a2 s.co m EasyMock.replay(client); // set up service operationHandler = new HttpNotificationWorkflowOperationHandler(); }
From source file:com.nexmo.client.voice.SendDtmfMethodTest.java
@Test public void parseResponse() throws Exception { HttpWrapper wrapper = new HttpWrapper(); SendDtmfMethod methodUnderTest = new SendDtmfMethod(wrapper); HttpResponse stubResponse = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("1.1", 1, 1), 200, "OK")); String json = "{\"message\": \"DTMF sent\",\"uuid\": \"ssf61863-4a51-ef6b-11e1-w6edebcf93bb\"}"; InputStream jsonStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(jsonStream);/*w ww . java2s . c om*/ stubResponse.setEntity(entity); DtmfResponse response = methodUnderTest.parseResponse(stubResponse); assertEquals("DTMF sent", response.getMessage()); assertEquals("ssf61863-4a51-ef6b-11e1-w6edebcf93bb", response.getUuid()); }