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 theLocalModulesServicein tests.To understand the operation of
LocalModulesServiceTestConfigplease note that a number ofApiProxy.Environmentsettings 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
LocalServiceTestHelpermust 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 forLocalServiceTestHelperafter you callsetUp()do not apply forModulesServiceduring your test run. For simple configurationsLocalModulesServiceTestConfigwill generate a configuration based on the currentApiProxy.Environment. The generatedLocalModulesServiceTestConfigcontains 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
LocalModulesServiceTestConfigto theLocalServiceTestHelperconstructor with other neededLocalServiceTestConfigobjects. - Update the test
ApiProxy.Environmentto 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.StringDEFAULT_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 LocalModulesServiceTestConfigaddAutomaticScalingModuleVersion(java.lang.String module, java.lang.String version)Adds a automatic scaling module version.LocalModulesServiceTestConfigaddBasicScalingModuleVersion(java.lang.String module, java.lang.String version, int numInstances)Adds a basic scaling module version.LocalModulesServiceTestConfigaddDefaultModuleVersion()Adds an automatic scaling module version that matches the defaultApiProxy.Environmentconstructed byLocalServiceTestHelperwith module = "default" and version = "1".LocalModulesServiceTestConfigaddManualScalingModuleVersion(java.lang.String module, java.lang.String version, int numInstances)Adds a manual scaling module version.voidclearModuleVersions()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.LocalModulesServicegetLocalModulesService()Returns theLocalModulesServicewhich is created on first use.voidsetUp()Set up the local service.voidtearDown()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:LocalServiceTestConfigSet up the local service.- Specified by:
setUpin interfaceLocalServiceTestConfig
-
tearDown
public void tearDown()
Description copied from interface:LocalServiceTestConfigTear down the local service.- Specified by:
tearDownin 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.Environmentconstructed byLocalServiceTestHelperwith 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 theLocalModulesServicewhich is created on first use.
-
-