0 Replies Latest reply on Feb 17, 2015 11:49 AM by Rakesh Panati

    Testing Spring Boot application on WildFly with Arquillian

    Rakesh Panati Newbie

      I'm building an application based on Spring Boot v1.2.1 and running it on WildFly 8.2. I wanted to use Arquillian for my testing needs as it is simpler than meddling with the application.properties file for doing the integration tests.

       

      I'm unable to get the started because I think the War File is actually not being deployed before the application boots.

       

       

      The Arquillian portion of pom.xml has below config

       

       

       

              <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.shrinkwrap.resolver</groupId>

                  <artifactId>shrinkwrap-resolver-api-maven</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.extension</groupId>

                  <artifactId>arquillian-service-container-spring</artifactId>

                  <version>${arquillian.spring.version}</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.extension</groupId>

                  <artifactId>arquillian-service-deployer-spring-3</artifactId>

                  <version>${arquillian.spring.version}</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.extension</groupId>

                  <artifactId>arquillian-service-integration-spring-inject</artifactId>

                  <version>${arquillian.spring.version}</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.extension</groupId>

                  <artifactId>arquillian-service-integration-spring-javaconfig</artifactId>

                  <version>${arquillian.spring.version}</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.extension</groupId>

                  <artifactId>arquillian-warp-spring</artifactId>

                  <version>${arquillian.spring.version}</version>

                  <scope>test</scope>

              </dependency>

      .....

       

       

              <profile>

                  <activation>

                      <activeByDefault>true</activeByDefault>

                  </activation>

                  <id>wildfy82-embedded</id>

                  <!-- the dependencies for Wildfly8.2  -->

                  <repositories>

                      <repository>

                          <id>JBOSS Maven Repository</id>

                          <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>

                      </repository>

                  </repositories>

                  <dependencies>

                      <!--

                      <dependency>

                          <groupId>org.wildfly</groupId>

                          <artifactId>wildfly-arquillian-container-embedded</artifactId>

                          <version>8.2.0.Final</version>

                      </dependency>

                      -->

                      <dependency>

                          <groupId>org.wildfly</groupId>

                          <artifactId>wildfly-embedded</artifactId>

                          <version>8.2.0.Final</version>

                      </dependency>

                  </dependencies>

       

       

                  <build>

                      <plugins>

                          <plugin>

                              <artifactId>maven-surefire-plugin</artifactId>

                              <configuration>

                                  <systemProperties>

                                      <property>

                                          <name>java.util.logging.manager</name>

                                          <value>org.jboss.logmanager.LogManager</value>

                                      </property>

                                  </systemProperties>

                              </configuration>

                          </plugin>

                          <!-- You need the maven dependency plugin to download locally a zip with the server, unless you provide your own, it will download under the /target directory -->

                          <plugin>

                              <groupId>org.apache.maven.plugins</groupId>

                              <artifactId>maven-dependency-plugin</artifactId>

                              <version>2.10</version>

                              <executions>

                                  <execution>

                                      <id>unpack</id>

                                      <phase>process-test-classes</phase>

                                      <goals>

                                          <goal>unpack</goal>

                                      </goals>

                                      <configuration>

                                          <artifactItems>

                                              <artifactItem>

                                                  <groupId>org.wildfly</groupId>

                                                  <artifactId>wildfly-dist</artifactId>

                                                  <version>8.2.0.Final</version>

                                                  <type>zip</type>

                                                  <overWrite>false</overWrite>

                                                  <outputDirectory>target</outputDirectory>

                                              </artifactItem>

                                          </artifactItems>

                                      </configuration>

                                  </execution>

                              </executions>

                          </plugin>

                          <plugin>

                              <groupId>org.apache.maven.plugins</groupId>

                              <artifactId>maven-surefire-plugin</artifactId>

                              <version>2.17</version>

                              <configuration>

                                  <!-- Fork every test because it will launch a separate AS instance -->

                                  <forkMode>always</forkMode>

                                  <systemPropertyVariables>

                                      <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>

                                      <!-- the maven dependency plugin will have already downloaded the server on /target -->

                                      <jboss.home>C:/rearch/wildfly-8.2.0.Final</jboss.home>

                                      <module.path>C:/rearch/wildfly-8.2.0.Final/modules</module.path>

                                  </systemPropertyVariables>

                                  <redirectTestOutputToFile>false</redirectTestOutputToFile>

                              </configuration>

                          </plugin>

                      </plugins>

                  </build>

              </profile>

       

       

       

       

      And then my Arquillian.xml looks as below

       

       

          <?xml version="1.0" encoding="UTF-8"?>

          <arquillian xmlns="http://jboss.org/schema/arquillian"

                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                      xsi:schemaLocation="

                  http://jboss.org/schema/arquillian

                  http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

         

              <engine>

                  <property name="deploymentExportPath">/tmp/</property>

              </engine>

         

              <container qualifier="wildfy82-embedded" default="true">

                  <configuration>

                      <property name="jbossHome">C:/rearch/wildfly-8.2.0.Final</property>

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

                      <property name="modulePath">C:/rearch/wildfly-8.2.0.Final/modules</property>

                      <property name="username">user</property>

                      <property name="password">password</property>

                  </configuration>

              </container>

         

              <extension qualifier="spring-deployer">

                  <property name="springVersion">4.1.4.RELEASE</property>

         

                  <!-- The version of CGLIB artifact - required by Java-based config, optional, default is 2.2.2 -->

                  <property name="cglibVersion">2.2</property>

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

         

              </extension>

         

          </arquillian>

       

       

      and then my test class looks as below

       

       

        @RunWith(Arquillian.class)

        @SpringAnnotationConfiguration(packages = "com.tb.ao")

        @Slf4j

        public class ModelServiceTest {

       

       

        @Autowired

        private ModelService modelService;

       

       

        @Deployment

        public static WebArchive createDeployment() {

       

       

        WebArchive war =  ShrinkWrap.create(WebArchive.class, "ao.war")

        .addPackages(true,"com.tb.ao");

       

       

        String[] extensions = {".properties"};

        FileUtils.listFiles(new File("src/main/resources"),extensions,false).stream().forEach(file -> war.addAsManifestResource(file));

        return war;

       

       

        }

       

        @Test

        //sometest

       

        }

       

       

       

       

      Finally, I get the exception as below (Datasource is not being detected because the WildFly environment is not started)

       

       

          Wrapped by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.

          at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:95) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]

          at org.jboss.arquillian.spring.integration.javaconfig.utils.AnnotationApplicationContextProducer.createAnnotatedApplicationContext(AnnotationApplicationContextProducer.java:72) [arquillian-service-integration-spring-javaconfig-1.0.0.Final-20140618.175956-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.spring.integration.javaconfig.utils.AnnotationApplicationContextProducer.createAnnotatedApplicationContext(AnnotationApplicationContextProducer.java:43) [arquillian-service-integration-spring-javaconfig-1.0.0.Final-20140618.175956-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.spring.integration.javaconfig.container.AnnotationRemoteApplicationContextProducer.getApplicationContext(AnnotationRemoteApplicationContextProducer.java:99) [arquillian-service-integration-spring-javaconfig-1.0.0.Final-20140618.175956-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.spring.integration.javaconfig.container.AnnotationRemoteApplicationContextProducer.createApplicationContext(AnnotationRemoteApplicationContextProducer.java:67) [arquillian-service-integration-spring-javaconfig-1.0.0.Final-20140618.175956-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.spring.integration.javaconfig.container.AnnotationRemoteApplicationContextProducer.createApplicationContext(AnnotationRemoteApplicationContextProducer.java:1) [arquillian-service-integration-spring-javaconfig-1.0.0.Final-20140618.175956-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.container.spring.embedded.SpringEmbeddedApplicationContextLifeCycleHandler.createApplicationContext(SpringEmbeddedApplicationContextLifeCycleHandler.java:180) [arquillian-service-container-spring-1.0.0.Final-20140618.175856-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.container.spring.embedded.SpringEmbeddedApplicationContextLifeCycleHandler.createTestApplicationContext(SpringEmbeddedApplicationContextLifeCycleHandler.java:150) [arquillian-service-container-spring-1.0.0.Final-20140618.175856-2.jar:1.0.0.Final-SNAPSHOT]

          at org.jboss.arquillian.container.spring.embedded.SpringEmbeddedApplicationContextLifeCycleHandler.beforeClass(SpringEmbeddedApplicationContextLifeCycleHandler.java:88) [arquillian-service-container-spring-1.0.0.Final-20140618.175856-2.jar:1.0.0.Final-SNAPSHOT]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]

          at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92) [arquillian-test-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]

          at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73) [arquillian-test-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]

          at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116) [arquillian-core-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87) [arquillian-test-impl-base-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:201) [arquillian-junit-core-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:422) [arquillian-junit-core-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54) [arquillian-junit-core-1.1.7.Final.jar:1.1.7.Final]

          at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218) [arquillian-junit-core-1.1.7.Final.jar:1.1.7.Final]

          at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]

          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166) [arquillian-junit-core-1.1.7.Final.jar:1.1.7.Final]

          at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.12.jar:4.12]

          at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) [junit-rt.jar:na]

          at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) [junit-rt.jar:na]

          at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) [junit-rt.jar:na]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]

          at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]

          at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:130) [idea_rt.jar:na]