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