Arquillian Spring Framework Extension 1.0.0.Beta1 Released

Since we wrote this post we didn't laze around. Check our latest announcement.

The Arquillian team is proud to announce the 1.0.0.Beta1 release of the Arquillian Spring Framework Extension component!

The first Beta release of the Arquillian Spring extension is here.

Some of the highlights in this release

Client side application context registration
Spring transaction support

Client side tests with Spring

So far the Spring extension has only allowed application context creation and bean injection to occure when the tests were deployed in a container. We wanted to bring the same functionality to the client side. With the two new annotations @SpringClientConfiguration and @SpringClientAnnotationConfiguration it is now possible to set up the application context and inject beans into Arquillian tests that are running on the client.

An example of use would be to test a deployed REST service using the Spring RestTemplate configured in the client context.

@RunWith(Arquillian.class)
@SpringClientConfiguration("applicationContext-rest.xml")
public class ClientRestServiceTestCase {

    @Deployment(testable = false)
    @OverProtocol("Servlet 3.0")
    public static Archive createTestArchive() {
        return Deployments.createWebApplication()
                .addAsWebInfResource("mvc/web.xml", "web.xml")
                .addAsWebInfResource("service-servlet.xml");
    }

    @ArquillianResource
    private URL contextPath;

    @Autowired
    private RestTemplate restTemplate;

    @Test
    public void testGetEmployees() {

        Employee result = restTemplate.getForObject(contextPath + "/Employees/1", Employee.class);

        assertEquals("The returned employee has invalid name.", "John Smith", result.getName());
    }
}

Spring transaction support

The recent release of the Arquillian Transaction Extension allow us to control the transactional behavior of our test methods. With the help of the Spring Extension you can now control your Spring configured transaction manager using the same API. The set up is done in the normal Spring way by defining a transaction manager in the application context.

applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

   <!-- Creates local entity manager factory -->
   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
       <property name="persistenceUnitName" value="ArquillianTestUnit"/>
   </bean>

   <!-- Enables the declarative transaction support -->
   <tx:annotation-driven transaction-manager="txManager"/>

   <!-- Creates transaction manager -->
   <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
       <property name="entityManagerFactory" ref="entityManagerFactory"/>
   </bean>

</beans>

You define which transaction manager to use in your test class via the manager attribute on the @Transactional annotation.

@RunWith(Arquillian.class)
@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class JpaEmployeeRepositoryTestCase {

    @Autowired
    private EmployeeRepository employeeRepository;

    @PersistenceContext
    private EntityManager entityManager;

    @Test
    public void testSave() {

        Employee employee = new Employee();
        employee.setName("Test employee");

        employeeRepository.save(employee);

        List<Employee> result = entityManager.createQuery("from Employee").getResultList();

        assertEquals("Two employees were expected.", 1, result.size());
    }
}

Migrating from 1.0.0.Alpha2

  • Artifact arquillian-container-spring has been renamed to arquillian-service-container-spring

We look forward to your feedback on this new release on the community forums!

What is Arquillian?

Arquillian is open source software that empowers you to test JVM-based applications more effectively. Created to defend the software galaxy from bugs, Arquillian brings your test to the runtime so you can focus on testing your application's behavior rather than managing the runtime. Using Arquillian, you can develop a comprehensive suite of tests from the convenience of your IDE and run them in any IDE, build tool or continuous integration environment.

Release details

Component Arquillian Spring Framework Extension
Version 1.0.0.Beta1 view tag
Release date 2012-08-17
Released by Aslak Knutsen
Compiled against

Published artifacts org.jboss.arquillian.extension

  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-common jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-2.5 jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-3 jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-integration-spring jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-container-spring jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-integration-spring-inject jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-integration-spring-javaconfig jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-transaction-spring jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-integration-spring-2.5-int-tests jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-integration-spring-3-int-tests jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-warp-spring jar javadoc pom

Release notes and resolved issues 3

Arquillian Transaction Extension support and Client side ApplicationContext creation

Feature Request
  • ARQ-958 - Provide support for Spring transactions
  • ARQ-985 - Register the Spring Extension on client side.

Thanks to the following list of contributors: Jakub Narloch, Aslak Knutsen