Package foo.domaintest.util

Examples of foo.domaintest.util.Key


    action.run();
    assertEquals(
        new FakeResponse().setPayload(TESTING_URL_BASE + "/temp/token"),
        action.response);
    assertTrue(((FakeResponse) action.response).isResponseSent());
    assertEquals(expectedParams, memcache.load(new Key(STASH, "token")));
  }
View Full Code Here


    assertTrue(((FakeResponse) action.response).isResponseSent());
    assertEquals(expectedParams, memcache.load(new Key(STASH, "token")));
  }

  Map<?, ?> loadMap(String token) {
    return (Map<?, ?>) memcache.load(new Key(STASH, token));
  }
View Full Code Here

            .put("cookiesToDelete", action.cookiesToDelete)
            .put("cookiesToAdd", action.cookiesToAdd)
            .put("headers", action.headers)
            .put("payload", action.payload)
            .build(),
        memcache.load(new Key(STASH, "token")));
  }
View Full Code Here

    expected.put("mimeType", null);
    expected.put("cookiesToDelete", null);
    expected.put("cookiesToAdd", null);
    expected.put("headers", null);
    expected.put("payload", null);
    assertEquals(expected, memcache.load(new Key(STASH, "token")));
  }
View Full Code Here

    assertEquals(20, ((List<String>) loadMap("token").get("cookiesToDelete")).size());
  }

  @Test
  public void testUserProvidedToken() throws Exception {
    memcache.save(new Key(TOKEN, "usertoken"), true, null);
    action.tokenParam = "usertoken";
    action.payload = "foo";
    action.run();
    assertEquals("foo", loadMap("usertoken").get("payload"));
  }
View Full Code Here

  @Test
  public void testTemp() {
    action.response = new FakeResponse();
    memcache.save(
        new Key(STASH, "token"),
        new ImmutableMap.Builder<String, Object>()
            .put("status", 234)
            .put("sleepSeconds", 5)
            .put("mimeType", "a/b")
            .put("cookiesToDelete", ImmutableList.of("x", "y"))
View Full Code Here

    action.run();
    assertEquals(
        new FakeResponse().setPayload("token"),
        action.response);
    assertTrue(((FakeResponse) action.response).isResponseSent());
    assertTrue((boolean) action.memcache.load(new Key(TOKEN, "token")));
  }
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void testStash() {
    action.subject = "test stashtoken";
    memcache.save(new Key(TOKEN, "stashtoken"), true, null);
    action.run();
    verify(emailer).send(
        "tester@testing.example",
        "developer@example.com",
        "http://testing.example/temp/stashtoken",
        null,
        null);
    assertEquals(
        "raw headers",
        ((Map<String, ?>) memcache.load(new Key(STASH, "stashtoken"))).get("payload"));
  }
View Full Code Here

  /** Serve stashed requests. */
  @Override
  @SuppressWarnings("unchecked")
  public void run() {
    String token = Iterables.getLast(Splitter.on('/').split(requestPath), "");
    Map<String, Object> params = memcache.load(new Key(STASH, token));
    if (params == null) {
      throw new NotFoundException("No stashed request for this token");
    } else {
      response
          .setStatus((Integer) params.get("status"))
          .setSleepSeconds((Integer) params.get("sleepSeconds"))
          .setMimeType((String) params.get("mimeType"))
          .setCookiesToDelete((List<String>) params.get("cookiesToDelete"))
          .setCookiesToAdd((Map<String, String>) params.get("cookiesToAdd"))
          .setHeaders((Map<String, String>) params.get("headers"))
          .setPayload((String) params.get("payload"))
          .send();
      memcache.delete(new Key(STASH, token));
    }
  }
View Full Code Here

  public void run() {
    // If there's a valid user-supplied token, use it. If not, get a random one.
    String token;
    if (tokenParam == null) {
      token = lazyRandomToken.get();
    } else if (memcache.load(new Key(TOKEN, tokenParam)) != null) {
      token = tokenParam;
    } else {
      throw new BadRequestException("Invalid token");
    }
    // For safety we truncate all string fields so that an attacker can't blow out our memcache.
    Map<String, Object> params = new HashMap<>();
    params.put("status", status);
    params.put("sleepSeconds", sleepSeconds);
    params.put("mimeType", truncate(mimeType, MIMETYPE_MAX_LENGTH));
    params.put("cookiesToDelete", truncate(cookiesToDelete, MAX_PARAM_REPETITION, NAME_MAX_LENGTH));
    params.put(
        "cookiesToAdd",
        truncate(cookiesToAdd, MAX_PARAM_REPETITION, NAME_MAX_LENGTH, VALUE_MAX_LENGTH));
    params.put(
        "headers",
        truncate(headers, MAX_PARAM_REPETITION, NAME_MAX_LENGTH, VALUE_MAX_LENGTH));
    params.put("payload", truncate(payload, PAYLOAD_MAX_LENGTH));
    memcache.save(new Key(STASH, token), params, STASH_EXPIRATION);
    response.setPayload(tempUrlFactory.getTempUrl(token)).send();
  }
View Full Code Here

TOP

Related Classes of foo.domaintest.util.Key

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.