コード例 #1
0
  public void testFindItem() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");

    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    clearSession();

    Item queryItem = contentDao.findItemByUid(a.getUid());
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof CollectionItem);

    queryItem = contentDao.findItemByPath("/testuser2/a");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof CollectionItem);

    ContentItem item = generateTestContent();

    a = contentDao.findCollectionByUid(a.getUid());
    item = contentDao.createContent(a, item);

    clearSession();

    queryItem = contentDao.findItemByPath("/testuser2/a/test");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof ContentItem);

    clearSession();

    queryItem = contentDao.findItemParentByPath("/testuser2/a/test");
    Assert.assertNotNull(queryItem);
    Assert.assertEquals(a.getUid(), queryItem.getUid());
  }
コード例 #2
0
  public void testItemDaoMove() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    CollectionItem b = new HibCollectionItem();
    b.setName("b");
    b.setOwner(getUser(userDao, "testuser2"));

    b = contentDao.createCollection(a, b);

    CollectionItem c = new HibCollectionItem();
    c.setName("c");
    c.setOwner(getUser(userDao, "testuser2"));

    c = contentDao.createCollection(b, c);

    ContentItem d = generateTestContent("d", "testuser2");

    d = contentDao.createContent(c, d);

    CollectionItem e = new HibCollectionItem();
    e.setName("e");
    e.setOwner(getUser(userDao, "testuser2"));

    e = contentDao.createCollection(a, e);

    clearSession();

    root = (CollectionItem) contentDao.getRootItem(testuser2);
    e = contentDao.findCollectionByUid(e.getUid());
    b = contentDao.findCollectionByUid(b.getUid());

    // verify can't move root collection
    try {
      contentDao.moveItem("/testuser2", "/testuser2/a/blah");
      Assert.fail("able to move root collection");
    } catch (IllegalArgumentException iae) {
    }

    // verify can't move to root collection
    try {
      contentDao.moveItem("/testuser2/a/e", "/testuser2");
      Assert.fail("able to move to root collection");
    } catch (ItemNotFoundException infe) {
    }

    // verify can't create loop
    try {
      contentDao.moveItem("/testuser2/a/b", "/testuser2/a/b/c/new");
      Assert.fail("able to create loop");
    } catch (ModelValidationException iae) {
    }

    clearSession();

    // verify that move works
    b = contentDao.findCollectionByPath("/testuser2/a/b");

    contentDao.moveItem("/testuser2/a/b", "/testuser2/a/e/b");

    clearSession();

    CollectionItem queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/b");
    Assert.assertNotNull(queryCollection);

    contentDao.moveItem("/testuser2/a/e/b", "/testuser2/a/e/bnew");

    clearSession();
    queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bnew");
    Assert.assertNotNull(queryCollection);

    Item queryItem = contentDao.findItemByPath("/testuser2/a/e/bnew/c/d");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof ContentItem);
  }
コード例 #3
0
  public void testContentDaoAdvanced() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    CollectionItem b = new HibCollectionItem();
    b.setName("b");
    b.setOwner(getUser(userDao, "testuser2"));

    b = contentDao.createCollection(a, b);

    ContentItem c = generateTestContent("c", "testuser2");

    c = contentDao.createContent(b, c);

    ContentItem d = generateTestContent("d", "testuser2");

    d = contentDao.createContent(a, d);

    clearSession();

    a = contentDao.findCollectionByUid(a.getUid());
    b = contentDao.findCollectionByUid(b.getUid());
    c = contentDao.findContentByUid(c.getUid());
    d = contentDao.findContentByUid(d.getUid());
    root = contentDao.getRootItem(testuser2);

    Assert.assertNotNull(a);
    Assert.assertNotNull(b);
    Assert.assertNotNull(d);
    Assert.assertNotNull(root);

    // test children
    Collection children = a.getChildren();
    Assert.assertEquals(2, children.size());
    verifyContains(children, b);
    verifyContains(children, d);

    children = root.getChildren();
    Assert.assertEquals(1, children.size());
    verifyContains(children, a);

    // test get by path
    ContentItem queryC = contentDao.findContentByPath("/testuser2/a/b/c");
    Assert.assertNotNull(queryC);
    helper.verifyInputStream(
        helper.getInputStream("testdata1.txt"), ((FileItem) queryC).getContent());
    Assert.assertEquals("c", queryC.getName());

    // test get path/uid abstract
    Item queryItem = contentDao.findItemByPath("/testuser2/a/b/c");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof ContentItem);

    queryItem = contentDao.findItemByUid(a.getUid());
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof CollectionItem);

    // test delete
    contentDao.removeContent(c);
    queryC = contentDao.findContentByUid(c.getUid());
    Assert.assertNull(queryC);

    contentDao.removeCollection(a);

    CollectionItem queryA = contentDao.findCollectionByUid(a.getUid());
    Assert.assertNull(queryA);

    ContentItem queryD = contentDao.findContentByUid(d.getUid());
    Assert.assertNull(queryD);
  }