Search in sources :

Example 51 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method testReplaceCategoryNewParent.

/**
 * tests top category child to new parent
 */
public void testReplaceCategoryNewParent() {
    addWorldClassification();
    MCRCategory europe = category.getChildren().get(0);
    MCRCategoryImpl test = new MCRCategoryImpl();
    test.setId(new MCRCategoryID(category.getId().getRootID(), "test"));
    test.setLabels(new HashSet<>());
    test.getLabels().add(new MCRLabel("de", "JUnit testcase", null));
    category.getChildren().add(test);
    category.getChildren().remove(0);
    test.getChildren().add(europe);
    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) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 52 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method testLicenses.

@Test
public void testLicenses() throws Exception {
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL("http://mycore.de/classifications/mir_licenses.xml")));
    MCRCategory licenses = MCRXMLTransformer.getCategory(xml);
    DAO.addCategory(null, licenses);
    MCRCategoryID cc_30 = new MCRCategoryID(licenses.getId().getRootID(), "cc_3.0");
    DAO.deleteCategory(cc_30);
    startNewTransaction();
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) Test(org.junit.Test)

Example 53 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method addCategoryToPosition.

/**
 * Test case for https://sourceforge.net/p/mycore/bugs/664/
 */
@Test
public void addCategoryToPosition() {
    addWorldClassification();
    MCRCategoryImpl america = new MCRCategoryImpl();
    MCRCategoryID categoryID = new MCRCategoryID(category.getId().getRootID(), "America");
    america.setId(categoryID);
    america.setLabels(new HashSet<>());
    america.getLabels().add(new MCRLabel("de", "Amerika", null));
    america.getLabels().add(new MCRLabel("en", "America", null));
    DAO.addCategory(category.getId(), america, 1);
    startNewTransaction();
    america = MCRCategoryDAOImpl.getByNaturalID(getEntityManager().get(), america.getId());
    assertNotNull(categoryID + " was not added to database.", america);
    assertEquals("invalid position in parent", 1, america.getPositionInParent());
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 54 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method addCategory.

@Test
public void addCategory() throws MCRException {
    addWorldClassification();
    assertTrue("Exist check failed for Category " + category.getId(), DAO.exist(category.getId()));
    MCRCategoryImpl india = new MCRCategoryImpl();
    india.setId(new MCRCategoryID(category.getId().getRootID(), "India"));
    india.setLabels(new HashSet<>());
    india.getLabels().add(new MCRLabel("de", "Indien", null));
    india.getLabels().add(new MCRLabel("en", "India", null));
    DAO.addCategory(new MCRCategoryID(category.getId().getRootID(), "Asia"), india);
    startNewTransaction();
    assertTrue("Exist check failed for Category " + india.getId(), DAO.exist(india.getId()));
    MCRCategoryImpl rootCategory = getRootCategoryFromSession();
    assertEquals("Child category count does not match.", category.getChildren().size(), rootCategory.getChildren().size());
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Number> countQuery = cb.createQuery(Number.class);
    long allNodes = em.createQuery(countQuery.select(cb.count(countQuery.from(MCRCategoryImpl.class)))).getSingleResult().longValue();
    // category + india
    assertEquals("Complete category count does not match.", countNodes(category) + 1, allNodes);
    assertTrue("No root category present", rootCategory.getRoot() != null);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 55 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImplTest method moveCategoryDeep.

@Test
public void moveCategoryDeep() {
    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");
    MCRCategoryID child4ID = new MCRCategoryID(rootIDStr, "child4");
    MCRCategoryImpl root = newCategory(rootID, "root node");
    MCRCategoryImpl a = newCategory(child1ID, "child node 1");
    MCRCategoryImpl aa = newCategory(child2ID, "child node 2");
    MCRCategoryImpl aaa = newCategory(child3ID, "child node 3");
    MCRCategoryImpl aab = newCategory(child4ID, "child node 4");
    addChild(root, a);
    addChild(a, aa);
    addChild(aa, aaa);
    addChild(aa, aab);
    startNewTransaction();
    DAO.addCategory(null, root);
    endTransaction();
    startNewTransaction();
    DAO.moveCategory(child4ID, child3ID);
    endTransaction();
}
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