com.google.appengine.tools.development.testing.LocalURLFetchServiceTestConfig Java Examples

The following examples show how to use com.google.appengine.tools.development.testing.LocalURLFetchServiceTestConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppEngineRule.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
protected void before() throws IOException {
  setupLogging();
  temporaryFolder.create();
  Set<LocalServiceTestConfig> configs = new HashSet<>();
  if (withUrlFetch) {
    configs.add(new LocalURLFetchServiceTestConfig());
  }
  if (withDatastore) {
    configs.add(new LocalDatastoreServiceTestConfig()
        // We need to set this to allow cross entity group transactions.
        .setApplyAllHighRepJobPolicy()
        // This causes unit tests to write a file containing any indexes the test required. We
        // can use that file below to make sure we have the right indexes in our prod code.
        .setNoIndexAutoGen(false));
    // This forces app engine to write the generated indexes to a usable location.
    System.setProperty("appengine.generated.dir", temporaryFolder.getRoot().getAbsolutePath());
  }
  if (withLocalModules) {
    configs.add(new LocalModulesServiceTestConfig()
        .addBasicScalingModuleVersion("default", "1", 1)
        .addBasicScalingModuleVersion("tools", "1", 1)
        .addBasicScalingModuleVersion("backend", "1", 1));
  }
  if (withTaskQueue) {
    File queueFile = temporaryFolder.newFile("queue.xml");
    Files.asCharSink(queueFile, UTF_8).write(taskQueueXml);
    configs.add(new LocalTaskQueueTestConfig()
        .setQueueXmlPath(queueFile.getAbsolutePath()));
  }
  if (withUserService) {
    configs.add(new LocalUserServiceTestConfig());
  }

  helper = new LocalServiceTestHelper(configs.toArray(new LocalServiceTestConfig[]{}));

  if (withUserService) {
    // Set top-level properties on LocalServiceTestConfig for user login.
    helper
        .setEnvIsLoggedIn(userInfo.isLoggedIn())
        // This envAttributes thing is the only way to set userId.
        // see https://code.google.com/p/googleappengine/issues/detail?id=3579
        .setEnvAttributes(
            ImmutableMap.of(
                "com.google.appengine.api.users.UserService.user_id_key", userInfo.gaeUserId()))
        .setEnvAuthDomain(userInfo.authDomain())
        .setEnvEmail(userInfo.email())
        .setEnvIsAdmin(userInfo.isAdmin());
  }

  if (clock != null) {
    helper.setClock(() -> clock.nowUtc().getMillis());
  }

  if (withLocalModules) {
    helper.setEnvInstance("0");
  }

  helper.setUp();

  if (withDatastore) {
    ObjectifyService.initOfy();
    // Reset id allocation in ObjectifyService so that ids are deterministic in tests.
    ObjectifyService.resetNextTestId();
    if (!withoutCannedData) {
      loadInitialData();
    }
    this.ofyTestEntities.forEach(AppEngineRule::register);
  }
}