Android BasicStatusLine - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BasicStatusLine class.

This code example shows how to use the following methods:
        return getInstrumentation().getContext();
    } 
 
    public PersitingActorTestCase<T> given(InputStream in) {
        httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1),
                200, "OK")); 
        InputStreamEntity entity = new InputStreamEntity(in, -1);
        httpResponse.setEntity(entity);
        return this;
    } 
 
    public PersitingActorTestCase<T> given(String httpResponseBody) {
        httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1),
                200, "OK")); 
        StringEntity entity = null;
        try { 
            entity = new StringEntity(httpResponseBody);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } 
6
CodeRank
This code example shows how to use the following methods:
		super.setUp(); 
 
		// Set up the MockClient 
		this.mockEntity = new MockHttpEntity();
 
		StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1,
		                                            HttpStatus.SC_OK,
		                                            "OK"); 
    	this.mockResponse = new MockHttpResponse(this.mockEntity, statusLine);
    	this.mockClient = new MockHttpClient(this.mockResponse);
        this.loadLiveLibraryHeaderChecker();
    	this.exceptionQueue = new LinkedBlockingQueue<LiveOperationException>();
    	this.liveConnectClient = TestUtils.newLiveConnectClient(this.mockClient);
	} 
 
	@Override 
	protected void tearDown() throws Exception { 
	    super.tearDown(); 
 
	    this.mockEntity = null;
6
CodeRank
This code example shows how to use the following methods:
        folder.put(JsonKeys.UPLOAD_LOCATION, "https://upload.location.com/some/path");
 
        InputStream uploadLocationStream =
                new ByteArrayInputStream(folder.toString().getBytes());
        MockHttpEntity uploadLocationEntity = new MockHttpEntity(uploadLocationStream);
        StatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "");
        MockHttpResponse uploadLocationResponse = new MockHttpResponse(uploadLocationEntity, ok);
        this.mockClient.setHttpResponse(uploadLocationResponse);
    } 
 
    @Override 
    protected String getMethod() {
        return HttpPut.METHOD_NAME;
    } 
 
    @Override 
    protected void setUp() throws Exception { 
        super.setUp(); 
 
        // some upload requests perform two http requests, so clear any responses that may have 
6
CodeRank
This code example shows how to use the following methods:
 
    // This is the only one we actually use. 
    @Override 
    public HttpResponse execute(HttpUriRequest request, HttpContext context) {
        requestExecuted = request;
        StatusLine statusLine = new BasicStatusLine(
                new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
        HttpResponse response = new BasicHttpResponse(statusLine);
        response.setEntity(mResponseEntity);
 
        return response;
    } 
 
 
    // Unimplemented methods ahoy 
 
    @Override 
    public HttpResponse execute(HttpUriRequest request) {
        throw new UnsupportedOperationException();
    } 
5
CodeRank
This code example shows how to use the following methods:
     * @return 
     */ 
    private HttpResponse createResponse(final String stringResponse) {
        final HttpResponse responseMock = Mockito.mock(HttpResponse.class);
        Mockito.when(responseMock.getHeaders("ETag")).thenReturn(new Header[]{new BasicHeader("ETag", "123")});
        Mockito.when(responseMock.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "All good"));        
        Mockito.when(responseMock.getEntity()).thenReturn(new ByteArrayEntity(stringResponse.getBytes()));
        return responseMock;
    } 
 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 
    @Test 
    @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ThrowableInstanceNeverThrown"}) 
    public void testAPIException(){ 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine( 
                new ProtocolVersion("HTTP",1,1), 404, "Not Found")); 
        String testMsg = "Test Message"; 
        APIError apiError = APIError.newBuilder() 
                .setError("TEST") 
                .setErrorCode(42) 
                .setOperationId("OpID") 
                .build(); 
 
        RuntimeException runtimeException = 
                new RuntimeException("Test RuntimeException"); 
 
        APIRequestException testException = APIRequestException.newBuilder() 
                .setMessage(testMsg) 
                .setCause(runtimeException) 
                .setApiError(apiError) 
4
CodeRank
This code example shows how to use the following methods:
    public void testUnsuccessfulResponse() throws Exception { 
        InputStream instream = Mockito.mock(InputStream.class);
        HttpEntity entity = Mockito.mock(HttpEntity.class);
        Mockito.when(entity.isStreaming()).thenReturn(true);
        Mockito.when(entity.getContent()).thenReturn(instream);
        StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "Not Found");
        HttpResponse response = Mockito.mock(HttpResponse.class);
        Mockito.when(response.getStatusLine()).thenReturn(sl);
        Mockito.when(response.getEntity()).thenReturn(entity);
 
        BasicResponseHandler handler = new BasicResponseHandler();
        try { 
            handler.handleResponse(response);
            Assert.fail("HttpResponseException expected");
        } catch (HttpResponseException ex) {
            Assert.assertEquals(404, ex.getStatusCode());
            Assert.assertEquals("Not Found", ex.getMessage());
        } 
        Mockito.verify(entity).getContent();
        Mockito.verify(instream).close();
4
CodeRank
This code example shows how to use the following methods:
 
 
    @Test 
    public void testAPIScheduleResponse(){ 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 200, "OK"));
        APIScheduleResponse scheduleResponse = APIScheduleResponse.newBuilder()
                .setScheduleUrls(Arrays.asList("ID1", "ID2"))
                .setOperationId("ID") 
                .build(); 
        APIClientResponse.Builder<APIScheduleResponse> builder = 
                APIClientResponse.newScheduleResponseBuilder() 
                                 .setApiResponse(scheduleResponse)
                                 .setHttpResponse(httpResponse);
        APIClientResponse<APIScheduleResponse> testResponse = builder.build();
        assertTrue("HTTP response not set properly", 
                   testResponse.getHttpResponse().equals(httpResponse));
 
        assertTrue("APIResponse not set properly", 
                   testResponse.getApiResponse().equals(scheduleResponse));
