Package com.google.jenkins.plugins.util
Class MockExecutor
- java.lang.Object
-
- com.google.jenkins.plugins.util.Executor
-
- com.google.jenkins.plugins.util.MockExecutor
-
public class MockExecutor extends Executor
This is an implementation ofExecutor
that can be injected to inject a set of canned responses to requests including:- A pre-determined object
- Throwing an
IOException
orExecutorException
- 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 Constructor Description MockExecutor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
execute(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T> request)
Executes the request, returning a response of the appropriate type.<T> T
execute(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 givenrequestType
pass 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 givenrequestType
and the provided userPredicate
pass through the request'sgetJsonContent()
cast to the expected response type.boolean
sawAll()
Did we see all of the expected requests?boolean
sawUnexpected()
Did we see any unexpected requests?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;<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidthrowWhen(Class<C> requestType, ExecutorException exception)
When the next request matches the givenrequestType
throwexception
instead 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 givenrequestType
and the provided userPredicate
throwexception
instead 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 givenrequestType
throwexception
instead 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 givenrequestType
and the provided userPredicate
throwexception
instead of responding.<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidwhen(Class<C> requestType, T response)
When the next request matches the givenrequestType
returnresponse
as the response.<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S>
voidwhen(Class<C> requestType, T response, com.google.common.base.Predicate<S> predicate)
When the next request matches the givenrequestType
and the provided userPredicate
returnresponse
as the response.
-
-
-
Method Detail
-
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
public <T> T execute(RequestCallable<T> request) throws IOException, ExecutorException
Executes the request, returning a response of the appropriate type.- Specified by:
execute
in 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:
execute
in 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>,C extends S> void when(Class<C> requestType, T response, com.google.common.base.Predicate<S> predicate)
When the next request matches the givenrequestType
and the provided userPredicate
returnresponse
as 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 givenrequestType
returnresponse
as the response.
-
throwWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void throwWhen(Class<C> requestType, IOException exception, com.google.common.base.Predicate<S> predicate)
When the next request matches the givenrequestType
and the provided userPredicate
throwexception
instead 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 givenrequestType
throwexception
instead of responding.
-
throwWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void throwWhen(Class<C> requestType, ExecutorException exception, com.google.common.base.Predicate<S> predicate)
When the next request matches the givenrequestType
and the provided userPredicate
throwexception
instead 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 givenrequestType
throwexception
instead of responding.
-
passThruWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void passThruWhen(Class<C> requestType, com.google.common.base.Predicate<S> predicate)
When the next request matches the givenrequestType
and the provided userPredicate
pass 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 givenrequestType
pass 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?
-
-