Grails Quartz Job Integration test - Not Auto Level Jobs

I am writing an Integration test for Quartz Job in a grails application. I have Job in the grails-app / jobs folder, and if I run the application, it works. The problem is that I want to get it in the integration test, but the auto device will not work. The test is as follows:

class MyJobTest{
    MyJob myJob
    def setUp(){
        assert myJob != null
    }

    def testExecute(){
         //test logic
    }

}

but it fails because myJob is null ... some help?

+3
source share
1 answer

, . Quartz , ( , , ). myJob = new MyJob() setUp execute() . , , triggers {}, , metaClass?

:

, . , :

, :

class MyJob {
    def myServiceA
    def myServiceB

    def execute() {
        if(myJobLogicToDetermineWhatToDo) {
            myServiceA.doStuff(parameter)
        } else {
            myServiceB.doStuff(parameter)
        }

    }        
}

, myJobLogicToDetermineWhatToDo. , ( ) / myServiceA myServiceB, , . / .

@Test
void routeOne() {
    def job = new MyJob()
    def myServiceA = new Object()
    def expectedParameter = "Name"
    def wasCalled = false
    myServiceA.metaClass.doStuff = {someParameter ->
        assert expectedParameter == someParameter
        wasCalled = true
    }
    job.myServiceA = myServiceA
    //Setup data to cause myServiceA to be invoked

    job.execute()

    assert wasCalled
}

, . , , , , . , , . , - , . , , , , , . , , . , - .

+4
source

All Articles