Search in sources :

Example 1 with MockHttpClient

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

the class ApiTest method loadLiveLibraryHeaderChecker.

/**
     * Changes the mockClient to one that checks if the incoming requests contains the
     * Live Library header and then reverts to the original mockClient.
     */
protected void loadLiveLibraryHeaderChecker() {
    final MockHttpClient currentMockClient = this.mockClient;
    MockHttpClient liveLibraryHeaderCheckerClient = new MockHttpClient() {

        @Override
        public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {
            Header header = request.getFirstHeader("X-HTTP-Live-Library");
            assertEquals("android/" + Build.VERSION.RELEASE + "_5.0", header.getValue());
            // load the old mock client back after we check.
            mockClient = currentMockClient;
            return currentMockClient.execute(request);
        }

        @Override
        public HttpResponse getHttpResponse() {
            return currentMockClient.getHttpResponse();
        }

        @Override
        public void setHttpResponse(HttpResponse httpResponse) {
            currentMockClient.setHttpResponse(httpResponse);
        }

        @Override
        public void addHttpResponse(HttpResponse httpResponse) {
            currentMockClient.addHttpResponse(httpResponse);
        }

        @Override
        public void clearHttpResponseQueue() {
            currentMockClient.clearHttpResponseQueue();
        }
    };
    this.mockClient = liveLibraryHeaderCheckerClient;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Header(org.apache.http.Header) MockHttpResponse(com.microsoft.live.mock.MockHttpResponse) HttpResponse(org.apache.http.HttpResponse) MockHttpClient(com.microsoft.live.mock.MockHttpClient)

Example 2 with MockHttpClient

use of com.microsoft.live.mock.MockHttpClient 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)

Aggregations

MockHttpClient (com.microsoft.live.mock.MockHttpClient)2 MockHttpResponse (com.microsoft.live.mock.MockHttpResponse)2 LiveOperationException (com.microsoft.live.LiveOperationException)1 MockHttpEntity (com.microsoft.live.mock.MockHttpEntity)1 Header (org.apache.http.Header)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 BasicStatusLine (org.apache.http.message.BasicStatusLine)1