categoryService = injector.getInstance(CategoryService.class);
}
@Test
public void testSaveOrUpdate() throws Exception {
Category category1 = new Category();
category1.setType(Type.ENTRY);
category1.setName("Programming");
category1 = categoryService.saveOrUpdate(category1);
Category category2 = new Category();
category2.setName("Java");
category2.setType(Type.ENTRY);
category2.setParent(category1);
categoryService.saveOrUpdate(category2);
Category javaCategory = categoryService.getByName("Java", category1.getId());
assertEquals("Java", javaCategory.getName());
assertEquals("Programming", javaCategory.getParent().getName());
assertNotNull(javaCategory.getParent());
assertEquals("Programming", categoryService.getByName("Programming", null).getName());
Category proCate = categoryService.get(category1.getId());
assertEquals(1, proCate.getChildren().size());
}