Skip to content

Commit

Permalink
Fix tests for fluent code
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Aug 25, 2016
1 parent a1cd0f1 commit 6c35000
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void updateFromResponseOnPutPatch(Response<ResponseBody> response) throws
}

if (responseContent == null || responseContent.isEmpty()) {
CloudException exception = new CloudException("no body");
CloudException exception = new CloudException("polling response does not contain a valid body");
exception.setResponse(response);
throw exception;
}
Expand Down
35 changes: 28 additions & 7 deletions client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class ServiceCall<T> extends AbstractFuture<ServiceResponse<T>> {
protected ServiceCall() {
}

/**
* Creates a ServiceCall from an observable object.
*
* @param observable the observable to create from
* @param <T> the type of the response
* @return the created ServiceCall
*/
public static <T> ServiceCall<T> create(final Observable<ServiceResponse<T>> observable) {
final ServiceCall<T> serviceCall = new ServiceCall<>();
serviceCall.subscription = observable
Expand All @@ -47,6 +54,14 @@ public void call(Throwable throwable) {
return serviceCall;
}

/**
* Creates a ServiceCall from an observable object and a callback.
*
* @param observable the observable to create from
* @param callback the callback to call when events happen
* @param <T> the type of the response
* @return the created ServiceCall
*/
public static <T> ServiceCall<T> create(final Observable<ServiceResponse<T>> observable, final ServiceCallback<T> callback) {
final ServiceCall<T> serviceCall = new ServiceCall<>();
serviceCall.subscription = observable
Expand All @@ -71,6 +86,15 @@ public void call(Throwable throwable) {
return serviceCall;
}

/**
* Creates a ServiceCall from an observable and a callback for a header response.
*
* @param observable the observable of a REST call that returns JSON in a header
* @param callback the callback to call when events happen
* @param <T> the type of the response body
* @param <V> the type of the response header
* @return the created ServiceCall
*/
public static <T, V> ServiceCall<T> createWithHeaders(final Observable<ServiceResponseWithHeaders<T, V>> observable, final ServiceCallback<T> callback) {
final ServiceCall<T> serviceCall = new ServiceCall<>();
serviceCall.subscription = observable
Expand All @@ -95,20 +119,17 @@ public void call(Throwable throwable) {
return serviceCall;
}

/**
* @return the current Rx subscription associated with the ServiceCall.
*/
public Subscription getSubscription() {
return subscription;
}

public void setSubscription(Subscription subscription) {
protected void setSubscription(Subscription subscription) {
this.subscription = subscription;
}

/**
* Cancel the Retrofit call if possible. Parameter
* 'mayInterruptIfRunning is ignored.
*
* @param mayInterruptIfRunning ignored
*/
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
subscription.unsubscribe();
Expand Down

0 comments on commit 6c35000

Please sign in to comment.