Search in sources :

Example 6 with MCRCategoryImpl

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

Example 7 with MCRCategoryImpl

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

Example 8 with MCRCategoryImpl

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

Example 9 with MCRCategoryImpl

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

Example 10 with MCRCategoryImpl

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

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)17 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)17 Test (org.junit.Test)15 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)10 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)7 EntityManager (javax.persistence.EntityManager)6 HashMap (java.util.HashMap)4 MCRException (org.mycore.common.MCRException)4 MCRPersistenceException (org.mycore.common.MCRPersistenceException)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 AbstractMap (java.util.AbstractMap)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 BiConsumer (java.util.function.BiConsumer)2 Consumer (java.util.function.Consumer)2