vendredi 4 mars 2016

Grails spock unit testing query

I'm using grails 2.3.7 .. in a Spock unit test i'm mocking a findWhere method ..

  DocumentHeader.metaClass.static.findWhere = {DocumentType type, String workStation, Boolean complete ->
            println "Running mock findWhere .. "
            new DefaultDocument()
        }

which i'm using to mock a method call in a service ..

def returnDocument =  DocumentHeader.findWhere(documentType:DocumentType.DEFAULT_TYPE,
                        workStation: requirement.workstation,
                        complete: false)

The parameter types are correct but when invoke the test I get

Cannot query [com.sample.DocumentHeader] on non-existent property: workStation org.springframework.dao.InvalidDataAccessResourceUsageException: Cannot query [com.vantec.DocumentHeader] on non-existent property: workStation
at org.grails.datastore.mapping.simple.query.SimpleMapQuery

so it appears to be invoking the real method - not the mock .. Anyone any ideas ? Don't recall mocking a findWhere query before so anyone know of any problems ? TIA ..

Aucun commentaire:

Enregistrer un commentaire