com.google.appengine.tools.development.testing
Class LocalServiceTestHelper
- java.lang.Object
-
- com.google.appengine.tools.development.testing.LocalServiceTestHelper
-
public class LocalServiceTestHelper extends java.lang.Object
Helper class for testing against local app engine services. Construct the helper with oneLocalServiceTestConfig
instance for each service that you wish to access as part of your test. Then callsetUp()
before each test executes andtearDown()
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 Modifier and Type Class and Description static interface
LocalServiceTestHelper.RequestMillisTimer
-
Constructor Summary
Constructors Constructor and Description LocalServiceTestHelper(LocalServiceTestConfig... configs)
Constructs a LocalServiceTestHelper with the provided configurations.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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 registeredApiProxyLocal
.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 theApiProxy.Environment
that will be installed.protected LocalServerEnvironment
newLocalServerEnvironment()
Constructs theLocalServerEnvironment
that will be installed.protected LocalServerEnvironment
newLocalServerEnvironment(java.lang.Integer apiServerPort)
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 byApiProxy.getCurrentEnvironment().getAppId()
LocalServiceTestHelper
setEnvAttributes(java.util.Map<java.lang.String,java.lang.Object> envAttributes)
The value to be returned byApiProxy.getCurrentEnvironment().getAttributes()
LocalServiceTestHelper
setEnvAuthDomain(java.lang.String envAuthDomain)
The value to be returned byApiProxy.getCurrentEnvironment().getAuthDomain()
LocalServiceTestHelper
setEnvEmail(java.lang.String envEmail)
The value to be returned byApiProxy.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 byApiProxy.getCurrentEnvironment().isAdmin()
LocalServiceTestHelper
setEnvIsLoggedIn(boolean envIsLoggedIn)
The value to be returned byApiProxy.getCurrentEnvironment().isLoggedIn()
LocalServiceTestHelper
setEnvModuleId(java.lang.String envModuleId)
The value to be returned byApiProxy.getCurrentEnvironment().getModuleId()
LocalServiceTestHelper
setEnvRequestNamespace(java.lang.String envRequestNamespace)
The value to be returned byApiProxy.getCurrentEnvironment().getRequestNamespace()
LocalServiceTestHelper
setEnvVersionId(java.lang.String envVersionId)
The value to be returned byApiProxy.getCurrentEnvironment().getVersionId()
LocalServiceTestHelper
setRemainingMillisTimer(LocalServiceTestHelper.RequestMillisTimer timer)
Sets the object that will return the value to be returned byApiProxy.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.
-
-
-
Constructor Detail
-
LocalServiceTestHelper
public LocalServiceTestHelper(LocalServiceTestConfig... configs)
Constructs a LocalServiceTestHelper with the provided configurations.- Parameters:
configs
- for the local services that need to be set up and torn down.
-
-
Method Detail
-
setEnvAppId
public LocalServiceTestHelper setEnvAppId(java.lang.String envAppId)
The value to be returned byApiProxy.getCurrentEnvironment().getAppId()
- Parameters:
envAppId
-- Returns:
this
(for chaining)
-
setEnvModuleId
public LocalServiceTestHelper setEnvModuleId(java.lang.String envModuleId)
The value to be returned byApiProxy.getCurrentEnvironment().getModuleId()
- Parameters:
envModuleId
-- Returns:
this
(for chaining)
-
setEnvVersionId
public LocalServiceTestHelper setEnvVersionId(java.lang.String envVersionId)
The value to be returned byApiProxy.getCurrentEnvironment().getVersionId()
- Parameters:
envVersionId
-- Returns:
this
(for chaining)
-
setEnvInstance
public LocalServiceTestHelper setEnvInstance(java.lang.String envInstance)
The current instance id held by ApiProxy.getCurrentEnvironment()- Parameters:
envInstance
- must an integer >= -1 (default instance)- Returns:
this
(for chaining)
-
setEnvEmail
public LocalServiceTestHelper setEnvEmail(java.lang.String envEmail)
The value to be returned byApiProxy.getCurrentEnvironment().getEmail()
- Parameters:
envEmail
-- Returns:
this
(for chaining)
-
setEnvIsLoggedIn
public LocalServiceTestHelper setEnvIsLoggedIn(boolean envIsLoggedIn)
The value to be returned byApiProxy.getCurrentEnvironment().isLoggedIn()
- Parameters:
envIsLoggedIn
-- Returns:
this
(for chaining)
-
setEnvIsAdmin
public LocalServiceTestHelper setEnvIsAdmin(boolean envIsAdmin)
The value to be returned byApiProxy.getCurrentEnvironment().isAdmin()
- Parameters:
envIsAdmin
-- Returns:
this
(for chaining)
-
setEnvAuthDomain
public LocalServiceTestHelper setEnvAuthDomain(java.lang.String envAuthDomain)
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
public LocalServiceTestHelper setEnvRequestNamespace(java.lang.String envRequestNamespace)
The value to be returned byApiProxy.getCurrentEnvironment().getRequestNamespace()
- Parameters:
envRequestNamespace
-- Returns:
this
(for chaining)
-
setEnvAttributes
public LocalServiceTestHelper setEnvAttributes(java.util.Map<java.lang.String,java.lang.Object> envAttributes)
The value to be returned byApiProxy.getCurrentEnvironment().getAttributes()
- Parameters:
envAttributes
-- Returns:
this
(for chaining)
-
setClock
public LocalServiceTestHelper setClock(Clock clock)
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
public LocalServiceTestHelper setEnforceApiDeadlines(boolean val)
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
public LocalServiceTestHelper setSimulateProdLatencies(boolean val)
Determines whether or not local services should simulate production latencies. The default isfalse
.- Parameters:
val
-- Returns:
this
(for chaining)
-
setTimeZone
public LocalServiceTestHelper setTimeZone(java.util.TimeZone timeZone)
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.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.- Parameters:
timeZone
- the time zone- Returns:
this
(for chaining)
-
setUp
public final LocalServiceTestHelper setUp()
Set up an environment in which tests that use local services can execute.- Returns:
this
(for chaining)
-
newEnvironment
protected com.google.apphosting.api.ApiProxy.Environment newEnvironment()
Constructs theApiProxy.Environment
that will be installed. Subclass and override to provide your own implementation.
-
newLocalServerEnvironment
protected LocalServerEnvironment newLocalServerEnvironment()
Constructs theLocalServerEnvironment
that will be installed. Subclass and override to provide your own implementation.
-
newLocalServerEnvironment
protected LocalServerEnvironment newLocalServerEnvironment(java.lang.Integer apiServerPort)
-
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
public static ApiProxyLocal getApiProxyLocal()
Convenience function for getting ahold of the currently registeredApiProxyLocal
.
-
getLocalService
public static LocalRpcService getLocalService(java.lang.String serviceName)
Convenience function for getting ahold of a specific local service. For example, to get ahold of the LocalDatastoreService you would callgetLocalService(LocalDatastoreService.PACKAGE)
.
-
-