Question

Currently, we have one database instance for all of our integration testing. The oracle database schema is synced by a bunch of DDLs. Then we use DBunit to populate and truncate the tables in between tests. There are two issues with this approach:

  1. The time spent preparing the database is more than what is spent testing
  2. On occasion, usually a test failure, test data bleeds over to a subsequent test and causes more failures.

I want to isolate the tests by creating an in-memory database (such as h2) per test. I plan on configuring EclipseLink to generate the DDL (because converting the oracle DDL to something else will be a nightmare I'd imagine). The only issue at that point would be to create triggers.

So I have two questions...

  1. Could I create an in-memory database (h2 or whatever) off of an existing oracle schema, triggers included?
  2. Or, can I create an in memory database using my entitymanager (DDL generation) and create a bunch of triggers on the fly, but prior to test execution?

Technology stack:

  • Spring: 3.2.8
  • Spring Data JPA: 1.5.3
  • Eclipse Link: 2.5.1
  • Oracle: 11

I am familiar with how to instantiate a Spring Test Integration environment to load up an in-memory database. Just not sure how I can translate the oracle stuff (triggers, specifically).

Was it helpful?

Solution

Could I create an in-memory database (h2 or whatever) off of an existing oracle schema, triggers included?

Yes you can have this. We use Postgres for all of our physical databases and HSQL for the in-memory database. We started off with using hibernate to generate the database off of the entity classes, but have now migrated to use Flyway. Keep in mind that some of your DML and DDL will be custom to Oracle so you will have to customize for HSQL or H2 (pretty easy to do using Flyway).

Or, can I create an in memory database using my entitymanager (DDL generation) and create a bunch of triggers on the fly, but prior to test execution?

You can clean/populate your in-memory database however you wish. There are multiple ways:

  1. Flyway Test Extensions - this makes it easy and is what we use. https://github.com/flyway/flyway-test-extensions.
  2. Write a Spring bean that has a test profile @Profile("test") and will insert data for the test environment.
  3. Use an import.sql script. I believe the Spring test harness will look for this.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top