Search in sources :

Example 11 with MCRCategory

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 12 with MCRCategory

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;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Example 13 with MCRCategory

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);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 14 with MCRCategory

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));
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 15 with MCRCategory

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Test(org.junit.Test)

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)87 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)36 Test (org.junit.Test)24 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)17 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)10 ArrayList (java.util.ArrayList)9 Document (org.jdom2.Document)9 Element (org.jdom2.Element)8 MCRException (org.mycore.common.MCRException)8 IOException (java.io.IOException)6 EntityManager (javax.persistence.EntityManager)6 URI (java.net.URI)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4