/** * Test method TaxonomyService.getAllCategories() Input: Add 3 categories to node Expect: return 3 * categories * * @throws RepositoryException * @throws TaxonomyNodeAlreadyExistsException * @throws TaxonomyAlreadyExistsException */ public void testGetAllCategories() throws RepositoryException, TaxonomyNodeAlreadyExistsException, TaxonomyAlreadyExistsException { session.getRootNode().addNode("MyDocuments"); Node article = session.getRootNode().addNode("Article"); session.save(); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Culture", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "News", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/News", "Politics", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Culture", "Foods", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Culture", "Art", "root"); Node rootTree1 = (Node) session.getItem("/MyDocuments/Culture"); Node rootTree2 = (Node) session.getItem("/MyDocuments/News"); taxonomyService.addTaxonomyTree(rootTree1); taxonomyService.addTaxonomyTree(rootTree2); taxonomyService.addCategories(article, "Culture", new String[] {"Foods", "Art"}, true); taxonomyService.addCategory(article, "News", "Politics", true); List<Node> lstNode = mockTaxonomyService.getAllCategories(article, true); Node taxoLink1 = (Node) session.getItem("/MyDocuments/Culture/Foods"); Node taxoLink2 = (Node) session.getItem("/MyDocuments/Culture/Art"); Node taxoLink3 = (Node) session.getItem("/MyDocuments/News/Politics"); assertEquals(3, lstNode.size()); assertTrue(lstNode.contains(taxoLink1)); assertTrue(lstNode.contains(taxoLink2)); assertTrue(lstNode.contains(taxoLink3)); }
/** * Test method TaxonomyService.hasCategories() Input: Add categories for article node Expect: * return true with category is added return false with category that is not added * * @throws RepositoryException * @throws TaxonomyNodeAlreadyExistsException * @throws TaxonomyAlreadyExistsException */ public void testHasCategories() throws RepositoryException, TaxonomyNodeAlreadyExistsException, TaxonomyAlreadyExistsException { session.getRootNode().addNode("MyDocuments"); Node article = session.getRootNode().addNode("Article"); session.save(); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Budesliga", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Serie", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Serie", "A", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Serie", "B", "root"); Node rootTree1 = (Node) session.getItem("/MyDocuments/Serie"); Node rootTree2 = (Node) session.getItem("/MyDocuments/Budesliga"); taxonomyService.addTaxonomyTree(rootTree1); taxonomyService.addTaxonomyTree(rootTree2); taxonomyService.addCategories(article, "Serie", new String[] {"A", "B"}, true); assertTrue(mockTaxonomyService.hasCategories(article, "Serie", true)); assertFalse(mockTaxonomyService.hasCategories(article, "Budesliga", true)); }
/** * Test method TaxonomyService.getCategories() Input: Add 2 categories to article node Expect: * Return 2 node of categories * * @throws RepositoryException * @throws TaxonomyNodeAlreadyExistsException * @throws TaxonomyAlreadyExistsException */ public void testGetCategories() throws RepositoryException, TaxonomyNodeAlreadyExistsException, TaxonomyAlreadyExistsException { session.getRootNode().addNode("MyDocuments"); Node article = session.getRootNode().addNode("Article"); session.save(); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Stories", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Stories", "Homorous", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Stories", "Fairy", "root"); Node rootTree = (Node) session.getItem("/MyDocuments/Stories"); taxonomyService.addTaxonomyTree(rootTree); taxonomyService.addCategories(article, "Stories", new String[] {"Homorous", "Fairy"}, true); List<Node> lstNode = mockTaxonomyService.getCategories(article, "Stories", true); Node taxoLink1 = (Node) session.getItem("/MyDocuments/Stories/Homorous"); Node taxoLink2 = (Node) session.getItem("/MyDocuments/Stories/Fairy"); assertEquals(2, lstNode.size()); assertTrue(lstNode.contains(taxoLink1)); assertTrue(lstNode.contains(taxoLink2)); }
/** * Test method TaxonomyService.addCategories() Input: add 2 categories in article node Output: * create 2 exo:taxonomyLink in each category * * @throws RepositoryException * @throws TaxonomyNodeAlreadyExistsException * @throws TaxonomyAlreadyExistsException */ public void testAddCategories() throws RepositoryException, TaxonomyNodeAlreadyExistsException, TaxonomyAlreadyExistsException { session.getRootNode().addNode("MyDocuments"); Node article = session.getRootNode().addNode("Article"); session.save(); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments", "Serie", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Serie", "A", "root"); taxonomyService.addTaxonomyNode(COLLABORATION_WS, "/MyDocuments/Serie", "B", "root"); Node rootTree = (Node) session.getItem("/MyDocuments/Serie"); taxonomyService.addTaxonomyTree(rootTree); taxonomyService.addCategories(article, "Serie", new String[] {"A", "B"}, true); Node link1 = (Node) session.getItem("/MyDocuments/Serie/A/Article"); Node link2 = (Node) session.getItem("/MyDocuments/Serie/B/Article"); assertTrue(link1.isNodeType("exo:taxonomyLink")); assertEquals(article, linkManage.getTarget(link1)); assertTrue(link2.isNodeType("exo:taxonomyLink")); assertEquals(article, linkManage.getTarget(link2)); }