use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method replaceCategoryShiftCase.
/**
* tests relink child to grandparent and removal of parent.
*/
@Test
public void replaceCategoryShiftCase() {
addWorldClassification();
MCRCategory europe = category.getChildren().get(0);
MCRCategory germany = europe.getChildren().get(0);
europe.getChildren().remove(0);
assertNull("Germany should not have a parent right now", germany.getParent());
category.getChildren().remove(0);
assertNull("Europe should not have a parent right now", europe.getParent());
category.getChildren().add(germany);
assertEquals("Germany should not have world as parent right now", category.getId(), germany.getParent().getId());
DAO.replaceCategory(category);
startNewTransaction();
MCRCategory rootNode = getRootCategoryFromSession();
assertEquals("Category count does not match.", countNodes(category), countNodes(rootNode));
assertEquals("Label count does not match.", category.getChildren().get(0).getLabels().size(), rootNode.getChildren().get(0).getLabels().size());
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method checkLeftRightLevelValue.
private int checkLeftRightLevelValue(MCRCategoryImpl node, int leftStart, int levelStart) {
int curValue = leftStart;
final int nextLevel = levelStart + 1;
assertEquals("Left value did not match on ID: " + node.getId(), leftStart, node.getLeft());
assertEquals("Level value did not match on ID: " + node.getId(), levelStart, node.getLevel());
for (MCRCategory child : node.getChildren()) {
curValue = checkLeftRightLevelValue((MCRCategoryImpl) child, ++curValue, nextLevel);
}
assertEquals("Right value did not match on ID: " + node.getId(), ++curValue, node.getRight());
return curValue;
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method deleteSubCategory.
@Test
public void deleteSubCategory() {
addWorldClassification();
MCRCategory deleteCategory = category.getChildren().get(0);
assertTrue("Sub category does not exist.", DAO.exist(deleteCategory.getId()));
testDelete(deleteCategory);
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method getRootCategory.
@Test
public void getRootCategory() {
addWorldClassification();
// Europe
MCRCategory find = category.getChildren().get(0);
MCRCategory rootCategory = DAO.getRootCategory(find.getId(), 0);
assertEquals("Category count does not match.", 2, countNodes(rootCategory));
assertEquals("Did not get root Category.", find.getRoot().getId(), rootCategory.getId());
rootCategory = DAO.getRootCategory(find.getId(), -1);
assertEquals("Category count does not match.", 1 + countNodes(find), countNodes(rootCategory));
}
use of org.mycore.datamodel.classifications2.MCRCategory 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());
}
Aggregations