use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method addCategorySingleSteps.
/**
* Test case for https://sourceforge.net/p/mycore/bugs/612/
*/
@Test
public void addCategorySingleSteps() {
MCRCategory root = new MCRCategoryImpl();
MCRCategoryID rootID = MCRCategoryID.rootID("junit");
root.setId(rootID);
DAO.addCategory(null, root);
startNewTransaction();
MCRCategory a = new MCRCategoryImpl();
MCRCategoryID aId = new MCRCategoryID(rootID.getRootID(), "a");
a.setId(aId);
MCRCategory b = new MCRCategoryImpl();
MCRCategoryID bId = new MCRCategoryID(rootID.getRootID(), "b");
b.setId(bId);
MCRCategory c = new MCRCategoryImpl();
MCRCategoryID cId = new MCRCategoryID(rootID.getRootID(), "c");
c.setId(cId);
DAO.addCategory(rootID, a);
DAO.addCategory(rootID, c);
DAO.addCategory(aId, b);
startNewTransaction();
assertTrue("Category c should not contain child categories.", DAO.getChildren(cId).isEmpty());
assertFalse("Category a should contain child categories.", DAO.getChildren(aId).isEmpty());
root = DAO.getCategory(rootID, -1);
checkLeftRightLevelValue((MCRCategoryImpl) root, 0, 0);
assertEquals("Did not get all categories", 4, countNodes(root));
List<MCRCategory> children = root.getChildren();
assertEquals("Children count mismatch", 2, children.size());
a = children.get(0);
c = children.get(1);
assertEquals("Wrong order of children", aId, a.getId());
assertEquals("Wrong order of children", cId, c.getId());
assertTrue("Category c should not contain child categories.", c.getChildren().isEmpty());
assertFalse("Category a should contain child categories.", a.getChildren().isEmpty());
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method replaceSameCategory.
@Test
public void replaceSameCategory() throws Exception {
loadWorldClassification2();
addWorldClassification();
MCRCategory oldCategory = DAO.getCategory(new MCRCategoryID("World", "Europe"), -1);
DAO.replaceCategory(oldCategory);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method moveRightCategory.
@Test
public void moveRightCategory() throws SQLException {
String rootIDStr = "rootID";
MCRCategoryID rootID = MCRCategoryID.rootID(rootIDStr);
MCRCategoryID child1ID = new MCRCategoryID(rootIDStr, "child1");
MCRCategoryID child2ID = new MCRCategoryID(rootIDStr, "child2");
MCRCategoryID child3ID = new MCRCategoryID(rootIDStr, "child3");
MCRCategoryImpl root = newCategory(rootID, "root node");
addChild(root, newCategory(child1ID, "child node 1"));
addChild(root, newCategory(child2ID, "child node 2"));
addChild(root, newCategory(child3ID, "child node 3"));
startNewTransaction();
DAO.addCategory(null, root);
endTransaction();
startNewTransaction();
printCategoryTable();
endTransaction();
assertLeftRightVal(rootID, 0, 7);
assertLeftRightVal(child1ID, 1, 2);
assertLeftRightVal(child2ID, 3, 4);
assertLeftRightVal(child3ID, 5, 6);
startNewTransaction();
DAO.moveCategory(child2ID, child1ID, 0);
DAO.moveCategory(child3ID, child1ID, 1);
endTransaction();
startNewTransaction();
printCategoryTable();
endTransaction();
assertLeftRightVal(rootID, 0, 7);
assertLeftRightVal(child1ID, 1, 6);
assertLeftRightVal(child2ID, 2, 3);
assertLeftRightVal(child3ID, 4, 5);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method getRootCategoryIDs.
@Test
public void getRootCategoryIDs() {
addWorldClassification();
MCRCategoryID find = category.getId();
List<MCRCategoryID> classIds = DAO.getRootCategoryIDs();
assertEquals("Result size does not match.", 1, classIds.size());
assertEquals("Returned MCRCategoryID does not match.", find, classIds.get(0));
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method moveCategoryUp.
@Test
public void moveCategoryUp() {
String rootIDStr = "rootID";
MCRCategoryID rootID = MCRCategoryID.rootID(rootIDStr);
MCRCategoryID child1ID = new MCRCategoryID(rootIDStr, "child1");
MCRCategoryID child2ID = new MCRCategoryID(rootIDStr, "child2");
MCRCategoryImpl root = newCategory(rootID, "root node");
MCRCategoryImpl child1 = newCategory(child1ID, "child node 1");
addChild(root, child1);
addChild(child1, newCategory(child2ID, "child node 2"));
startNewTransaction();
DAO.addCategory(null, root);
endTransaction();
assertLeftRightVal(rootID, 0, 5);
assertLeftRightVal(child1ID, 1, 4);
assertLeftRightVal(child2ID, 2, 3);
startNewTransaction();
DAO.moveCategory(child2ID, rootID);
endTransaction();
startNewTransaction();
printCategoryTable();
endTransaction();
assertLeftRightVal(rootID, 0, 5);
assertLeftRightVal(child1ID, 1, 2);
assertLeftRightVal(child2ID, 3, 4);
}
Aggregations