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());
}
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());
}
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();
}
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());
}
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);
}
Aggregations