Arquillian Spring Framework Extension 1.1.0.Alpha1 Released

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

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.1.0.Alpha1 view tag
Release date 2015-08-05
Released by Aslak Knutsen
Compiled against

Published artifacts org.jboss.arquillian.extension

  • 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-persistence-spring 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

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

Arquillian Spring Framework Extension 1.0.0.Beta3 Released

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

It has again been a while since that last Arquillian Spring extension release, but it’s finally here. This release focus mainly on further integration and compatibility with the Arquillian Universe

Upgraded to Arquillian Core 1.1.x

With Arquillian Core 1.1.0.Final came the new ShrinkWrap Resolver 2.0 APIs.

The Arquillian Spring Deployers have been updated to support the new ShrinkWrap Resolver 2.0 APIs and should now work with the latest and greatest from the Arquillian Universe.

Arquillian Persistence Extension support

In this release we’ve added a new module, arquillian-persistence-spring, which integrates Spring with the Arquillian Persistence Extension.

More specifically, it’s an implementation of the Persistence Extension DataSourceProvider SPI.

This integration allow you to configure the Persistence Extension to operate on a DataSource configured in your Spring applicationContext.

Configure your DataSource and TransactionManager in the applicationContext.xml file. For example;

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   ...
</bean>

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
</bean>

Then setup your Test case using the Spring, Transaction and Persistence Extension annotations:

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

...

    @Test
    @ShouldMatchDataSet(value = "employee.yml", excludeColumns = "id")
    public void testSave() {

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

        employeeRepository.save(employee);

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

        employeeRepository.save(employee);
    }

    @UsingDataSet("employee.yml")
    @Cleanup(strategy = CleanupStrategy.USED_TABLES_ONLY)
    public void testGetEmployees() throws Exception {

        List<Employee> result = employeeRepository.getEmployees();

        assertNotNull("Method returned null list as result.", result);
        assertEquals("Two employees were expected.", 2, result.size());
    }
}

Optionally you can configure the transaction manager reference and data source reference globally for the whole test suite via arquillian.xml

<arquillian>
   <extension qualifier="transaction">
      <property name="manager">txManager</property>
   </extension>
   <extension qualifier="persistence">
      <property name="defaultDataSource">dataSource</property>
   </extension>
</arquillian>

See the Persistence Extension Reference Docs for more ingo

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.Beta3 view tag
Release date 2014-06-26
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-persistence-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 0

Thanks to the following list of contributors: Aslak Knutsen, Tommy Tynjä, Jakub Narloch, Andrew Lee Rubinger

Arquillian Spring Framework Extension 1.0.0.Beta2 Released

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

It has been a while since that last Arquillian Spring extension release, but it’s finally here. This release focus more on improving existing features rather then introducing completely new ones.

I would like to thank Jakub Kurlenda and John Ament for helping with this release.

Some of the highlights in this release

Managing the Spring’s ApplicationContext lifecycle

New ways of configuring Spring’s context

Warp Spring extension

Deployer new functionality

Managing the Spring’s ApplicationContext lifecycle

Previous versions had one common drawback, each test were running using a separate instance of Spring’s ApplicationContext. Although the ApplicationContext were destroyed and all of its resources were freed after the test execution, this brought additional overhead for each test. From now on the developer has the control whether he want to create only a single context per test case or to have each test run with a new “clean” context, which in some situation might be handy. By default the context will be created only once, but it can easly be changed by adding the @ContextLifeCycle annotation to the test case.

New ways of configuring Spring’s context

This release also bring a couple of new features to ease the test configuration. First are smart defaults used for configuration. Each @SpringConfiguration annotated test do not need to explicitly define the location of the XML file anymore. If no file has been defined, by default the extension will look for file in classpath with exactly the same name as the class located in the class package. The same goes for @SpringAnnotationConfiguration, which now allow to add a static non final internal class which needs to be marked with @Configuration. The extension will use that class by default when configuring Spring.

Example:

@SpringClientAnnotationConfiguration
public class TestCase {

    @Configuration
    public static class ContextConfiguration {

        @Bean
        public EmployeeService employeeService() {
            return new EmployeeServiceImpl();
        }
    }
}

The last new feature is programmatic creation of the ApplicationContext from within a test. From now on it is possible to create the instance of the Spring ApplicationContext for each test via code. This is done by adding a static factory method to the test which needs to be annotated with @SpringContextConfiguration. The extension will invoke this method prior to test execution (all context lifecycle rules mentioned above also apply here) and use it’s result afterwards.

Example:

@SpringContextConfiguration
public static ApplicationContext contextConfiguration() {

   return new ClassPathXmlApplicationContext(
       new String[]{"classpath:service.xml", "classpath:repository.xml"});
}

Why would this be needed? In some cases you needs to have greater control over the context; for instance at the moment this is the only way to pragmatically set the Spring profiles to use for the test. The other possibility could be integration with other frameworks in which the context should not be managed by the test itself.

Warp Spring extension

The Warp Spring extension has been updated to the latest Alpha 2 release. For consistency with other Warp extensions the SpringMvcResult can be now injected using @ArquillianResource annotation. The custom @SpringResource has been deprecated and might be remove in next releases.

Deployer new functionality