4
CodeRank
This code example shows how to use the following methods:
    @Test 
    public void testHandleSuccess(){ 
        String successJSON = "{\"ok\" : true, \"operation_id\" : \"OpID\", " +
                "\"schedule_ids\" : [\"ScheduleID\"]}"; 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 200, "OK"));
        InputStreamEntity inputStreamEntity = new InputStreamEntity(
                new ByteArrayInputStream(successJSON.getBytes()),
                successJSON.getBytes().length);
        httpResponse.setEntity(inputStreamEntity);
        ScheduleAPIResponseHandler handler = new ScheduleAPIResponseHandler();
 
        try { 
            APIClientResponse<APIScheduleResponse> response =
                    handler.handleResponse(httpResponse);
            assertTrue("Operation ID incorrect", 
                       response.getApiResponse().getOperationId().equals("OpID"));
            assertTrue("HttpResponse is incorrect", 
                       httpResponse.equals(httpResponse));
        } 
4
CodeRank
This code example shows how to use the following methods:
                "\"error\" : \"Could not parse request body\"," + 
                "\"error_code\" : 40000," + 
                "\"details\" : {\"error\" : \"Unexpected token '#'\"," + 
                "\"location\" : {\"line\" : 10,\"column\" : 3}}}"; 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 400, "Unauthorized"));
        InputStreamEntity inputStreamEntity = new InputStreamEntity(
                new ByteArrayInputStream(pushJSON.getBytes()),
                pushJSON.getBytes().length);
        httpResponse.setEntity(inputStreamEntity);
        httpResponse.setHeader(new BasicHeader(CONTENT_TYPE_KEY, UA_JSON_RESPONSE));
 
        /* Test handling */ 
        PushAPIResponseHandler handler = new PushAPIResponseHandler();
        try{ 
            handler.handleResponse(httpResponse);
        } 
        catch (APIRequestException ex){
            System.out.println("Exception " + ex.getMessage());
            APIError error = ex.getError().get();
4
CodeRank

Related Android BasicStatusLine Questions & Answers:

See Code Examples for Android BasicStatusLine Methods: