Search in sources :

Example 6 with MCRCategory

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

the class MCRCategoryDAOImplTest method replaceCategory.

@Test
public void replaceCategory() throws URISyntaxException, MCRException, SAXParseException, IOException {
    loadWorldClassification2();
    addWorldClassification();
    DAO.replaceCategory(category2);
    startNewTransaction();
    MCRCategoryImpl rootNode = getRootCategoryFromSession();
    assertEquals("Category count does not match.", countNodes(category2), countNodes(rootNode));
    assertEquals("Label count does not match.", category2.getChildren().get(0).getLabels().size(), rootNode.getChildren().get(0).getLabels().size());
    checkLeftRightLevelValue(rootNode, 0, 0);
    final URI germanURI = new URI("http://www.deutschland.de");
    final MCRCategory germany = rootNode.getChildren().get(0).getChildren().get(0);
    assertEquals("URI was not updated", germanURI, germany.getURI());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) URI(java.net.URI) Test(org.junit.Test)

Example 7 with MCRCategory

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

the class MCRCategoryDAOImplTest method removeLabel.

@Test
public void removeLabel() {
    addWorldClassification();
    final MCRCategory labelNode = category.getChildren().get(0);
    int labelCount = labelNode.getLabels().size();
    DAO.removeLabel(labelNode.getId(), "en");
    startNewTransaction();
    final MCRCategory labelNodeNew = getRootCategoryFromSession().getChildren().get(0);
    assertEquals("Label count did not match.", labelCount - 1, labelNodeNew.getLabels().size());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 8 with MCRCategory

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

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

the class MCRCategoryDAOImplTest method setLabel.

@Test
public void setLabel() {
    addWorldClassification();
    startNewTransaction();
    // test add
    int count = category.getLabels().size();
    final String lang = "ju";
    final String text = "JUnit-Test";
    DAO.setLabel(category.getId(), new MCRLabel(lang, text, "Added by JUnit"));
    startNewTransaction();
    MCRCategory rootNode = getRootCategoryFromSession();
    assertEquals("Label count does not match.", count + 1, rootNode.getLabels().size());
    // test modify
    String description = "Modified by JUnit";
    DAO.setLabel(category.getId(), new MCRLabel(lang, text, description));
    startNewTransaction();
    rootNode = getRootCategoryFromSession();
    assertEquals("Label count does not match.", count + 1, rootNode.getLabels().size());
    assertEquals("Label does not match.", description, rootNode.getLabel(lang).get().getDescription());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 10 with MCRCategory

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

the class MCRCategoryDAOImplTest method setLabels.

@Test
public void setLabels() {
    addWorldClassification();
    startNewTransaction();
    MCRCategory germany = DAO.getCategory(MCRCategoryID.fromString("World:Germany"), 0);
    MCRCategory france = DAO.getCategory(MCRCategoryID.fromString("World:France"), 0);
    Set<MCRLabel> labels1 = new HashSet<>();
    labels1.add(new MCRLabel("de", "deutschland", null));
    DAO.setLabels(germany.getId(), labels1);
    startNewTransaction();
    Set<MCRLabel> labels2 = new HashSet<>();
    labels2.add(new MCRLabel("de", "frankreich", null));
    DAO.setLabels(france.getId(), labels2);
    startNewTransaction();
    germany = DAO.getCategory(MCRCategoryID.fromString("World:Germany"), 0);
    france = DAO.getCategory(MCRCategoryID.fromString("World:France"), 0);
    assertEquals(1, germany.getLabels().size());
    assertEquals(1, france.getLabels().size());
    assertEquals("deutschland", germany.getLabel("de").get().getText());
    assertEquals("frankreich", france.getLabel("de").get().getText());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet) 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