public void testItemInMutipleCollectionsDeleteCollection() throws Exception { User user = getUser(userDao, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); CollectionItem a = new HibCollectionItem(); a.setName("a"); a.setOwner(user); a = contentDao.createCollection(root, a); ContentItem item = generateTestContent(); item.setName("test"); ContentItem newItem = contentDao.createContent(a, item); clearSession(); ContentItem queryItem = contentDao.findContentByUid(newItem.getUid()); Assert.assertEquals(queryItem.getParents().size(), 1); CollectionItem b = new HibCollectionItem(); b.setName("b"); b.setOwner(user); b = contentDao.createCollection(root, b); contentDao.addItemToCollection(queryItem, b); clearSession(); queryItem = contentDao.findContentByUid(newItem.getUid()); Assert.assertEquals(queryItem.getParents().size(), 2); b = contentDao.findCollectionByUid(b.getUid()); contentDao.removeCollection(b); clearSession(); b = contentDao.findCollectionByUid(b.getUid()); queryItem = contentDao.findContentByUid(newItem.getUid()); Assert.assertNull(b); Assert.assertEquals(queryItem.getParents().size(), 1); a = contentDao.findCollectionByUid(a.getUid()); contentDao.removeCollection(a); clearSession(); a = contentDao.findCollectionByUid(a.getUid()); queryItem = contentDao.findContentByUid(newItem.getUid()); Assert.assertNull(a); Assert.assertNull(queryItem); }
public void testContentDaoUpdateCollection() throws Exception { User user = getUser(userDao, "testuser2"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); CollectionItem a = new HibCollectionItem(); a.setName("a"); a.setOwner(user); a = contentDao.createCollection(root, a); clearSession(); Assert.assertTrue(getHibItem(a).getId() > -1); Assert.assertNotNull(a.getUid()); CollectionItem queryItem = contentDao.findCollectionByUid(a.getUid()); helper.verifyItem(a, queryItem); queryItem.setName("b"); contentDao.updateCollection(queryItem); clearSession(); queryItem = contentDao.findCollectionByUid(a.getUid()); Assert.assertEquals("b", queryItem.getName()); }
/** * Gets collection. * * @param parent The parent. * @param name The name. * @return The collection item. * @throws Exception - if something is wrong this exception is thrown. */ private CollectionItem getCollection(CollectionItem parent, String name) throws Exception { for (Item child : (Set<Item>) parent.getChildren()) { if (child.getName().equals(name)) { return (CollectionItem) child; } } CollectionItem collection = new HibCollectionItem(); collection.setName(name); collection.setDisplayName(name); collection.setOwner(parent.getOwner()); return contentDao.createCollection(parent, collection); }
public void testContentDaoUpdateCollectionTimestamp() throws Exception { User user = getUser(userDao, "testuser2"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); CollectionItem a = new HibCollectionItem(); a.setName("a"); a.setOwner(user); a = contentDao.createCollection(root, a); Integer ver = a.getVersion(); Date timestamp = a.getModifiedDate(); clearSession(); Thread.sleep(1); a = contentDao.updateCollectionTimestamp(a); Assert.assertTrue(a.getVersion() == ver + 1); Assert.assertTrue(timestamp.before(a.getModifiedDate())); }
public void testContentDaoDeleteCollection() throws Exception { User user = getUser(userDao, "testuser2"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); CollectionItem a = new HibCollectionItem(); a.setName("a"); a.setOwner(user); a = contentDao.createCollection(root, a); clearSession(); CollectionItem queryItem = contentDao.findCollectionByUid(a.getUid()); Assert.assertNotNull(queryItem); contentDao.removeCollection(queryItem); clearSession(); queryItem = contentDao.findCollectionByUid(a.getUid()); Assert.assertNull(queryItem); }
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()); }
public void testItemDaoCopy() 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 copy root collection try { contentDao.copyItem(root, "/testuser2/a/blah", true); Assert.fail("able to copy root collection"); } catch (IllegalArgumentException iae) { } // verify can't move to root collection try { contentDao.copyItem(e, "/testuser2", true); Assert.fail("able to move to root collection"); } catch (ItemNotFoundException infe) { } // verify can't create loop try { contentDao.copyItem(b, "/testuser2/a/b/c/new", true); Assert.fail("able to create loop"); } catch (ModelValidationException iae) { } clearSession(); // verify that copy works b = contentDao.findCollectionByPath("/testuser2/a/b"); contentDao.copyItem(b, "/testuser2/a/e/bcopy", true); clearSession(); CollectionItem queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopy"); Assert.assertNotNull(queryCollection); queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopy/c"); Assert.assertNotNull(queryCollection); d = contentDao.findContentByUid(d.getUid()); ContentItem dcopy = contentDao.findContentByPath("/testuser2/a/e/bcopy/c/d"); Assert.assertNotNull(dcopy); Assert.assertEquals(d.getName(), dcopy.getName()); Assert.assertNotSame(d.getUid(), dcopy.getUid()); helper.verifyBytes(((FileItem) d).getContent(), ((FileItem) dcopy).getContent()); clearSession(); b = contentDao.findCollectionByPath("/testuser2/a/b"); contentDao.copyItem(b, "/testuser2/a/e/bcopyshallow", false); clearSession(); queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopyshallow"); Assert.assertNotNull(queryCollection); queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopyshallow/c"); Assert.assertNull(queryCollection); clearSession(); d = contentDao.findContentByUid(d.getUid()); contentDao.copyItem(d, "/testuser2/dcopy", true); clearSession(); dcopy = contentDao.findContentByPath("/testuser2/dcopy"); Assert.assertNotNull(dcopy); }
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); }
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); }
public void testContentDaoUpdateCollectionWithMods() throws Exception { User user = getUser(userDao, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); NoteItem note1 = generateTestNote("test1", "testuser"); NoteItem note2 = generateTestNote("test2", "testuser"); note1.setUid("1"); note2.setUid("1:20070101"); note2.setModifies(note1); Set<ContentItem> items = new LinkedHashSet<ContentItem>(); items.add(note2); items.add(note1); // should fail because modification is processed before master try { contentDao.updateCollection(root, items); Assert.fail("able to create invalid mod"); } catch (ModelValidationException e) { } items.clear(); // now make sure master is processed before mod items.add(note1); items.add(note2); contentDao.updateCollection(root, items); note1 = (NoteItem) contentDao.findContentByUid("1"); Assert.assertNotNull(note1); Assert.assertTrue(1 == note1.getModifications().size()); note2 = (NoteItem) contentDao.findContentByUid("1:20070101"); Assert.assertNotNull(note2); Assert.assertNotNull(note2.getModifies()); // now create new collection CollectionItem a = new HibCollectionItem(); a.setUid("a"); a.setName("a"); a.setOwner(user); a = contentDao.createCollection(root, a); // try to add mod to another collection before adding master items.clear(); items.add(note2); // should fail because modification is added before master try { contentDao.updateCollection(a, items); Assert.fail("able to add mod before master"); } catch (ModelValidationException e) { } items.clear(); items.add(note1); items.add(note2); contentDao.updateCollection(a, items); // now create new collection CollectionItem b = new HibCollectionItem(); b.setUid("b"); b.setName("b"); b.setOwner(user); b = contentDao.createCollection(root, b); // only add master items.clear(); items.add(note1); contentDao.updateCollection(b, items); // adding master should add mods too clearSession(); b = contentDao.findCollectionByUid("b"); Assert.assertNotNull(b); Assert.assertEquals(2, b.getChildren().size()); }