Changeset 514 for trunk


Ignore:
Timestamp:
Apr 29, 2010, 5:01:51 AM (15 years ago)
Author:
gav
Message:

Added integration test for TaskSearchService.getPersonsTasks().
Extended TaskService.delete() to handle assignedPersons and assignedGroups.
Use safe collection navigation in AssignedGroupService and AssignedPersonService?.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/AssignedGroupService.groovy

    r291 r514  
    146146                return fail(code:"personGroup.not.found")
    147147
    148             result.personsInGroup = result.personGroup.persons.sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }
     148            result.personsInGroup = result.personGroup.persons?.sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }
    149149
    150150            result.assignedGroupInstance = new AssignedGroup()
  • trunk/grails-app/services/AssignedPersonService.groovy

    r291 r514  
    146146                return fail(code:"person.not.found")
    147147
    148             result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }
     148            result.groupsForPerson = result.person.personGroups?.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }
    149149
    150150            result.assignedPersonInstance = new AssignedPerson()
  • trunk/grails-app/services/TaskService.groovy

    r510 r514  
    254254            }
    255255
     256            // Handle assignedPersons.
     257            def taskAssignedPersons = AssignedPerson.findAllByTask(result.taskInstance)
     258            taskAssignedPersons.each() {
     259                result.taskInstance.removeFromAssignedPersons(it)
     260                it.delete()
     261            }
     262
     263            // Handle assignedGroups.
     264            def taskAssignedGroups = AssignedGroup.findAllByTask(result.taskInstance)
     265            taskAssignedGroups.each() {
     266                result.taskInstance.removeFromAssignedGroups(it)
     267                it.delete()
     268            }
     269
    256270            if(result.error)
    257271                return result
  • trunk/test/integration/TaskSearchServiceTests.groovy

    r512 r514  
    1313    def dateUtilService
    1414    def taskSearchService
     15    def assignedGroupService
     16    def assignedPersonService
    1517
    1618    def taskA
     
    6466    }
    6567
     68
     69    /**
     70    * Test GetTasks.
     71    */
    6672    void testGetTasks() {
    67         // Todays tasks should be returned
     73        // Todays tasks should be returned.
    6874        def tasks = taskSearchService.getTasks([:])
    6975        assert tasks.totalCount == taskCount
     
    110116    } // testGetTasks()
    111117
     118    /**
     119    * Test GetPersonsTasks.
     120    */
     121    void testGetPersonsTasks() {
     122
     123        def result
     124        def p = [:]
     125
     126        // Todays tasks should be returned, since Person #1 is lead and created the tasks.
     127        def tasks = taskSearchService.getPersonsTasks([:])
     128        assert tasks.totalCount == taskCount
     129
     130        // Tasks in the trash should not be returned.
     131        taskA.trash = true
     132        taskA.save(flush:true)
     133        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount - 1
     134        taskB.trash = true
     135        taskB.save(flush:true)
     136        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount - 2
     137
     138        // Restored tasks should be returned.
     139        taskA.trash = false
     140        taskA.save(flush:true)
     141        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount - 1
     142        taskB.trash = false
     143        taskB.save(flush:true)
     144        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount
     145
     146        // Tomorrows tasks should not be returned.
     147        taskA.targetStartDate = dateUtilService.tomorrow
     148        taskA.targetCompletionDate = dateUtilService.tomorrow
     149        taskA.save(flush:true)
     150        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount - 1
     151
     152        // Tomorrows tasks should be returned, if we ask for them.
     153        assert taskSearchService.getPersonsTasks([:], null, dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
     154
     155        // Yesterdays tasks should not be returned.
     156        taskA.targetStartDate = dateUtilService.yesterday
     157        taskA.targetCompletionDate = dateUtilService.yesterday
     158        taskA.save(flush:true)
     159        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount - 1
     160
     161        // Yesterdays tasks should be returned, if we ask for them.
     162        assert taskSearchService.getPersonsTasks([:], null, dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
     163
     164        // Tasks that span today should be returned.
     165        taskA.targetStartDate = dateUtilService.yesterday
     166        taskA.targetCompletionDate = dateUtilService.tomorrow
     167        taskA.save(flush:true)
     168        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount
     169
     170        // Tasks for a different person should not be returned.
     171        taskA.leadPerson = Person.get(2)
     172        taskA.save(flush:true)
     173        assert taskSearchService.getPersonsTasks([:]).totalCount == taskCount - 1
     174
     175        // Tasks for a specified leadPerson should be returned.
     176        // But only if approved since this person did not create the tasks.
     177        taskA.leadPerson = Person.get(2)
     178        taskA.save(flush:true)
     179        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 0
     180        taskA.approved = true
     181        taskA.save(flush:true)
     182        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 1
     183        // Moving the task to the trash, stops it being returned.
     184        taskA.trash = true
     185        taskA.save(flush:true)
     186        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 0
     187
     188        // Tasks assigned to a person should be returned.
     189        // But only if approved.
     190        p = [person: Person.get(2),
     191                task: taskB,
     192                estimatedHour: 1,
     193                estimatedMinute: 20]
     194        assert assignedPersonService.save(p).error == null
     195        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 0
     196        taskB.approved = true
     197        taskB.save(flush:true)
     198        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 1
     199
     200        // Tasks assigned to a person via a group should be returned.
     201        // But only if approved.
     202        Person.get(2).addToPersonGroups(PersonGroup.read(1)).save(flush:true)
     203        taskA.trash = false
     204        taskA.approved = false
     205        taskA.save(flush:true)
     206        p = [personGroup: PersonGroup.read(1),
     207                task: taskA,
     208                estimatedHour: 2,
     209                estimatedMinute: 30]
     210        assert assignedGroupService.save(p).error == null
     211        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 1 // Only taskB from above.
     212        taskA.approved = true
     213        taskA.save(flush:true)
     214        assert taskSearchService.getPersonsTasks([:], Person.get(2)).totalCount == 2 // taskA and taskB.
     215
     216    } // testGetTasks()
     217
    112218} // end class
Note: See TracChangeset for help on using the changeset viewer.