This is for some high level Web/Rest tests of my whole system that are being powered by Jetty/Spring.
What I am trying to do is to have a completely self contained test that,
- Starts Jetty which starts the Application
- Application starts Spring
- Test uses Webdriver / RestAssured to hit application and test behavior
- Test checks DB for changed data
What I am trying to do is have the whole thing running in a single JVM, i.e. I’m starting a org.eclipse.jetty.server.Server.
This is because its easy, and avoids the test having outside dependencies (like starting Jetty)
This is all cool, but I hate that I have to check the DB manually … I want to use my DAO (or maybe service layer) classes so I’m not re-writing DB code.
Since my DAO’s have already been started by Spring in the Jetty instance in the same JVM as the test case, I want to grab that ApplicationContext and then pull my DAO beans out.
I’m a bit stuck getting the ApplicationContext since the test isn’t a “Spring” test per say.
People got any ideas on how to do this?
I think it is not possible to access the spring context in jetty if it is start normally, may it could work if you use some embedded server.
But I think there are much simpler solutions: