hibernate/hibernate-ogm — pull request #199 by gunnarmorling (2013-07-18 07:48:53+00:00)
Title: Don't apply - OGM-45 Using test runner instead of superclass for SF handling

Creating this preview PR as base for discussion. The idea is to provide a JUnit 4 runner for OGM tests which does the session factory handling, without requiring tests to extend a superclass. It is used like this:

@RunWith(OgmTestRunner.class)
@ForEntities({ PolarBear.class, Giraffe.class })
public class AnimalFarmTest {

//injected by the runner, same instance for all test methods of this test
@TestSessionFactory
public SessionFactory sessions;

@Test
public void shouldCountAnimals() throws Exception {
Session session = sessions.openSession();
...
session.close();
}

//optional
@SessionFactoryConfiguration
public static void configure(Configuration cfg) {
cfg.setProperty(
Environment.MONGODB_ASSOCIATIONS_STORE,
AssociationStorage.COLLECTION.name()
);
}
}

Alternatively a JUnit 4 _test rule_ could be used. But this has several shortcomings:

* It can't access methods of the test class, so something like `configure()` above isn't possible. Given that we currently only use this method to set properties, one could think about an annotation based approach for setting these. One can't invoke something like `AssociationStorage.COLLECTION.name()` within an annotation, though.
* AFAICS a rule can't suppress single test methods, which we would need for `@SkipDialect` (which is apparently not used though atm.).

Based on that I think a runner is more suitable here. Any thoughts?