如何使用mongo查询单元测试grails服务方法?

时间:2015-12-02 12:15:23

标签: mongodb unit-testing grails

我有一个名为getEmployeeSalary的方法的服务,我想进行单元测试,但我无法模拟和查询员工集合

private List getEmployeeSalary(String department, Date from){

     def db = grailsApplication.mainContext.mongo.getDB(grailsApplication.config.grails.mongo.databaseName)

     List employeeSalaryByDepartment = db.employee.aggregate([
                [ '$match' : [ department: department, 
                  dateCreated: ['$gte': from] ] ],
                [
                   $group' : [
                            '_id': "\$department",
                             'sum': [ '$sum': "\$salary" ]
                            ]
                ]
        ]).results()*.values()

   return employeeSalaryByDepartment
}

0 个答案:

没有答案