Search in sources :

Example 61 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory 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 62 with MCRCategory

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

the class MCRCategoryDAOImplTest method testClassEditorBatch.

@Test
public void testClassEditorBatch() throws Exception {
    EntityManager entityManager = MCREntityManagerProvider.getCurrentEntityManager();
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL("http://mycore.de/classifications/nameIdentifier.xml")));
    MCRCategory nameIdentifier = MCRXMLTransformer.getCategory(xml);
    MCRCategory secondCateg = nameIdentifier.getChildren().get(1);
    DAO.addCategory(null, nameIdentifier);
    startNewTransaction();
    MCRCategLinkServiceFactory.getInstance().getLinksFromCategory(secondCateg.getId());
    assertTrue(secondCateg.getId() + " should exist.", DAO.exist(secondCateg.getId()));
    // re-set labels
    DAO.setLabels(secondCateg.getId(), secondCateg.getLabels().stream().collect(Collectors.toSet()));
    // re-set URI
    entityManager.detach(DAO.setURI(secondCateg.getId(), secondCateg.getURI()));
    // move to new index
    DAO.moveCategory(secondCateg.getId(), secondCateg.getParent().getId(), 0);
    startNewTransaction();
    MCRCategoryImpl copyOfDB = MCRCategoryDAOImpl.getByNaturalID(entityManager, secondCateg.getId());
    assertNotNull(secondCateg.getId() + " must hav a parent.", copyOfDB.getParent());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) EntityManager(javax.persistence.EntityManager) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) Test(org.junit.Test)

Example 63 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory 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 64 with MCRCategory

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

the class MCRCategoryDAOImplTest method getCategory.

@Test
public void getCategory() {
    addWorldClassification();
    MCRCategory rootCategory = DAO.getCategory(category.getId(), 0);
    assertTrue("Children present with child Level 0.", rootCategory.getChildren().isEmpty());
    rootCategory = DAO.getCategory(category.getId(), 1);
    MCRCategory origSubCategory = rootCategory.getChildren().get(0);
    assertTrue("Children present with child Level 1.", origSubCategory.getChildren().isEmpty());
    assertEquals("Category count does not match with child Level 1.\n" + MCRStringTransformer.getString(rootCategory), category.getChildren().size(), rootCategory.getChildren().size());
    assertEquals("Children of Level 1 do not know that they are at the first level.\n" + MCRStringTransformer.getString(rootCategory), 1, origSubCategory.getLevel());
    MCRCategory europe = DAO.getCategory(category.getChildren().get(0).getId(), -1);
    assertFalse("No children present in " + europe.getId(), europe.getChildren().isEmpty());
    europe = DAO.getCategory(category.getChildren().get(0).getId(), 1);
    assertFalse("No children present in " + europe.getId(), europe.getChildren().isEmpty());
    rootCategory = DAO.getCategory(category.getId(), -1);
    assertEquals("Did not get all categories." + MCRStringTransformer.getString(rootCategory), countNodes(category), countNodes(rootCategory));
    assertEquals("Children of Level 1 do not match", category.getChildren().size(), rootCategory.getChildren().size());
    MCRCategory subCategory = DAO.getCategory(origSubCategory.getId(), 0);
    assertNotNull("Did not return ", subCategory);
    assertEquals("ObjectIDs did not match", origSubCategory.getId(), subCategory.getId());
    assertNotNull("Root category may not null.", subCategory.getRoot());
    assertEquals("Root does not match", origSubCategory.getRoot().getId(), subCategory.getRoot().getId());
    MCRCategory germanyResource = find(category, "Germany").get();
    MCRCategory germanyDB = DAO.getCategory(germanyResource.getId(), 1);
    printCategoryTable();
    assertEquals("Children of Level 1 do not match", germanyResource.getChildren().size(), germanyDB.getChildren().size());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 65 with MCRCategory

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

the class MCRCategoryDAOImplTest method moveCategoryWithoutIndex.

@Test
public void moveCategoryWithoutIndex() throws SQLException {
    addWorldClassification();
    checkLeftRightLevelValue(getRootCategoryFromSession(), 0, 0);
    startNewTransaction();
    MCRCategory moveNode = category.getChildren().get(1);
    // Europe conquer Asia
    DAO.moveCategory(moveNode.getId(), category.getChildren().get(0).getId());
    startNewTransaction();
    MCRCategoryImpl rootNode = getRootCategoryFromSession();
    checkLeftRightLevelValue(rootNode, 0, 0);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) 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