Class LocalModulesServiceTestConfig
- All Implemented Interfaces:
LocalServiceTestConfig
LocalModulesService in tests.
To understand the operation of LocalModulesServiceTestConfig please note that a number
of ApiProxy.Environment settings affect the
operation of ModulesService. For the test environment
these settings are controlled using LocalServiceTestHelper:
-
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 for LocalServiceTestHelper after you call
setUp() do not apply for ModulesService
during your test run.
For simple configurations LocalModulesServiceTestConfig will generate a configuration
based on the current ApiProxy.Environment. The generated
LocalModulesServiceTestConfig 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 .invalid input: '<'minor-version> 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.
LocalServiceTestHelper helper;
@Before
public void createService() {
helper = new LocalServiceTestHelper(new LocalModulesServiceTestConfig());
helper.setEnvModuleId("m1"); // Optional
helper.setEnvVersionId("v2"); // Optional
helper.setEnvInstance("2"); // Optional
helper.setUp();
}
A tester may specify the module versions in the test configuration explicitly
by following these steps.
- Construct a
LocalModulesServiceTestConfig - Add needed module versions with
addDefaultModuleVersion(),addAutomaticScalingModuleVersion(java.lang.String, java.lang.String),addManualScalingModuleVersion(java.lang.String, java.lang.String, int)andaddBasicScalingModuleVersion(java.lang.String, java.lang.String, int). When multiple versions are added for the same module, the first will be the default. - Pass the
LocalModulesServiceTestConfigto theLocalServiceTestHelperconstructor with other neededLocalServiceTestConfigobjects. - Update the test
ApiProxy.Environmentto refer to a configured module instance as needed. - Start the testing environment with
setUp(). Changes made to the configuration after callingsetUp()are not available during your test.
Here is a sample usage:
LocalServiceTestHelper helper;
@Before
public void createService() {
helper = new LocalServiceTestHelper(new LocalModulesServiceTestConfig()
.addDefaultModuleVersion()
.addAutomaticScalingModuleVersion("a1", "v1") // default version for module "a1"
.addManualScalingModuleVersion("m1", "v1", 2) // default version for module "m1"
.addManualScalingModuleVersion("m1", "v2", 3));
helper.setEnvModuleId("m1");
helper.setEnvVersionId("v2");
helper.setEnvInstance("0"); // Optional
helper.setUp();
}
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAutomaticScalingModuleVersion(String module, String version) Adds a automatic scaling module version.addBasicScalingModuleVersion(String module, String version, int numInstances) Adds a basic scaling module version.Adds an automatic scaling module version that matches the defaultApiProxy.Environmentconstructed byLocalServiceTestHelperwith module = "default" and version = "1".addManualScalingModuleVersion(String module, String version, int numInstances) Adds a manual scaling module version.voidClears 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 LocalModulesServiceReturns theLocalModulesServicewhich is created on first use.voidsetUp()Set up the local service.voidtearDown()Tear down the local service.
-
Field Details
-
DEFAULT_MODULE_NAME
- See Also:
-
-
Constructor Details
-
LocalModulesServiceTestConfig
public LocalModulesServiceTestConfig()
-
-
Method Details
-
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(String module, String version) Adds a automatic scaling module version.- Parameters:
module- the module nameversion- the version- Returns:
- this for chaining
- Throws:
IllegalArgumentException- if a module version with the same name and version has already been added.
-
addManualScalingModuleVersion
public LocalModulesServiceTestConfig addManualScalingModuleVersion(String module, 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:
IllegalArgumentException- if a module version with the same name and version has already been added.IllegalArgumentException- if numInstances invalid input: '<'= 0.
-
addBasicScalingModuleVersion
public LocalModulesServiceTestConfig addBasicScalingModuleVersion(String module, 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:
IllegalArgumentException- if a module version with the same name and version has already been added.IllegalArgumentException- if numInstances invalid input: '<'= 0.
-
addDefaultModuleVersion
Adds an automatic scaling module version that matches the defaultApiProxy.Environmentconstructed byLocalServiceTestHelperwith module = "default" and version = "1".- Returns:
- this for chaining
- Throws:
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
Returns theLocalModulesServicewhich is created on first use.
-