Class LocalServiceTestHelper
java.lang.Object
com.google.appengine.tools.development.testing.LocalServiceTestHelper
Helper class for testing against local app engine services.
Construct the helper with one
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();
}
}
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionLocalServiceTestHelper(LocalServiceTestConfig... configs) Constructs a LocalServiceTestHelper with the provided configurations. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidIndicate the request has ended so that local services can do any post request work.static ApiProxyLocalConvenience function for getting ahold of the currently registeredApiProxyLocal.static LocalRpcServicegetLocalService(String serviceName) Convenience function for getting ahold of a specific local service.Sets the clock with which all local services will be initialized.setEnforceApiDeadlines(boolean val) Determines whether or not API calls should be subject to the same deadlines as in production.setEnvAppId(String envAppId) The value to be returned byApiProxy.getCurrentEnvironment().getAppId()setEnvAttributes(Map<String, Object> envAttributes) The value to be returned byApiProxy.getCurrentEnvironment().getAttributes()setEnvAuthDomain(String envAuthDomain) The value to be returned byApiProxy.getCurrentEnvironment().getAuthDomain()setEnvEmail(String envEmail) The value to be returned byApiProxy.getCurrentEnvironment().getEmail()setEnvInstance(String envInstance) The current instance id held by ApiProxy.getCurrentEnvironment()setEnvIsAdmin(boolean envIsAdmin) The value to be returned byApiProxy.getCurrentEnvironment().isAdmin()setEnvIsLoggedIn(boolean envIsLoggedIn) The value to be returned byApiProxy.getCurrentEnvironment().isLoggedIn()setEnvModuleId(String envModuleId) The value to be returned byApiProxy.getCurrentEnvironment().getModuleId()setEnvRequestNamespace(String envRequestNamespace) The value to be returned byApiProxy.getCurrentEnvironment().getRequestNamespace()setEnvVersionId(String envVersionId) The value to be returned byApiProxy.getCurrentEnvironment().getVersionId()Sets the object that will return the value to be returned byApiProxy.getCurrentEnvironment().getRemainingMillis()setSimulateProdLatencies(boolean val) Determines whether or not local services should simulate production latencies.setTimeZone(TimeZone timeZone) Sets the time zone in which tests will execute.final LocalServiceTestHelpersetUp()Set up an environment in which tests that use local services can execute.final voidtearDown()Tear down the environment in which tests that use local services can execute.
-
Constructor Details
-
LocalServiceTestHelper
Constructs a LocalServiceTestHelper with the provided configurations.- Parameters:
configs- for the local services that need to be set up and torn down.
-
-
Method Details
-
setEnvAppId
The value to be returned byApiProxy.getCurrentEnvironment().getAppId()- Parameters:
envAppId-- Returns:
this(for chaining)
-
setEnvModuleId
The value to be returned byApiProxy.getCurrentEnvironment().getModuleId()- Parameters:
envModuleId-- Returns:
this(for chaining)
-
setEnvVersionId
The value to be returned byApiProxy.getCurrentEnvironment().getVersionId()- Parameters:
envVersionId-- Returns:
this(for chaining)
-
setEnvInstance
The current instance id held by ApiProxy.getCurrentEnvironment()- Parameters:
envInstance- must an integer >= -1 (default instance)- Returns:
this(for chaining)
-
setEnvEmail
The value to be returned byApiProxy.getCurrentEnvironment().getEmail()- Parameters:
envEmail-- Returns:
this(for chaining)
-
setEnvIsLoggedIn
The value to be returned byApiProxy.getCurrentEnvironment().isLoggedIn()- Parameters:
envIsLoggedIn-- Returns:
this(for chaining)
-
setEnvIsAdmin
The value to be returned byApiProxy.getCurrentEnvironment().isAdmin()- Parameters:
envIsAdmin-- Returns:
this(for chaining)
-
setEnvAuthDomain
The value to be returned byApiProxy.getCurrentEnvironment().getAuthDomain()- Parameters:
envAuthDomain-- Returns:
this(for chaining)
-
setRemainingMillisTimer
public LocalServiceTestHelper setRemainingMillisTimer(LocalServiceTestHelper.RequestMillisTimer timer) Sets the object that will return the value to be returned byApiProxy.getCurrentEnvironment().getRemainingMillis()- Parameters:
timer- The timer that returns the amount of time left.- Returns:
this(for chaining)
-
setEnvRequestNamespace
The value to be returned byApiProxy.getCurrentEnvironment().getRequestNamespace()- Parameters:
envRequestNamespace-- Returns:
this(for chaining)
-
setEnvAttributes
The value to be returned byApiProxy.getCurrentEnvironment().getAttributes()- Parameters:
envAttributes-- Returns:
this(for chaining)
-
setClock
Sets the clock with which all local services will be initialized. Note that once a local service is initialized its clock cannot be altered.- Parameters:
clock-- Returns:
this(for chaining)
-
setEnforceApiDeadlines
Determines whether or not API calls should be subject to the same deadlines as in production. The default isfalse.- Parameters:
val-- Returns:
this(for chaining)
-
setSimulateProdLatencies
Determines whether or not local services should simulate production latencies. The default isfalse.- Parameters:
val-- Returns:
this(for chaining)
-
setTimeZone
Sets the time zone in which tests will execute. If not set we use the same timezone that we use in production and the dev appserver: UTC. Note that if your code has permission to modify theuser.timezonesystem 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.- Parameters:
timeZone- the time zone- Returns:
this(for chaining)
-
setUp
Set up an environment in which tests that use local services can execute.- Returns:
this(for chaining)
-
tearDown
public final void tearDown()Tear down the environment in which tests that use local services can execute. -
endRequest
public static void endRequest()Indicate the request has ended so that local services can do any post request work. This method is optional and is automatically done intearDown(). You only need to call this method if you want to calltearDown()from your own tearDown / @After method but need to end the request to verify any behavior. -
getApiProxyLocal
Convenience function for getting ahold of the currently registeredApiProxyLocal. -
getLocalService
Convenience function for getting ahold of a specific local service. For example, to get ahold of the LocalDatastoreService you would callgetLocalService(LocalDatastoreService.PACKAGE).
-