Search in sources :

Example 1 with MockHttpEntity

use of com.microsoft.live.mock.MockHttpEntity in project LiveSDK-for-Android by liveservices.

the class UploadTest method loadUploadLocationResponseBody.

protected void loadUploadLocationResponseBody() throws Exception {
    /* create folder response */
    JSONObject folder = new JSONObject();
    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);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MockHttpEntity(com.microsoft.live.mock.MockHttpEntity) BasicStatusLine(org.apache.http.message.BasicStatusLine) MockHttpResponse(com.microsoft.live.mock.MockHttpResponse)

Example 2 with MockHttpEntity

use of com.microsoft.live.mock.MockHttpEntity in project LiveSDK-for-Android by liveservices.

the class UploadRequestTest method testSendPathQueryParameterToHttpPut.

/**
     * WinLive 633441: Make sure the query parameters on path get sent to
     * the HTTP PUT part of the upload.
     */
public void testSendPathQueryParameterToHttpPut() throws Throwable {
    JSONObject jsonResponseBody = new JSONObject();
    jsonResponseBody.put(JsonKeys.UPLOAD_LOCATION, "http://test.com/location");
    InputStream responseStream = new ByteArrayInputStream(jsonResponseBody.toString().getBytes());
    MockHttpEntity responseEntity = new MockHttpEntity(responseStream);
    BasicStatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "");
    final MockHttpResponse uploadLocationResponse = new MockHttpResponse(responseEntity, ok);
    HttpClient client = new HttpClient() {

        /** the first request to the client is the upload location request. */
        boolean uploadLocationRequest = true;

        @Override
        public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {
            if (uploadLocationRequest) {
                uploadLocationRequest = false;
                return uploadLocationResponse;
            }
            // This is really the only part we care about in this test.
            // That the 2nd request's uri has foo=bar in the query string.
            URI uri = request.getURI();
            assertEquals("foo=bar&overwrite=choosenewname", uri.getQuery());
            // just return the previous reponse.
            return uploadLocationResponse;
        }

        @Override
        public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1, HttpContext arg2) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2, HttpContext arg3) throws IOException, ClientProtocolException {
            throw new UnsupportedOperationException();
        }

        @Override
        public ClientConnectionManager getConnectionManager() {
            throw new UnsupportedOperationException();
        }

        @Override
        public HttpParams getParams() {
            throw new UnsupportedOperationException();
        }
    };
    LiveConnectSession session = TestUtils.newMockLiveConnectSession();
    HttpEntity entity = new MockHttpEntity();
    String path = Paths.ME_SKYDRIVE + "?foo=bar";
    String filename = "filename";
    UploadRequest uploadRequest = new UploadRequest(session, client, path, entity, filename, OverwriteOption.Rename);
    uploadRequest.execute();
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpRequest(org.apache.http.HttpRequest) ResponseHandler(org.apache.http.client.ResponseHandler) HttpEntity(org.apache.http.HttpEntity) MockHttpEntity(com.microsoft.live.mock.MockHttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpContext(org.apache.http.protocol.HttpContext) MockHttpEntity(com.microsoft.live.mock.MockHttpEntity) URI(java.net.URI) BasicStatusLine(org.apache.http.message.BasicStatusLine) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) MockHttpResponse(com.microsoft.live.mock.MockHttpResponse)

Example 3 with MockHttpEntity

use of com.microsoft.live.mock.MockHttpEntity in project LiveSDK-for-Android by liveservices.

the class ApiTest method setUp.

@Override
protected void setUp() throws Exception {
    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);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) MockHttpEntity(com.microsoft.live.mock.MockHttpEntity) LiveOperationException(com.microsoft.live.LiveOperationException) MockHttpClient(com.microsoft.live.mock.MockHttpClient) BasicStatusLine(org.apache.http.message.BasicStatusLine) MockHttpResponse(com.microsoft.live.mock.MockHttpResponse)

Example 4 with MockHttpEntity

use of com.microsoft.live.mock.MockHttpEntity in project LiveSDK-for-Android by liveservices.

the class UploadTest method loadValidResponseBody.

@Override
protected void loadValidResponseBody() throws Exception {
    JSONObject jsonResponseBody = new JSONObject();
    jsonResponseBody.put(JsonKeys.ID, FILE_ID);
    jsonResponseBody.put(JsonKeys.SOURCE, SOURCE);
    InputStream responseStream = new ByteArrayInputStream(jsonResponseBody.toString().getBytes());
    MockHttpEntity responseEntity = new MockHttpEntity(responseStream);
    StatusLine created = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_CREATED, "");
    MockHttpResponse response = new MockHttpResponse(responseEntity, created);
    this.mockClient.addHttpResponse(response);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MockHttpEntity(com.microsoft.live.mock.MockHttpEntity) BasicStatusLine(org.apache.http.message.BasicStatusLine) MockHttpResponse(com.microsoft.live.mock.MockHttpResponse)

Aggregations

MockHttpEntity (com.microsoft.live.mock.MockHttpEntity)4 MockHttpResponse (com.microsoft.live.mock.MockHttpResponse)4 BasicStatusLine (org.apache.http.message.BasicStatusLine)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 StatusLine (org.apache.http.StatusLine)3 JSONObject (org.json.JSONObject)3 LiveOperationException (com.microsoft.live.LiveOperationException)1 MockHttpClient (com.microsoft.live.mock.MockHttpClient)1 URI (java.net.URI)1 HttpEntity (org.apache.http.HttpEntity)1 HttpHost (org.apache.http.HttpHost)1 HttpRequest (org.apache.http.HttpRequest)1 HttpClient (org.apache.http.client.HttpClient)1 ResponseHandler (org.apache.http.client.ResponseHandler)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 HttpContext (org.apache.http.protocol.HttpContext)1