Class LocalModulesServiceTestConfig
- java.lang.Object
-
- com.google.appengine.tools.development.testing.LocalModulesServiceTestConfig
-
- All Implemented Interfaces:
- LocalServiceTestConfig
public class LocalModulesServiceTestConfig extends java.lang.Object implements LocalServiceTestConfig
Config for accessing theLocalModulesService
in tests.To understand the operation of
LocalModulesServiceTestConfig
please note that a number ofApiProxy.Environment
settings affect the operation ofModulesService
. For the test environment these settings are controlled usingLocalServiceTestHelper
:-
LocalServiceTestHelper.setEnvModuleId(java.lang.String)
specifies the result returned byModulesService.getCurrentModule()
. The default module is "default". -
LocalServiceTestHelper.setEnvVersionId(java.lang.String)
specifies the result returned byModulesService.getCurrentVersion()
. The default version is "1". -
LocalServiceTestHelper.setEnvInstance(java.lang.String)
specifies the result returned byModulesService.getCurrentInstanceId()
. For manual scaling and basic scaling module versions you can explicitly specify a configured instance or if you prefer you can leave the default("-1") value and the testing framework will set the instance to 0. For automatic scaling module version you must leave the value as the default("-1").
The environment values for
LocalServiceTestHelper
must match a module, version (and instance if needed) that you configure or one that is automatically generated for you. Changes made to the environment values forLocalServiceTestHelper
after you callsetUp()
do not apply forModulesService
during your test run. For simple configurationsLocalModulesServiceTestConfig
will generate a configuration based on the currentApiProxy.Environment
. The generatedLocalModulesServiceTestConfig
contains the following elements:- If the envModuleId element is not "default" then an automatic scaling module version will be added with module = "default" and version = "1". This simulates the appengine rule that an application must have a version of the default module.
- If the envInstance has not been set or is set to its default "-1" value then an
automatic scaling module version will be added with module = envModuleId and
version = envVerionId. Note here and below that in the event envVersionId contains
a .
suffix (eg "v1.9") the minor suffix is not included in the added module version. - If the envInstance has been set or is set to a non default ("-1") value then a manual scaling module version will be added with module = envModuleId and version = envVerionId and instance = envInstance.
- Construct a
LocalModulesServiceTestConfig
- Pass the
LocalModulesServiceTestConfig
to theLocalServiceTestHelper
constructor with other neededLocalServiceTestConfig
objects. - Update the test
ApiProxy.Environment
to refer to a desired module, version and instance (if needed). - Start the testing environment with
setUp()
and execute your test.
{@code LocalServiceTestHelper helper;
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.String
DEFAULT_MODULE_NAME
-
Constructor Summary
Constructors Constructor and Description LocalModulesServiceTestConfig()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description LocalModulesServiceTestConfig
addAutomaticScalingModuleVersion(java.lang.String module, java.lang.String version)
Adds a automatic scaling module version.LocalModulesServiceTestConfig
addBasicScalingModuleVersion(java.lang.String module, java.lang.String version, int numInstances)
Adds a basic scaling module version.LocalModulesServiceTestConfig
addDefaultModuleVersion()
Adds an automatic scaling module version that matches the defaultApiProxy.Environment
constructed byLocalServiceTestHelper
with module = "default" and version = "1".LocalModulesServiceTestConfig
addManualScalingModuleVersion(java.lang.String module, java.lang.String version, int numInstances)
Adds a manual scaling module version.void
clearModuleVersions()
Clears any module versions that have been added withaddAutomaticScalingModuleVersion(java.lang.String, java.lang.String)
,addBasicScalingModuleVersion(java.lang.String, java.lang.String, int)
,addManualScalingModuleVersion(java.lang.String, java.lang.String, int)
andaddDefaultModuleVersion()
.static com.google.appengine.api.modules.dev.LocalModulesService
getLocalModulesService()
Returns theLocalModulesService
which is created on first use.void
setUp()
Set up the local service.void
tearDown()
Tear down the local service.
-
-
-
Field Detail
-
DEFAULT_MODULE_NAME
public static final java.lang.String DEFAULT_MODULE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
setUp
public void setUp()
Description copied from interface:LocalServiceTestConfig
Set up the local service.- Specified by:
setUp
in interfaceLocalServiceTestConfig
-
tearDown
public void tearDown()
Description copied from interface:LocalServiceTestConfig
Tear down the local service.- Specified by:
tearDown
in interfaceLocalServiceTestConfig
-
addAutomaticScalingModuleVersion
public LocalModulesServiceTestConfig addAutomaticScalingModuleVersion(java.lang.String module, java.lang.String version)
Adds a automatic scaling module version.- Parameters:
module
- the module nameversion
- the version- Returns:
- this for chaining
- Throws:
java.lang.IllegalArgumentException
- if a module version with the same name and version has already been added.
-
addManualScalingModuleVersion
public LocalModulesServiceTestConfig addManualScalingModuleVersion(java.lang.String module, java.lang.String version, int numInstances)
Adds a manual scaling module version.- Parameters:
module
- the module nameversion
- the versionnumInstances
- the number of instances for the module version.- Returns:
- this for chaining
- Throws:
java.lang.IllegalArgumentException
- if a module version with the same name and version has already been added.java.lang.IllegalArgumentException
- if numInstances <= 0.
-
addBasicScalingModuleVersion
public LocalModulesServiceTestConfig addBasicScalingModuleVersion(java.lang.String module, java.lang.String version, int numInstances)
Adds a basic scaling module version.- Parameters:
module
- the module nameversion
- the versionnumInstances
- the number of instances for the module version.- Returns:
- this for chaining
- Throws:
java.lang.IllegalArgumentException
- if a module version with the same name and version has already been added.java.lang.IllegalArgumentException
- if numInstances <= 0.
-
addDefaultModuleVersion
public LocalModulesServiceTestConfig addDefaultModuleVersion()
Adds an automatic scaling module version that matches the defaultApiProxy.Environment
constructed byLocalServiceTestHelper
with module = "default" and version = "1".- Returns:
- this for chaining
- Throws:
java.lang.IllegalArgumentException
- if a module version with the same name and version has already been added.
-
clearModuleVersions
public void clearModuleVersions()
Clears any module versions that have been added withaddAutomaticScalingModuleVersion(java.lang.String, java.lang.String)
,addBasicScalingModuleVersion(java.lang.String, java.lang.String, int)
,addManualScalingModuleVersion(java.lang.String, java.lang.String, int)
andaddDefaultModuleVersion()
.
-
getLocalModulesService
public static com.google.appengine.api.modules.dev.LocalModulesService getLocalModulesService()
Returns theLocalModulesService
which is created on first use.
-
-