public void testInvalidEntryNoKey() throws Exception {
    Preference pref = new HibPreference(null, "new value");
    RequestContext req = createRequestContext(pref);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 400, res.getStatus());
  }
  public void testEntryNoValue() throws Exception {
    Preference pref = new HibPreference("new key", null);
    RequestContext req = createRequestContext(pref);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 201, res.getStatus());
  }
  public void testEntryExists() throws Exception {
    Preference pref = helper.makeAndStoreDummyPreference();
    RequestContext req = createRequestContext(pref);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 409, res.getStatus());
  }
  public void testInvalidEntryNoKey() throws Exception {
    CollectionItem collection = helper.makeAndStoreDummyCollection();
    Ticket ticket = new HibTicket(TicketType.READ_ONLY);
    RequestContext req = createRequestContext(collection, ticket);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 400, res.getStatus());
  }
  public void testEntryExists() throws Exception {
    CollectionItem collection = helper.makeAndStoreDummyCollection();
    Ticket ticket = helper.makeAndStoreDummyTicket(collection);
    RequestContext req = createRequestContext(collection, ticket);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 409, res.getStatus());
  }
  public void testGenerationError() throws Exception {
    Preference pref = helper.makeDummyPreference();
    RequestContext req = createRequestContext(pref);
    helper.enableGeneratorFailure();

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 500, res.getStatus());
  }
  public void testGenerationError() throws Exception {
    CollectionItem collection = helper.makeAndStoreDummyCollection();
    Ticket ticket = helper.makeDummyTicket();
    ticket.setKey("generationTicket");
    RequestContext req = createRequestContext(collection, ticket);
    helper.enableGeneratorFailure();

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 500, res.getStatus());
  }
  public void testCreateEntry() throws Exception {
    Preference pref = helper.makeDummyPreference();
    RequestContext req = createRequestContext(pref);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 201, res.getStatus());
    assertNotNull("Null etag", res.getEntityTag());
    // disable last modified check til mock dao bumps modified date
    // assertNotNull("Null last modified", res.getLastModified());
    assertNotNull("Null Location header", res.getHeader("Location"));
    assertNotNull("Null Content-Location header", res.getHeader("Content-Location"));

    String username = helper.getUser().getUsername();
    Preference saved = helper.getUserService().getUser(username).getPreference(pref.getKey());
    assertNotNull("Preference not saved", saved);
    assertEquals("Wrong key", pref.getKey(), saved.getKey());
    assertEquals("Wrong value", pref.getValue(), saved.getValue());
  }
  public void testCreateEntry() throws Exception {
    CollectionItem collection = helper.makeAndStoreDummyCollection();
    Ticket ticket = helper.makeDummyTicket();
    ticket.setKey("createEntryTicket");

    RequestContext req = createRequestContext(collection, ticket);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 201, res.getStatus());
    assertNotNull("Null etag", res.getEntityTag());
    // disable last modified check til mock dao bumps modified date
    // assertNotNull("Null last modified", res.getLastModified());
    assertNotNull("Null Location header", res.getHeader("Location"));
    assertNotNull("Null Content-Location header", res.getHeader("Content-Location"));

    String username = helper.getUser().getUsername();
    Ticket saved = helper.getContentService().getTicket(collection, ticket.getKey());
    assertNotNull("Ticket not saved", saved);
    assertEquals("Wrong key", ticket.getKey(), saved.getKey());
    assertEquals("Wrong type", ticket.getType(), saved.getType());
  }
Example #10
0
 protected ResponseContext getCanonicalRedirect(Agent agent) {
   String location = getId(agent);
   ResponseContext response = new EmptyResponseContext(303, "Agent found with email address");
   response.setLocation(location);
   return response;
 }