Quantcast

Integration testing of quartz jobs

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Integration testing of quartz jobs

Chris Searle-4
I'm having some persistance issues here - not sure why/what I've  
misunderstood. Everything is working in the app itself at the GORM  
level so I think that the domain objects are probably OK.

Person {
   String name
   String email

   static hasMany = [owns: Hut]
}

Hut {
   String name
   Person owner

   static belongsTo = Person
}

So - I need to use these from a quartz job. The job has the following  
structure in a getMessage method (the execute method will call this  
and then email the results - the message generation is factored out  
simply to assist in testing). Currently reduced to the following

     def getMessage = {

         def people = Person.list()

         people.each {person ->
             log.debug("${person.name} ${person.owns}")
         }
         return ""
   }

So - in the integration test for this job I have the following:

     void setUp() {
         Person.list()*.delete()
         Hut.list()*.delete()

         def owner = new Person(name: "Hut owner", email: "[hidden email]
").save(flush: true)
         def renter1 = new Person(name: "Hut renter 1", email: "[hidden email]
").save(flush: true)
         def renter2 = new Person(name: "Hut renter 2", email: "[hidden email]
").save(flush: true)

         def hut = new Hut(name: "Test Hut", owner: owner).save(flush:  
true)
     }

     void testData() {
         assertEquals 3, Person.list().size()

         assertEquals 1, Hut.list().size()
     }

     void testGetMessage() {
         def messageText = new OwnerWeeklyRentalReportJob().getMessage()
     }


testData passes - it believes that there are three people and one hut.

testGetMessage logs the following:

[14351] task.OwnerWeeklyRentalReportJob Hut owner null
[14351] task.OwnerWeeklyRentalReportJob Hut renter 1 null
[14352] task.OwnerWeeklyRentalReportJob Hut renter 2 null

I simply cannot see why owner's owns is logging as null.

I can - in the test onSetup add an assertEquals(owner, hut.owner) and  
that passes.

This is grails 1.0.2. Am I missing something obvious?

Oh - side question - when wanting to test a job - do I really have to  
call new JobName() to get it? Can't see that in the examples - but it  
doesn't find the method otherwise.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Integration testing of quartz jobs

justinedelson
I think the problem is in your setup code, not the test itself.

Instead of:
def owner = new Person(name: "Hut owner", email: "[hidden email]").save(flush: true)
def hut = new Hut(name: "Test Hut", owner: owner).save(flush: true)

Try:
def owner = new Person(name: "Hut owner", email: "[hidden email]")
def hut = new Hut(name: "Test Hut")
owner.addToOwns(hut)
owner.save(flush:true)



On Sat, Apr 5, 2008 at 8:23 AM, Chris Searle <[hidden email]> wrote:
I'm having some persistance issues here - not sure why/what I've misunderstood. Everything is working in the app itself at the GORM level so I think that the domain objects are probably OK.

Person {
 String name
 String email

 static hasMany = [owns: Hut]
}

Hut {
 String name
 Person owner

 static belongsTo = Person
}

So - I need to use these from a quartz job. The job has the following structure in a getMessage method (the execute method will call this and then email the results - the message generation is factored out simply to assist in testing). Currently reduced to the following

   def getMessage = {

       def people = Person.list()

       people.each {person ->
           log.debug("${person.name} ${person.owns}")
       }
       return ""
 }

So - in the integration test for this job I have the following:

   void setUp() {
       Person.list()*.delete()
       Hut.list()*.delete()

       def owner = new Person(name: "Hut owner", email: "[hidden email]").save(flush: true)
       def renter1 = new Person(name: "Hut renter 1", email: "[hidden email]").save(flush: true)
       def renter2 = new Person(name: "Hut renter 2", email: "[hidden email]").save(flush: true)

       def hut = new Hut(name: "Test Hut", owner: owner).save(flush: true)
   }

   void testData() {
       assertEquals 3, Person.list().size()

       assertEquals 1, Hut.list().size()
   }

   void testGetMessage() {
       def messageText = new OwnerWeeklyRentalReportJob().getMessage()
   }


testData passes - it believes that there are three people and one hut.

testGetMessage logs the following:

[14351] task.OwnerWeeklyRentalReportJob Hut owner null
[14351] task.OwnerWeeklyRentalReportJob Hut renter 1 null
[14352] task.OwnerWeeklyRentalReportJob Hut renter 2 null

I simply cannot see why owner's owns is logging as null.

I can - in the test onSetup add an assertEquals(owner, hut.owner) and that passes.

This is grails 1.0.2. Am I missing something obvious?

Oh - side question - when wanting to test a job - do I really have to call new JobName() to get it? Can't see that in the examples - but it doesn't find the method otherwise.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Integration testing of quartz jobs

Chris Searle-4

On 5. april. 2008, at 16.11, Justin Edelson wrote:
I think the problem is in your setup code, not the test itself.

Instead of:
def owner = new Person(name: "Hut owner", email: "[hidden email]").save(flush: true)
def hut = new Hut(name: "Test Hut", owner: owner).save(flush: true)

Try:
def owner = new Person(name: "Hut owner", email: "[hidden email]")
def hut = new Hut(name: "Test Hut")
owner.addToOwns(hut)
owner.save(flush:true)

Been playing with this.

Managed to find out that hut.owner.owns was null so that signified that the link was only made one way (don't ask me why the controller save action which does it this way works fine :))

Some followup questions if I may:

1) if I don't provide an owner to the hut in the constructor validation fails since the owner is mandatory.  Do I have to do

def hut = new Hut(name: "Test Hut", owner: owner)
owner.addToOwns(hut)

Gets further but seems to be a bit overdone.

Secondly - if I do this addToOwns - then call People.list()*.delete() I get a contstraint violation (I clear out the DB both in setUp and tearDown) - isn't that supposed to be solved by the belongsTo?

Do I need to make owner non mandatory so that I can avoid it in the contructor of Hut then call only the addToOwns ?




On Sat, Apr 5, 2008 at 8:23 AM, Chris Searle <[hidden email]> wrote:
I'm having some persistance issues here - not sure why/what I've misunderstood. Everything is working in the app itself at the GORM level so I think that the domain objects are probably OK.

Person {
 String name
 String email

 static hasMany = [owns: Hut]
}

Hut {
 String name
 Person owner

 static belongsTo = Person
}

So - I need to use these from a quartz job. The job has the following structure in a getMessage method (the execute method will call this and then email the results - the message generation is factored out simply to assist in testing). Currently reduced to the following

   def getMessage = {

       def people = Person.list()

       people.each {person ->
           log.debug("${person.name} ${person.owns}")
       }
       return ""
 }

So - in the integration test for this job I have the following:

   void setUp() {
       Person.list()*.delete()
       Hut.list()*.delete()

       def owner = new Person(name: "Hut owner", email: "[hidden email]").save(flush: true)
       def renter1 = new Person(name: "Hut renter 1", email: "[hidden email]").save(flush: true)
       def renter2 = new Person(name: "Hut renter 2", email: "[hidden email]").save(flush: true)

       def hut = new Hut(name: "Test Hut", owner: owner).save(flush: true)
   }

   void testData() {
       assertEquals 3, Person.list().size()

       assertEquals 1, Hut.list().size()
   }

   void testGetMessage() {
       def messageText = new OwnerWeeklyRentalReportJob().getMessage()
   }


testData passes - it believes that there are three people and one hut.

testGetMessage logs the following:

[14351] task.OwnerWeeklyRentalReportJob Hut owner null
[14351] task.OwnerWeeklyRentalReportJob Hut renter 1 null
[14352] task.OwnerWeeklyRentalReportJob Hut renter 2 null

I simply cannot see why owner's owns is logging as null.

I can - in the test onSetup add an assertEquals(owner, hut.owner) and that passes.

This is grails 1.0.2. Am I missing something obvious?

Oh - side question - when wanting to test a job - do I really have to call new JobName() to get it? Can't see that in the examples - but it doesn't find the method otherwise.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email




-- 
Chris

Loading...