public void testInvalidEntryNoType() throws Exception {
    CollectionItem collection = helper.makeAndStoreDummyCollection();
    Ticket ticket = new HibTicket();
    ticket.setKey("invalidEntryNoTypeTicket");
    ticket.setKey("foo");
    RequestContext req = createRequestContext(collection, ticket);

    ResponseContext res = adapter.postEntry(req);
    assertNotNull("Null response context", res);
    assertEquals("Incorrect response status", 400, 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 {
    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 #4
0
  public void testTickets() throws Exception {
    User testuser = getUser(userDao, "testuser");
    String name = "ticketable:" + System.currentTimeMillis();
    ContentItem item = generateTestContent(name, "testuser");

    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser);
    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();
    newItem = contentDao.findContentByUid(newItem.getUid());

    Ticket ticket1 = new HibTicket();
    ticket1.setKey("ticket1");
    ticket1.setTimeout(10);
    ticket1.setOwner(testuser);
    HashSet privs = new HashSet();
    privs.add("priv1");
    privs.add("privs2");
    ticket1.setPrivileges(privs);

    contentDao.createTicket(newItem, ticket1);

    Ticket ticket2 = new HibTicket();
    ticket2.setKey("ticket2");
    ticket2.setTimeout(100);
    ticket2.setOwner(testuser);
    privs = new HashSet();
    privs.add("priv3");
    privs.add("priv4");
    ticket2.setPrivileges(privs);

    contentDao.createTicket(newItem, ticket2);

    clearSession();

    newItem = contentDao.findContentByUid(newItem.getUid());

    Ticket queryTicket1 = contentDao.getTicket(newItem, "ticket1");
    Assert.assertNotNull(queryTicket1);
    verifyTicket(queryTicket1, ticket1);

    Collection tickets = contentDao.getTickets(newItem);
    Assert.assertEquals(2, tickets.size());
    verifyTicketInCollection(tickets, ticket1.getKey());
    verifyTicketInCollection(tickets, ticket2.getKey());

    contentDao.removeTicket(newItem, ticket1);
    clearSession();

    newItem = contentDao.findContentByUid(newItem.getUid());

    tickets = contentDao.getTickets(newItem);
    Assert.assertEquals(1, tickets.size());
    verifyTicketInCollection(tickets, ticket2.getKey());

    queryTicket1 = contentDao.getTicket(newItem, "ticket1");
    Assert.assertNull(queryTicket1);

    Ticket queryTicket2 = contentDao.getTicket(newItem, "ticket2");
    Assert.assertNotNull(queryTicket2);
    verifyTicket(queryTicket2, ticket2);

    contentDao.removeTicket(newItem, ticket2);

    clearSession();
    newItem = contentDao.findContentByUid(newItem.getUid());

    tickets = contentDao.getTickets(newItem);
    Assert.assertEquals(0, tickets.size());
  }