28. controller.params.id= 1
29. def categoryList= controller.list()?.categoryList
30.
31. assertEquals 2, categoryList.size()
32. assertEquals 'Test11', categoryList[0].name
33. assertEquals 'Test12', categoryList[1].name
34. }
35. }
Controller部分代码
1. class CategoryController {
2. def index = { redirect(action:list,params:params) }
3.
4. def allowedMethods = [save:'POST']
5.
6. def list = {
7. if(!params.id){
8. return [ categoryList: Category.findAllByParentIsNull() ]
9. }else{
10. def category= Category.get(params.id)
11. if(category){
12. return [ categoryList: Category.findAll("from Category c where c.parent.id=$params.id"), path: category.getPath()]
13. }else{
14. flash.message = "Category not found with id ${params.id}"
15. redirect(action:list)
16. }
17. }
18. }
19. ......
20. }
文章来源于领测软件测试网 https://www.ltesting.net/