public class LocalServiceTestHelper
extends java.lang.Object
LocalServiceTestConfig
instance for
each service that you wish to access as part of your test. Then call
setUp()
before each test executes and tearDown()
after
each test executes. No specific test-harness is assumed, but here's a
JUnit 3 example that uses task queues and the datastore.
public void MyTest extends TestCase { private final LocalServiceTestHelper helper = new LocalServiceTestHelper( new LocalTaskQueueTestConfig(), new LocalDatastoreServiceTestConfig()); @Override public void setUp() { super.setUp(); helper.setUp(); } @Override public void tearDown() { helper.tearDown(); super.tearDown(); } }
Modifier and Type | Class and Description |
---|---|
static interface |
LocalServiceTestHelper.RequestMillisTimer |
Constructor and Description |
---|
LocalServiceTestHelper(LocalServiceTestConfig... configs)
Constructs a LocalServiceTestHelper with the provided configurations.
|
Modifier and Type | Method and Description |
---|---|
static void |
endRequest()
Indicate the request has ended so that local services can do any post request work.
|
static ApiProxyLocal |
getApiProxyLocal()
Convenience function for getting ahold of the currently
registered
ApiProxyLocal . |
static LocalRpcService |
getLocalService(java.lang.String serviceName)
Convenience function for getting ahold of a specific local service.
|
protected com.google.apphosting.api.ApiProxy.Environment |
newEnvironment()
Constructs the
ApiProxy.Environment that
will be installed. |
protected LocalServerEnvironment |
newLocalServerEnvironment()
Constructs the
LocalServerEnvironment that will be installed. |
LocalServiceTestHelper |
setClock(Clock clock)
Sets the clock with which all local services will be initialized.
|
LocalServiceTestHelper |
setEnforceApiDeadlines(boolean val)
Determines whether or not API calls should be subject to the same
deadlines as in production.
|
LocalServiceTestHelper |
setEnvAppId(java.lang.String envAppId)
The value to be returned by
ApiProxy.getCurrentEnvironment().getAppId() |
LocalServiceTestHelper |
setEnvAttributes(java.util.Map<java.lang.String,java.lang.Object> envAttributes)
The value to be returned by
ApiProxy.getCurrentEnvironment().getAttributes() |
LocalServiceTestHelper |
setEnvAuthDomain(java.lang.String envAuthDomain)
The value to be returned by
ApiProxy.getCurrentEnvironment().getAuthDomain() |
LocalServiceTestHelper |
setEnvEmail(java.lang.String envEmail)
The value to be returned by
ApiProxy.getCurrentEnvironment().getEmail() |
LocalServiceTestHelper |
setEnvInstance(java.lang.String envInstance)
The current instance id held by ApiProxy.getCurrentEnvironment()
|
LocalServiceTestHelper |
setEnvIsAdmin(boolean envIsAdmin)
The value to be returned by
ApiProxy.getCurrentEnvironment().isAdmin() |
LocalServiceTestHelper |
setEnvIsLoggedIn(boolean envIsLoggedIn)
The value to be returned by
ApiProxy.getCurrentEnvironment().isLoggedIn() |
LocalServiceTestHelper |
setEnvModuleId(java.lang.String envModuleId)
The value to be returned by
ApiProxy.getCurrentEnvironment().getModuleId() |
LocalServiceTestHelper |
setEnvRequestNamespace(java.lang.String envRequestNamespace)
The value to be returned by
ApiProxy.getCurrentEnvironment().getRequestNamespace() |
LocalServiceTestHelper |
setEnvVersionId(java.lang.String envVersionId)
The value to be returned by
ApiProxy.getCurrentEnvironment().getVersionId() |
LocalServiceTestHelper |
setRemainingMillisTimer(LocalServiceTestHelper.RequestMillisTimer timer)
Sets the object that will return the value to be returned by
ApiProxy.getCurrentEnvironment().getRemainingMillis() |
LocalServiceTestHelper |
setSimulateProdLatencies(boolean val)
Determines whether or not local services should simulate production
latencies.
|
LocalServiceTestHelper |
setTimeZone(java.util.TimeZone timeZone)
Sets the time zone in which tests will execute.
|
LocalServiceTestHelper |
setUp()
Set up an environment in which tests that use local services can execute.
|
void |
tearDown()
Tear down the environment in which tests that use local services can
execute.
|
public LocalServiceTestHelper(LocalServiceTestConfig... configs)
configs
- for the local services that need to be set up and torn down.public LocalServiceTestHelper setEnvAppId(java.lang.String envAppId)
ApiProxy.getCurrentEnvironment().getAppId()
envAppId
- this
(for chaining)public LocalServiceTestHelper setEnvModuleId(java.lang.String envModuleId)
ApiProxy.getCurrentEnvironment().getModuleId()
envModuleId
- this
(for chaining)public LocalServiceTestHelper setEnvVersionId(java.lang.String envVersionId)
ApiProxy.getCurrentEnvironment().getVersionId()
envVersionId
- this
(for chaining)public LocalServiceTestHelper setEnvInstance(java.lang.String envInstance)
envInstance
- must an integer >= -1 (default instance)this
(for chaining)public LocalServiceTestHelper setEnvEmail(java.lang.String envEmail)
ApiProxy.getCurrentEnvironment().getEmail()
envEmail
- this
(for chaining)public LocalServiceTestHelper setEnvIsLoggedIn(boolean envIsLoggedIn)
ApiProxy.getCurrentEnvironment().isLoggedIn()
envIsLoggedIn
- this
(for chaining)public LocalServiceTestHelper setEnvIsAdmin(boolean envIsAdmin)
ApiProxy.getCurrentEnvironment().isAdmin()
envIsAdmin
- this
(for chaining)public LocalServiceTestHelper setEnvAuthDomain(java.lang.String envAuthDomain)
ApiProxy.getCurrentEnvironment().getAuthDomain()
envAuthDomain
- this
(for chaining)public LocalServiceTestHelper setRemainingMillisTimer(LocalServiceTestHelper.RequestMillisTimer timer)
ApiProxy.getCurrentEnvironment().getRemainingMillis()
timer
- The timer that returns the amount of time left.this
(for chaining)public LocalServiceTestHelper setEnvRequestNamespace(java.lang.String envRequestNamespace)
ApiProxy.getCurrentEnvironment().getRequestNamespace()
envRequestNamespace
- this
(for chaining)public LocalServiceTestHelper setEnvAttributes(java.util.Map<java.lang.String,java.lang.Object> envAttributes)
ApiProxy.getCurrentEnvironment().getAttributes()
envAttributes
- this
(for chaining)public LocalServiceTestHelper setClock(Clock clock)
clock
- this
(for chaining)public LocalServiceTestHelper setEnforceApiDeadlines(boolean val)
false
.val
- this
(for chaining)public LocalServiceTestHelper setSimulateProdLatencies(boolean val)
false
.val
- this
(for chaining)public LocalServiceTestHelper setTimeZone(java.util.TimeZone timeZone)
user.timezone
system property, this will change the default timezone for the JVM.
However, if your code does not have this permission, the timezone will only
be altered for the current thread.timeZone
- the time zonethis
(for chaining)public final LocalServiceTestHelper setUp()
this
(for chaining)protected com.google.apphosting.api.ApiProxy.Environment newEnvironment()
ApiProxy.Environment
that
will be installed. Subclass and override to provide your own implementation.protected LocalServerEnvironment newLocalServerEnvironment()
LocalServerEnvironment
that will be installed.
Subclass and override to provide your own implementation.public final void tearDown()
public static void endRequest()
tearDown()
.
You only need to call this method if you want to call tearDown()
from your own tearDown / @After method but need to end the request to verify any behavior.public static ApiProxyLocal getApiProxyLocal()
ApiProxyLocal
.public static LocalRpcService getLocalService(java.lang.String serviceName)
getLocalService(LocalDatastoreService.PACKAGE)
.