Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Unit testing active objects for multiple databases

Bjarni Thorbjornsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2011

Hi,

Can someone tell me how to test active objects against multiple databases? I want to unit test my plugin (or at least my AO code) against all the major databases: MySQL, MS-SQL, Oracle, Postgres.

I see that there is something called "DynamicJdbcConfiguration" which according to the JavaDoc is: "A JDBC configuration that can be configured through either system properties or a configuration file." Does anyone have an example of how to use this "DynamicJdbcConfiguration" for multiple databases?

Many thanks,

-Bjarni

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Samuel Le Berrigaud
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 28, 2011

Hey Bjarni,

first you should probably read this first document, but I'm sure you have. This explains the configuration of the testing framework for a single database, and also mentions some important information relating to @NameConverters that should be used when testing your plugin.

Now if you want to test against multiple databases, I suggest you use the following strategy, which is used both in the AO lib and the AO plugin itself:

  1. Use the DynamicJdbcConfiguration
  2. Have one maven profile per database, the default one probably being HSQL. Remember that HSQL is more permissive than other DBs though.
  3. In each profile:
    1. have a system property set the database you want to use, you'll need to set this against the surefire plugin
    2. Add a dependency to the JDBC driver needed to connect to this database

This should get you started. Running your tests should be as simple as running mvn install -P'database'.

Some things to note:

  • You will not be able to run the tests against all the databases at once, we have one Bamboo build per database.
  • Dynamic JDCB configuration and its underlying classes is opiniated, i.e. databases should run on localhost, named 'ao_test' with a user 'ao_user'/'ao_password'
  • I't simple to write your own Jdbc configuration, following the same model if you need to, just a few lines of Java.
  • You might want to look at this pom.xml which contains all the integrations profiles for the AO lib.
  • You'll there the use of the database-maven-plugin, which is a simple plugin I wrote to help configure the database the way I want.

I hope that clarifies things a bit. Don't hesitate to comment if you need more info, I'll be happy to provide.

EddieW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2015

YOu can actually override the host, user, schema, etc. <profile> <id>db-postgres</id> <dependencies> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.3-1100-jdbc41</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <systemPropertyVariables> <ao.test.database>postgres</ao.test.database> <db.url>jdbc:postgresql://rds-db-xxxxx-us-east-1.rds.amazonaws.com:5432/test</db.url> <db.schema>public</db.schema> <db.username>user</db.username> <db.password>secret</db.password> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> </profile>

1 vote
Julien Hoarau
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

According to the presentation of Jason Hinch on ActiveObjects (Slides available here: https://developer.atlassian.com/display/DOCS/Atlascamp+2011+-+Using+Active+Objects+for+Rapid+Plugin+Development) you have to use the DynamicJdbcConfiguration class in Jdbc annotation and set the database via a property.

@Jdbc(DynamicJdbcConfiguration.class)
public class DatabaseTest
{
  //
}

To test with oracle database -Dao.test.database=oracle

Bjarni Thorbjornsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Thanks Julien,

I suspected that DynamicJdbcConfiguration was the way to go but I need more info...

How do I tell the DynamicJdbcConfiguration where my database is (URL, user&pass)? And how would I test all the databases in one go? Do you use maven profiles? Can you give us an example of how you set the tests up?

Best regards and thanks again,

-Bjarni (Tempo)

TAGS
AUG Leaders

Atlassian Community Events