@Test public void testGetFullPath() { CategoryItem root = getRepo().loadCategory("/"); CategoryItem tagItem1 = root.addCategory("testGetFullPath", "foo"); assertNotNull(tagItem1); assertEquals("testGetFullPath", tagItem1.getFullPath()); CategoryItem childTagItem1 = tagItem1.addCategory("TestChildTag1", "foo"); assertNotNull(childTagItem1); assertEquals("testGetFullPath/TestChildTag1", childTagItem1.getFullPath()); CategoryItem childTagItem2 = childTagItem1.addCategory("TestChildTag2", "wee"); assertNotNull(childTagItem2); assertEquals("testGetFullPath/TestChildTag1/TestChildTag2", childTagItem2.getFullPath()); }
@Test public void testTagItem() throws Exception { final CategoryItem root = getRepo().loadCategory("/"); root.addCategory("TestTag", "nothing to see"); CategoryItem tagItem1 = getRepo().loadCategory("TestTag"); assertNotNull(tagItem1); assertEquals("TestTag", tagItem1.getName()); CategoryItem tagItem2 = getRepo().loadCategory("TestTag"); assertNotNull(tagItem2); assertEquals("TestTag", tagItem2.getName()); assertEquals(tagItem1, tagItem2); List originalCats = getRepo().loadCategory("/").getChildTags(); // listCategoryNames(); assertTrue(originalCats.size() > 0); CategoryItem rootCat = (CategoryItem)originalCats.get(0); assertNotNull(rootCat.getName()); assertNotNull(rootCat.getFullPath()); root.addCategory("FootestTagItem", "nothing"); List cats = root.getChildTags(); assertEquals(originalCats.size() + 1, cats.size()); boolean found = false; for (Iterator iter = cats.iterator(); iter.hasNext();) { CategoryItem element = (CategoryItem)iter.next(); if (element.getName().equals("FootestTagItem")) { found = true; break; } } assertTrue(found); }
@Test public void testGetTag() { RulesRepository rulesRepository = getRepo(); CategoryItem root = rulesRepository.loadCategory( "/" ); CategoryItem tagItem1 = root.addCategory( "testGetTag", "ho" ); assertNotNull( tagItem1 ); assertEquals( "testGetTag", tagItem1.getName() ); assertEquals( "testGetTag", tagItem1.getFullPath() ); CategoryItem tagItem2 = rulesRepository.loadCategory( "testGetTag" ); assertNotNull( tagItem2 ); assertEquals( "testGetTag", tagItem2.getName() ); assertEquals( tagItem1, tagItem2 ); //now test getting a tag down in the tag hierarchy CategoryItem tagItem3 = tagItem2.addCategory( "TestChildTag1", "ka" ); assertNotNull( tagItem3 ); assertEquals( "TestChildTag1", tagItem3.getName() ); assertEquals( "testGetTag/TestChildTag1", tagItem3.getFullPath() ); }
@Test public void testCreateCateories() throws Exception { RulesRepository repo = getRepo(); // load the root CategoryItem root = repo.loadCategory("/"); CategoryItem item = root.addCategory("testCreateCategories", "this is a top level one"); assertEquals("testCreateCategories", item.getName()); assertEquals("testCreateCategories", item.getFullPath()); item = repo.loadCategory("testCreateCategories"); assertEquals("testCreateCategories", item.getName()); item.remove(); repo.save(); try { repo.loadCategory("testCreateCategories"); fail("this should not exist"); } catch (RulesRepositoryException e) { assertNotNull(e.getCause()); } }