com.google.appengine.tools.development.testing

## 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 the `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`:

  1. `LocalServiceTestHelper.setEnvModuleId(java.lang.String)` specifies the result returned by `ModulesService.getCurrentModule()`. The default module is "default".
  2. `LocalServiceTestHelper.setEnvVersionId(java.lang.String)` specifies the result returned by `ModulesService.getCurrentVersion()`. The default version is "1".
  3. `LocalServiceTestHelper.setEnvInstance(java.lang.String)` specifies the result returned by `ModulesService.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:

  1. 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.
  2. 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.
  3. 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.
  To configure a test to use ModulesService with a generated configuration perform these steps in the order given.
  1. Construct a `LocalModulesServiceTestConfig`
  2. Pass the `LocalModulesServiceTestConfig` to the `LocalServiceTestHelper` constructor with other needed `LocalServiceTestConfig` objects.
  3. Update the test `ApiProxy.Environment` to refer to a desired module, version and instance (if needed).
  4. Start the testing environment with `setUp()` and execute your test.
  Here is a sample usage:

      {@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 default `ApiProxy.Environment` constructed by `LocalServiceTestHelper` 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 with `addAutomaticScalingModuleVersion(java.lang.String, java.lang.String)`, `addBasicScalingModuleVersion(java.lang.String, java.lang.String, int)`, `addManualScalingModuleVersion(java.lang.String, java.lang.String, int)` and `addDefaultModuleVersion()`.
    `static LocalModulesService` | `getLocalModulesService()` Returns the `LocalModulesService` which is created on first use.
    `void` | `setUp()` Set up the local service.
    `void` | `tearDown()` Tear down the local service.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_MODULE_NAME

          public static final java.lang.String DEFAULT_MODULE_NAME

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LocalModulesServiceTestConfig

          public LocalModulesServiceTestConfig()

  - ### Method Detail

    - #### setUp

          public void setUp()

      Description copied from interface: `LocalServiceTestConfig`
      Set up the local service.
      Specified by:
        `setUp` in interface `LocalServiceTestConfig`

    - #### tearDown

          public void tearDown()

      Description copied from interface: `LocalServiceTestConfig`
      Tear down the local service.
      Specified by:
        `tearDown` in interface `LocalServiceTestConfig`

    - #### addAutomaticScalingModuleVersion

          public LocalModulesServiceTestConfig addAutomaticScalingModuleVersion(java.lang.String module,
                                                                                java.lang.String version)

      Adds a automatic scaling module version.
      Parameters:
        `module` - the module name
        `version` - 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 name
        `version` - the version
        `numInstances` - 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 name
        `version` - the version
        `numInstances` - 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 default `ApiProxy.Environment` constructed by `LocalServiceTestHelper` 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 with `addAutomaticScalingModuleVersion(java.lang.String, java.lang.String)`, `addBasicScalingModuleVersion(java.lang.String, java.lang.String, int)`, `addManualScalingModuleVersion(java.lang.String, java.lang.String, int)` and `addDefaultModuleVersion()`.

    - #### getLocalModulesService

          public static LocalModulesService getLocalModulesService()

      Returns the `LocalModulesService` which is created on first use.