Search in sources :

Example 6 with MCRCategoryID

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

Example 7 with MCRCategoryID

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

Example 8 with MCRCategoryID

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

Example 9 with MCRCategoryID

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

Example 10 with MCRCategoryID

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

Aggregations

MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)82 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)42 Test (org.junit.Test)14 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)13 Element (org.jdom2.Element)12 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)11 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)7 HashMap (java.util.HashMap)6 MCRException (org.mycore.common.MCRException)6 EntityManager (javax.persistence.EntityManager)5 Document (org.jdom2.Document)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Collection (java.util.Collection)4 LinkedList (java.util.LinkedList)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)4 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)4