The Spring deployer, which is used for automatic packaging the Spring artifacts and enriching the test deployment, has received some updates. It now allows for importing the dependencies directly from the Maven POM file, and could aid with setting up the deployment. The deployer can be configured in the arquillian.xml file through the spring-deployer section. Additional properties like pomFile allow you to specify the location of the pom file to load; useMavenOffline controls the offline mode of the maven resolver in use, and enableCache controls whether the deployer should cache the artifacts in memory. Finally the excludedArtifacts allow you to exclude artifacts that are unwanted from the deployment

<extension qualifier="spring-deployer">

        <property name="importPomDependencies">true</property>

        <property name="pomFile">src/main/resources/test_pom.xml</property>

        <property name="useMavenOffline">false</property>

        <property name="excludedArtifacts">org.jboss.arquillian:*</property>

        <property name="enableCache">true</property>
</extension>

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.Beta2 view tag
Release date 2013-06-19
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 0

Improvements

Thanks to the following list of contributors: Jakub Narloch, Aslak Knutsen, John D. Ament, Jakub Kurlenda

Arquillian Spring Framework Extension 1.0.0.Beta1 Released

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 0

Arquillian Transaction Extension support and Client side ApplicationContext creation

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

Arquillian Spring Framework Extension 1.0.0.Alpha2 Released

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

This release contain many improvements on the existing extension, but also some new features.

Some of the highlights in this release

Warp Spring MVC Extension
Spring Embedded Container
Separated the integration capabilities

Testing Spring MVC with Warp

Arquillian Warp is a powerful tool that let you run the functional tests against your web front end and at the same time verify the internal state of your application. With this release we are introducing the Warp extension for testing Spring MVC applications that run in a real servlet container.

Let’s dive into an example of how to test a Spring MVC application using Arquillian Warp. First we need to prepare the application descriptor.

web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <servlet>
        <servlet-name>welcome</servlet-name>
        <servlet-class>org.jboss.arquillian.warp.extension.spring.servlet.WarpDispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>welcome</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

</web-app>

You’ll notice that instead of using Spring’s DispatcherServlet we instead use the WarpDispatcherServlet.

And the testing code:

LoginControllerTestCase.java
@WarpTest
@RunWith(Arquillian.class)
public class LoginControllerTestCase {

    @Drone
    WebDriver browser;

    @ArquillianResource
    URL contextPath;

    @Test
    @RunAsClient
    public void testLoginValidationErrors() {
        browser.navigate().to(contextPath + "login.do");

        Warp.execute(new ClientAction() {

            @Override
            public void action() {

                browser.findElement(By.id("loginForm")).submit();
            }
        }).verify(new LoginControllerValidationErrorsVerification());
    }

    @Test
    @RunAsClient
    public void testLoginSuccess() {
        browser.navigate().to(contextPath + "login.do");
        browser.findElement(By.id("login")).sendKeys("warp");
        browser.findElement(By.id("password")).sendKeys("warp");

        Warp.execute(new ClientAction() {

            @Override
            public void action() {

                browser.findElement(By.id("loginForm")).submit();
            }
        }).verify(new LoginSuccessVerification());
    }

    public static class LoginControllerValidationErrorsVerification extends ServerAssertion {

            private static final long serialVersionUID = 1L;

            @SpringMvcResource
            private ModelAndView modelAndView;

            @SpringMvcResource
            private Errors errors;

            @AfterServlet
            public void testGetLogin() {

                assertEquals("login", modelAndView.getViewName());
                assertNotNull(modelAndView.getModel().get("userCredentials"));
                assertEquals("Two errors were expected.", 2, errors.getAllErrors().size());
                assertTrue("The login hasn't been validated.", errors.hasFieldErrors("login"));
                assertTrue("The password hasn't been validated.", errors.hasFieldErrors("password"));
            }
        }

    public static class LoginSuccessVerification extends ServerAssertion {

        private static final long serialVersionUID = 1L;

        @SpringMvcResource
        private ModelAndView modelAndView;

        @SpringMvcResource
        private Errors errors;

        @AfterServlet
        public void testGetLogin() {

            assertEquals("welcome", modelAndView.getViewName());
            assertFalse(errors.hasErrors());
        }
    }
}

In the above example we are using Arquillian Drone to navigate to the login page of our application and then filling in the login form with our user credentials.

The internal state of the DispatcherServlet is caught in a SpringMvcResult object which can be injected into the ServerAssertion. We can also inject other required objects like the ModelAndView.

Spring Embedded Container

Each development cycle may end in repeatedly re-running the integration tests, each time taking significant amount of time. The embedded container was thought to aid this situation. Running the tests embedded will decrease the execution time from seconds to milliseconds. It will help testing business objects, but since it’s not a full servlet container you won’t be able to use it for testing servlet requests in a web application.

Migrating from 1.0.0.Alpha1

1.0.0.Alpha2 comes with a couple significant changes from the previous version.

  • The Spring integration functionality has been separated out to its own module and is now part of the arquillian-service-integration-spring-inject module, and additional the arquillian-service-integration-spring-inject and the arquillian-service-integration-spring-javaconfig that does not target any specific Spring version, but rather provide functionality like XML or Java-based configuration.
  • The arquillian-service-deployer-spring module’s can still be used for autopackging the Spring artifacts.
  • The @SpringAnnotatedConfiguration has been renamed to @SpringAnnotationConfiguration.

Roadmap

The next release is planned to include Spring transaction support and will introduce even better Warp integration on the client side in order make REST testing even simpler.

We look forward to hearing your feedback about this release in 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.Alpha2 view tag
Release date 2012-07-21
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-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-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 0

Spring Embedded Container + Warp

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