Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Arquillian Database / Persistence Extension
Java
Branch: master
Pull request Compare This branch is 132 commits behind arquillian:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
api
impl
int-tests
.gitignore
README.md
license.txt
pom.xml

README.md

Arquillian Persistence Extension

What is this?

Arquillian Persistence Extension was created to help you writing tests where persistence layer is involved. Inspired by great framework called Unitils, it brings bunch of annotations to help you deal with the underlying data storage.

Arquillian Persistence Extension comes with following features:

  • Wrapping each test in the seperated transaction (with commit(default) or rollback at the end).
  • Seeding database using DBUnit with XML, XLS and YAML supported as data sets format.
  • Comparing database state at the end of the test using given data sets.

Currently tested on Glassfish 3.1 Embedded and JBoss AS 7.0.2 Final (managed).

Enough talking, let's see it in action!

Code example

@RunWith(Arquillian.class)
public class UserPersistenceTest
{

  @Deployment
  public static Archive<?> createDeploymentPackage()
  {
      return ShrinkWrap.create(JavaArchive.class, "test.jar")
                       .addPackage(UserAccount.class.getPackage())
                       .addPackages(true, "org.fest") // FEST Assert is not part of Arquillian JUnit
                       .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                       .addAsManifestResource("test-persistence.xml", "persistence.xml");
  }

  @PersistenceContext
  EntityManager em;

  @Test
  @UsingDataSet("datasets/users.yml")
  @ShouldMatchDataSet("datasets/expected-users.yml")
  public void shouldChangeUserPassword() throws Exception
  {
      // given
      String expectedPassword = "LexLuthor";
      UserAccount user = em.find(UserAccount.class, 2L);

      // when
      user.setPassword("LexLuthor");
      em.merge(user);

      // then
      assertThat(user.getPassword()).isEqualTo(expectedPassword);
  }
}

There are just two things which are different from the standard Arquillian test - @UsingDataSet and @ShouldMatchDataSet annotations. Former seeds the database using file in YAML format, and latter verifies database state using given file.

This example is taken from integration tests written for this project, so feel free to have a closer look. But it's that easy! And there's more to come!

Something went wrong with that request. Please try again.