Wish we could move our integration tests from the current ad-hoc approach to
the quickly evolving Bootique integration test framework. I am using this
framework a lot on various application projects, and it may just fit into
Cayenne, killing the boilerplate that we have now, and giving us much better
control of the test DB. The recent changes (in BQ 0.20) that made me think it
is a good match include:
* A port of JDBC part of Cayenne build-tools/cayenne-test-utilities (all those
DbHelper/TableHelper classes) to Bootique with substantially improved API.
* A transparent unit test lifecycle for managing in-memory Derby (full DB reset
and Cayenne schema load on each test; shutdown after the test) .
A typical DB-aware integration test now looks like the example below. Fairly
simple, clear, yet controllable (with .yml and custom DI modules). Fully
switching Cayenne i-tests to Bootique will require more work on both ends
(richer DB lifecycle, Docker, etc.), but at the end I think we'll have a more
sane and powerful test framework.
Now the catch is of course that Bootique requires Java 8. So perhaps that
should wait until we freeze 4.0 beta and split a 4.1 branch.
Andrus
-----
<!-- This imports a few more Bootique test modules and provides full DB
lifecycle... -->
<dependency>
<groupId>io.bootique.cayenne</groupId>
<artifactId>bootique-cayenne-test</artifactId>
<scope>test</scope>
</dependency>
@Rule
public BQTestFactory testFactory = new BQTestFactory();
@Before
public void before() {
BQTestRuntime runtime =
testFactory.app("--config=run-test.yml").autoLoadModules().createRuntime();
DatabaseChannel channel = DatabaseChannel.get(runtime);
Table teamTable = channel.newTable("schedule.team")
.columnNames("id", "name")
.build();
Table gameTable = channel.newTable("schedule.game")
.columnNames("id", "home_team_id", "visiting_team_id", "date_time",
"arena")
.build();
teamTable.insert(1, "New Jersey Devils")
.insert(2, "New York Rangers")
.insert(3, "Detroit Red Wings")
.insert(4, "LA Kings");
gameTable.insert(1, 1, 2, "2016-10-25 19:00:00", "Prudential Center")
.insert(2, 3, 4, "2016-10-25 20:00:00", "Joe Luis Arena")
.insert(3, 1, 4, "2016-10-26 19:00:00", "Prudential Center");
}