Service Middleware Integration Test


i would like to test a middleware service that hits the db via an integration test (and therefore has a dependency on DataManager). I’m not quite sure how to create an instance of my service in the test.
I tried @Inject like this:

class ExampleServiceTest extends CubaTestCase {
  ExampleService exampleService

But it doesn’t get injected. Probably just a normal spring configuration that i have to include, but i don’t really get it. A little help would be cool - thanks!


Hi Mario,

Tests are “external” objects in relation to the container, they create and own the container and not vice versa. So the only way to get beans from the container is to locate them through the AppBeans static methods:

public void testCreate() throws Exception {
    DataManager dataManager = AppBeans.get(DataManager.class);
    Customer customer = metadata.create(Customer.class);