}
@Test
@Transactional
public void testSaveMaterialSubcategoryTopDown() {
MaterialCategory category = createValidMaterialCategory();
MaterialCategory subcategory = createValidMaterialCategory();
category.addSubcategory(subcategory);
//materialCategoryDAO.save(subcategory); //unnecessary due to cascade=all
materialCategoryDAO.save(category);
List<MaterialCategory> list = materialCategoryDAO.list(MaterialCategory.class);
for(MaterialCategory listCategory:list) {
if(listCategory.getId()==category.getId()) {
assertEquals(1, listCategory.getSubcategories().size());
}
if(listCategory.getId()==subcategory.getId()) {
assertNotNull(listCategory.getParent());
assertEquals(category.getId(), listCategory.getParent().getId());
}
}
}