Package com.google.jenkins.plugins.util
Class MockExecutor
java.lang.Object
com.google.jenkins.plugins.util.Executor
com.google.jenkins.plugins.util.MockExecutor
This is an implementation of
Executor that can be injected to inject a set of canned
responses to requests including:
- A pre-determined object
- Throwing an
IOExceptionorExecutorException - Passing through a part of the request as the response
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.jenkins.plugins.util.Executor
Executor.Default -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Texecute(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T> request) Executes the request, returning a response of the appropriate type.<T> Texecute(RequestCallable<T> request) Executes the request, returning a response of the appropriate type.<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidpassThruWhen(Class<C> requestType) When the next request matches the givenrequestTypepass through the request'sgetJsonContent()cast to the expected response type.<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidpassThruWhen(Class<C> requestType, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatepass through the request'sgetJsonContent()cast to the expected response type.booleansawAll()Did we see all of the expected requests?booleanDid we see any unexpected requests?voidsleep()Surface this as a canonical means by which to sleep, so that clients can layer their own retry logic on top of the executor using the same sleep facility;<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidthrowWhen(Class<C> requestType, ExecutorException exception) When the next request matches the givenrequestTypethrowexceptioninstead of responding.<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidthrowWhen(Class<C> requestType, ExecutorException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatethrowexceptioninstead of responding.<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidthrowWhen(Class<C> requestType, IOException exception) When the next request matches the givenrequestTypethrowexceptioninstead of responding.<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidthrowWhen(Class<C> requestType, IOException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatethrowexceptioninstead of responding.<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidWhen the next request matches the givenrequestTypereturnresponseas the response.<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidWhen the next request matches the givenrequestTypeand the provided userPredicatereturnresponseas the response.
-
Constructor Details
-
MockExecutor
public MockExecutor()
-
-
Method Details
-
sleep
public void sleep()Surface this as a canonical means by which to sleep, so that clients can layer their own retry logic on top of the executor using the same sleep facility; -
execute
Executes the request, returning a response of the appropriate type.- Specified by:
executein classExecutor- Type Parameters:
T- The type of the expected response- Parameters:
request- The request we are issuing- Returns:
- a Json object of the given type
- Throws:
IOException- if anything goes wrongExecutorException
-
execute
public <T> T execute(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T> request) throws IOException, ExecutorException Executes the request, returning a response of the appropriate type.- Overrides:
executein classExecutor- Type Parameters:
T- The type of the expected response- Parameters:
request- The request we are issuing- Returns:
- a Json object of the given type
- Throws:
IOException- if anything goes wrongExecutorException
-
when
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void whenC extends S> (Class<C> requestType, T response, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatereturnresponseas the response. -
when
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void when(Class<C> requestType, T response) When the next request matches the givenrequestTypereturnresponseas the response. -
throwWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void throwWhenC extends S> (Class<C> requestType, IOException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatethrowexceptioninstead of responding. -
throwWhen
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void throwWhen(Class<C> requestType, IOException exception) When the next request matches the givenrequestTypethrowexceptioninstead of responding. -
throwWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void throwWhenC extends S> (Class<C> requestType, ExecutorException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatethrowexceptioninstead of responding. -
throwWhen
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void throwWhen(Class<C> requestType, ExecutorException exception) When the next request matches the givenrequestTypethrowexceptioninstead of responding. -
passThruWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void passThruWhenC extends S> (Class<C> requestType, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestTypeand the provided userPredicatepass through the request'sgetJsonContent()cast to the expected response type. -
passThruWhen
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void passThruWhen(Class<C> requestType) When the next request matches the givenrequestTypepass through the request'sgetJsonContent()cast to the expected response type. -
sawAll
public boolean sawAll()Did we see all of the expected requests? -
sawUnexpected
public boolean sawUnexpected()Did we see any unexpected requests?
-