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);
}
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();
}
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);
}
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);
}
Aggregations