Arquillian Persistence Extension Integration Tests

Demonstrates usage of Arquillian Persistence extension.

License

License

Categories

Categories

JBoss Container Application Servers Arquillian Application Testing & Monitoring
GroupId

GroupId

org.jboss.arquillian.extension
ArtifactId

ArtifactId

arquillian-persistence-integration-tests
Last Version

Last Version

1.0.0.Alpha7
Release Date

Release Date

Type

Type

jar
Description

Description

Arquillian Persistence Extension Integration Tests
Demonstrates usage of Arquillian Persistence extension.
Project URL

Project URL

http://www.jboss.org/arquillian-persistence-integration-tests
Project Organization

Project Organization

JBoss by Red Hat

Download arquillian-persistence-integration-tests

How to add to project

<!-- https://jarcasting.com/artifacts/org.jboss.arquillian.extension/arquillian-persistence-integration-tests/ -->
<dependency>
    <groupId>org.jboss.arquillian.extension</groupId>
    <artifactId>arquillian-persistence-integration-tests</artifactId>
    <version>1.0.0.Alpha7</version>
</dependency>
// https://jarcasting.com/artifacts/org.jboss.arquillian.extension/arquillian-persistence-integration-tests/
implementation 'org.jboss.arquillian.extension:arquillian-persistence-integration-tests:1.0.0.Alpha7'
// https://jarcasting.com/artifacts/org.jboss.arquillian.extension/arquillian-persistence-integration-tests/
implementation ("org.jboss.arquillian.extension:arquillian-persistence-integration-tests:1.0.0.Alpha7")
'org.jboss.arquillian.extension:arquillian-persistence-integration-tests:jar:1.0.0.Alpha7'
<dependency org="org.jboss.arquillian.extension" name="arquillian-persistence-integration-tests" rev="1.0.0.Alpha7">
  <artifact name="arquillian-persistence-integration-tests" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.jboss.arquillian.extension', module='arquillian-persistence-integration-tests', version='1.0.0.Alpha7')
)
libraryDependencies += "org.jboss.arquillian.extension" % "arquillian-persistence-integration-tests" % "1.0.0.Alpha7"
[org.jboss.arquillian.extension/arquillian-persistence-integration-tests "1.0.0.Alpha7"]

Dependencies

compile (1)

Group / Artifact Type Version
javax.validation : validation-api jar 1.0.0.GA

test (10)

Group / Artifact Type Version
org.jboss.arquillian.extension : arquillian-persistence-api jar 1.0.0.Alpha7
org.jboss.arquillian.extension : arquillian-persistence-core jar 1.0.0.Alpha7
org.jboss.arquillian.extension : arquillian-persistence-dbunit jar 1.0.0.Alpha7
junit : junit jar
org.easytesting : fest-assert jar 1.4
org.jboss.arquillian.junit : arquillian-junit-container jar
javax.enterprise : cdi-api jar 1.0-SP1
org.jboss.shrinkwrap.resolver : shrinkwrap-resolver-impl-maven jar
org.jboss.shrinkwrap.descriptors : shrinkwrap-descriptors-api-javaee jar
org.jboss.shrinkwrap.descriptors : shrinkwrap-descriptors-impl-javaee jar

Project Modules

There are no modules declared in this project.

Arquillian Persistence Extension

Build Status

To read complete documentation visit http://arquillian.org/arquillian-extension-persistence/

1. Overview

1.1. What Is This?

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

It comes with following features:

  • Wrapping each test in the separated transaction (with commit (default) or rollback at the end).

  • Seeding database using:

    • DBUnit with XML, XLS, YAML and JSON supported as data sets format.

    • Custom SQL scripts.

  • Comparing database state at the end of the test using given data sets (with column exclusion).

  • Eviction JPA second level cache between test method invocation, see @JpaCacheEviction.

1.2. Containers Used For Testing

  • Glassfish 3.1.2 Embedded

  • JBoss AS 7.0.2 Final (managed)

  • JBoss AS 7.1.1.Final (managed)

  • Wildfly 8.1

1.3. Verified With Following Databases

  • HSQL

  • MS SQL 2008 Express (with Microsoft JDBC Driver)

  • MySQL 5.5.24

  • PostgreSQL 9.1.4

  • Oracle 11g

  • Derby

Enough talking, let’s see it in action!

1.4. 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
                       .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 should_change_user_password() 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!

If you have any questions or would like to file feature request or bug report (hope not!) please have a look at the ways how you can get in touch with us.

org.jboss.arquillian.extension

An Innovative Testing Platform for the JVM

Versions

Version
1.0.0.Alpha7
1.0.0.Alpha6
1.0.0.Alpha5
1.0.0.Alpha4
1.0.0.Alpha3
1.0.0.Alpha2
1.0.0.Alpha1