0

I'm writing a griffon application with JavaFX and the JPA plugin. I have a service I'd like to test - this service makes use of the JPA plugin (withJpa {...}) and it's this database access that I want to test.

So, I want to write this test so it inserts some data, then check that the service produces the right answer thus verifying the sql query is correct.

I've written a simple test:

class ReportServiceTests extends GriffonUnitTestCase {
    GriffonApplication app

    public void testStats() {
        println app.getServices()
        println app.getControllers()
    }
}

but I cannot get hold of a valid service - both the println statements above produce "[:]".

How do I get hold of the 'ReportService' instance and exercise it against the database? I don't want to mock the database interaction.

Thanks.

prule
  • 2,536
  • 31
  • 32

1 Answers1

1

There's no need to mock the database. As explained in http://griffon.codehaus.org/guide/latest/guide/testing.html#integrationTesting applications reach the INITIALIZE phase during integration testing. Addons get initialized during this phase. Services on the other hand get initialized lazily as they are pulled in by MVC members when instantiated: they do not get instantiated out-of-the-box if you call app.getServices(). However you can instruct the application to eagerly instantiate all services, this will make your code work as expected; just add the following flag to Config.groovy

griffon.services.eager.instantiation = true

More info on services can be found at http://griffon.codehaus.org/guide/latest/guide/controllersAndServices.html#services

Andres Almiray
  • 3,236
  • 18
  • 28
  • Thanks - I've used a setup() method to find my service via the service manager and all is good. Once again, thanks for the awesome framework and support! ReportService reportService protected void setUp() { super.setUp() reportService = app.serviceManager.findService('reportService') } – prule Feb 18 '13 at 23:14