use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl 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.impl.MCRCategoryImpl 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);
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryImplTest method calculateLeftRightAndLevel.
/**
* Test method for {@link org.mycore.datamodel.classifications2.impl.MCRCategoryImpl#calculateLeftRightAndLevel(int, int)}.
*/
@Test
public void calculateLeftRightAndLevel() {
MCRCategoryImpl rootNode = buildNode(MCRCategoryID.rootID("co1"));
final int leftStart = 1;
final int levelStart = 0;
assertEquals(2, rootNode.calculateLeftRightAndLevel(leftStart, levelStart));
assertEquals(levelStart, rootNode.getLevel());
MCRCategoryImpl co2 = buildNode(new MCRCategoryID(rootNode.getId().getRootID(), "co2"));
rootNode.getChildren().add(co2);
assertEquals(4, rootNode.calculateLeftRightAndLevel(leftStart, levelStart));
assertEquals(leftStart, co2.getLevel());
MCRCategoryImpl co3 = buildNode(new MCRCategoryID(rootNode.getId().getRootID(), "co3"));
rootNode.getChildren().add(co3);
assertEquals(6, rootNode.calculateLeftRightAndLevel(leftStart, levelStart));
assertEquals(leftStart, co3.getLevel());
MCRCategoryImpl co4 = buildNode(new MCRCategoryID(rootNode.getId().getRootID(), "co4"));
co3.getChildren().add(co4);
assertEquals(8, rootNode.calculateLeftRightAndLevel(leftStart, levelStart));
assertEquals(2, co4.getLevel());
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryImplTest method getLeftSiblingOrOfAncestor.
@Test
public void getLeftSiblingOrOfAncestor() throws URISyntaxException, MCRException, SAXParseException, IOException {
loadWorldClassification();
MCRCategory europe = category.getChildren().get(0);
MCRCategoryImpl asia = (MCRCategoryImpl) category.getChildren().get(1);
MCRCategoryImpl germany = (MCRCategoryImpl) europe.getChildren().get(0);
assertEquals("Did not get Europe as left sibling of Asia", europe.getId(), asia.getLeftSiblingOrOfAncestor().getId());
assertEquals("Did not get World as left sibling or ancestor of Germany", category.getId(), germany.getLeftSiblingOrOfAncestor().getId());
MCRCategoryImpl america = buildNode(new MCRCategoryID(category.getRootID(), "America"));
category.getChildren().add(0, america);
assertEquals("Did not get America as left sibling or ancestor of Germany", america.getId(), germany.getLeftSiblingOrOfAncestor().getId());
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryImplTest method getLeftSiblingOrParent.
@Test
public void getLeftSiblingOrParent() throws URISyntaxException, MCRException, SAXParseException, IOException {
loadWorldClassification();
MCRCategory europe = category.getChildren().get(0);
MCRCategoryImpl asia = (MCRCategoryImpl) category.getChildren().get(1);
MCRCategoryImpl germany = (MCRCategoryImpl) europe.getChildren().get(0);
assertEquals("Did not get Europe as left sibling of Asia", europe.getId(), asia.getLeftSiblingOrParent().getId());
assertEquals("Did not get Europa as left sibling or ancestor of Germany", europe.getId(), germany.getLeftSiblingOrParent().getId());
}
Aggregations