4 Replies Latest reply on Jul 13, 2016 9:40 AM by Bartosz Majsak

    JBoss Arquillian: Spring MVC Integration

    Anup Ghosh Newbie

      I am just trying to integrate one of my existing Spring MVC application with Arquillian integration test. So far no luck.

      My application structure

      Core Module, Web Module and Test Module. I am trying to test my Core Module which is Spring Hibernate data layer. Test module contains all the test cases. Web Module depends on the core module and test module. Test module depends on the core module.

      I am generating .war using maven. The .war contains the core module as well as test module in WEB-INF/lib as dependency. I am using embedded tomcat 7.

      But while running the test case I am getting the below exception

      org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
      at org
      .springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)
      at org
      .springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
      at org
      .springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
      at org
      .springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
      at org
      .springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
      at org
      .springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
      at org
      .springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
      at org
      .springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
      at org
      .springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
      at org
      .springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:605)
      at org
      .springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509)
      at org
      .springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
      at org
      .springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
      at org
      .springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
      at org
      .apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
      at org
      .apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
      at org
      .apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org
      .apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
      at org
      .apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
      at org
      .apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
      at org
      .apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
      at org
      .apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653)
      at java
      .util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java
      .util.concurrent.FutureTask.run(FutureTask.java:262)
      at java
      .util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java
      .util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java
      .lang.Thread.run(Thread.java:745)
      Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
      at com
      .sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
      at com
      .sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
      at com
      .sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
      at com
      .sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
      at com
      .sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1437)
      at com
      .sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1019)
      at com
      .sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
      at com
      .sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
      at com
      .sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:503)
      at com
      .sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
      at com
      .sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
      at com
      .sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
      at com
      .sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
      at com
      .sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:338)
      at org
      .springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
      at org
      .springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
      at org
      .springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
      ... 26 more


      My aquillian.xml

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://jboss.org/schema/arquillian"
      xsi:schemaLocation="http://jboss.org/schema/arquillian
      http://jboss.org/schema/arquillian/arquillian_1_0.xsd"
      >
      <container qualifier="tomcat" default="true">
        
      <configuration>
        
      <property name="tomcatHome">target/tomcat-embedded-7</property>
        
      <property name="workDir">work</property>
        
      <property name="bindHttpPort">8888</property>
        
      <property name="unpackArchive">true</property>
        
      <property name="serverName">arquillian-tomcat-embedded-7</property>
        
      </configuration>
      </container>
      <extension qualifier="spring-deployer">
        
      <property name="autoPackage">false</property>
      </extension>
      </arquillian>


      My pom.xml


      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>

      <parent>
        
      <groupId>com.test</groupId>
        
      <artifactId>myApp-parent</artifactId>
        
      <version>0.0.1-SNAPSHOT</version>
      </parent>

      <artifactId>myApp-test</artifactId>
      <version>1.0</version>
      <packaging>jar</packaging>
      <name>myApp-test</name>
      <description>This is a test module of entire ear</description>

      <properties>
        
      <java-version>1.7</java-version>
        
      <org.springframework-version>4.2.2.RELEASE</org.springframework-version>
        
      <org.slf4j-version>1.7.12</org.slf4j-version>
      </properties>

      <!-- Arquillian CORE Dependencies -->
      <dependencyManagement>
        
      <dependencies>
        
      <dependency>
        
      <groupId>org.jboss.arquillian</groupId>
        
      <artifactId>arquillian-bom</artifactId>
        
      <version>1.1.11.Final</version>
        
      <type>pom</type>
        
      <scope>import</scope>
        
      </dependency>
        
      </dependencies>
      </dependencyManagement>

      <dependencies>
        
      <!-- Project module dependencies -->
        
      <dependency>
        
      <groupId>com.test</groupId>
        
      <artifactId>myApp-core</artifactId>
        
      <version>1.0</version>
        
      <type>jar</type>
        
      </dependency>

        
      <!-- Spring -->
        
      <dependency>
        
      <groupId>org.springframework</groupId>
        
      <artifactId>spring-context</artifactId>
        
      <version>${org.springframework-version}</version>
        
      <exclusions>
        
      <!-- Exclude Commons Logging in favor of SLF4j -->
        
      <exclusion>
        
      <groupId>commons-logging</groupId>
        
      <artifactId>commons-logging</artifactId>
        
      </exclusion>
        
      </exclusions>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.springframework</groupId>
        
      <artifactId>spring-webmvc</artifactId>
        
      <version>${org.springframework-version}</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.springframework</groupId>
        
      <artifactId>spring-jdbc</artifactId>
        
      <version>${org.springframework-version}</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.springframework</groupId>
        
      <artifactId>spring-orm</artifactId>
        
      <version>${org.springframework-version}</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.springframework.data</groupId>
        
      <artifactId>spring-data-commons-core</artifactId>
        
      <version>1.1.0.RELEASE</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>mysql</groupId>
        
      <artifactId>mysql-connector-java</artifactId>
        
      <version>5.1.6</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>javax.servlet</groupId>
        
      <artifactId>jstl</artifactId>
        
      <version>1.2</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>com.itextpdf</groupId>
        
      <artifactId>itextpdf</artifactId>
        
      <version>5.5.9</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.codehaus.jackson</groupId>
        
      <artifactId>jackson-mapper-lgpl</artifactId>
        
      <version>1.6.7</version>
        
      </dependency>

        
      <!-- Logging -->
        
      <dependency>
        
      <groupId>org.slf4j</groupId>
        
      <artifactId>slf4j-api</artifactId>
        
      <version>${org.slf4j-version}</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.slf4j</groupId>
        
      <artifactId>jcl-over-slf4j</artifactId>
        
      <version>${org.slf4j-version}</version>
        
      <scope>runtime</scope>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.slf4j</groupId>
        
      <artifactId>slf4j-log4j12</artifactId>
        
      <version>${org.slf4j-version}</version>
        
      <scope>runtime</scope>
        
      </dependency>
        
      <dependency>
        
      <groupId>log4j</groupId>
        
      <artifactId>log4j</artifactId>
        
      <version>1.2.16</version>
        
      <scope>runtime</scope>
        
      </dependency>

        
      <dependency>
        
      <groupId>javax.servlet.jsp</groupId>
        
      <artifactId>jsp-api</artifactId>
        
      <version>2.1</version>
        
      <scope>provided</scope>
        
      </dependency>
        
      <dependency>
        
      <groupId>javax.servlet.jsp.jstl</groupId>
        
      <artifactId>jstl-api</artifactId>
        
      <version>1.2</version>
        
      <exclusions>
        
      <exclusion>
        
      <groupId>javax.servlet</groupId>
        
      <artifactId>servlet-api</artifactId>
        
      </exclusion>
        
      </exclusions>
        
      </dependency>

        
      <!-- Jackson JSON Processor -->
        
      <dependency>
        
      <groupId>com.fasterxml.jackson.core</groupId>
        
      <artifactId>jackson-databind</artifactId>
        
      <version>2.5.3</version>
        
      </dependency>

        
      <!-- JSR 303 with Hibernate Validator -->
        
      <dependency>
        
      <groupId>javax.validation</groupId>
        
      <artifactId>validation-api</artifactId>
        
      <version>1.0.0.GA</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.hibernate</groupId>
        
      <artifactId>hibernate-core</artifactId>
        
      <version>4.1.0.Final</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.hibernate</groupId>
        
      <artifactId>hibernate-validator</artifactId>
        
      <version>4.1.0.Final</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>junit</groupId>
        
      <artifactId>junit</artifactId>
        
      <version>4.11</version>
        
      <scope>compile</scope>
        
      </dependency>

        
      <!-- Arquillian Unit Testing Container (JUNIT) -->
        
      <dependency>
        
      <groupId>org.jboss.arquillian.junit</groupId>
        
      <artifactId>arquillian-junit-container</artifactId>
        
      <scope>test</scope>
        
      </dependency>

        
      <!-- Arquillian Suite Extension -->
        
      <dependency>
        
      <groupId>org.eu.ingwar.tools</groupId>
        
      <artifactId>arquillian-suite-extension</artifactId>
        
      <version>1.1.2</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.arquillian.extension</groupId>
        
      <artifactId>arquillian-service-deployer-spring-3</artifactId>
        
      <version>1.0.0.Beta3</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.arquillian.extension</groupId>
        
      <artifactId>arquillian-service-integration-spring-inject</artifactId>
        
      <version>1.1.0.Alpha1</version>
        
      <scope>test</scope>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.apache.tomcat</groupId>
        
      <artifactId>tomcat-dbcp</artifactId>
        
      <version>7.0.34</version>
        
      </dependency>

      </dependencies>

      <profiles>
        
      <!-- Tomcat Embedded -->
        
      <profile>
        
      <id>arquillian-tomcat-embedded</id>
        
      <activation>
        
      <activeByDefault>true</activeByDefault>
        
      </activation>
        
      <dependencies>
        
      <dependency>
        
      <groupId>org.jboss.arquillian.container</groupId>
        
      <artifactId>arquillian-tomcat-embedded-7</artifactId>
        
      <version>1.0.0.CR5</version>
        
      <scope>test</scope>
        
      </dependency>

        
      <!-- org.apache.tomcat -->
        
      <dependency>
        
      <groupId>org.apache.tomcat.embed</groupId>
        
      <artifactId>tomcat-embed-core</artifactId>
        
      <version>7.0.42</version>
        
      <scope>provided</scope>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.apache.tomcat.embed</groupId>
        
      <artifactId>tomcat-embed-jasper</artifactId>
        
      <version>7.0.42</version>
        
      <scope>provided</scope>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.apache.tomcat.embed</groupId>
        
      <artifactId>tomcat-embed-logging-juli</artifactId>
        
      <version>7.0.42</version>
        
      <scope>provided</scope>
        
      </dependency>
        
      <dependency>
        
      <groupId>org.eclipse.jdt.core.compiler</groupId>
        
      <artifactId>ecj</artifactId>
        
      <version>3.7</version>
        
      <scope>provided</scope>
        
      </dependency>

        
      <!-- Weld for Dependency Injection @Inject -->
        
      <dependency>
        
      <groupId>org.jboss.weld.servlet</groupId>
        
      <artifactId>weld-servlet</artifactId>
        
      <version>1.1.9.Final</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.shrinkwrap.resolver</groupId>
        
      <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
        
      <scope>test</scope>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.arquillian.extension</groupId>
        
      <artifactId>arquillian-service-deployer-spring-3</artifactId>
        
      <version>1.0.0.Beta3</version>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.arquillian.extension</groupId>
        
      <artifactId>arquillian-service-integration-spring-inject</artifactId>
        
      <version>1.1.0.Alpha1</version>
        
      <scope>test</scope>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.arquillian.extension</groupId>
        
      <artifactId>arquillian-transaction-spring</artifactId>
        
      <version>1.1.0.Alpha1</version>
        
      <scope>test</scope>
        
      </dependency>

        
      <dependency>
        
      <groupId>org.jboss.arquillian.extension</groupId>
        
      <artifactId>arquillian-transaction-api</artifactId>
        
      <version>1.0.3.Final</version>
        
      <scope>test</scope>
        
      </dependency>

        
      </dependencies>
        
      </profile>
      </profiles>

      </project>


      My Suite Deployment class

      import java.io.File;

      import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquillianSuiteDeployment;
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.shrinkwrap.api.ArchivePaths;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.WebArchive;

      @ArquillianSuiteDeployment
      public class SuiteDeployer {

      private static final String warFilePath = "../myApp-web/target/myApp-web-1.0.war";

      @Deployment(name="normal")
      public static WebArchive deployBuild() {
        
      WebArchive webArchive = null;
        
      try {
        
      System.out.println("Deploying WAR...");
        
      File warFile = new File(warFilePath);
        webArchive
      =  ShrinkWrap.createFromZipFile(WebArchive.class, warFile)
        
      .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("applicationContext.xml"));
        
      } catch (Exception e) {
        e
      .printStackTrace();
        
      }

        
      return webArchive;
      }
      }


      My Test case

      import org.jboss.arquillian.container.test.api.OperateOnDeployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.springframework.data.domain.PageRequest;
      import org.springframework.data.domain.Pageable;

      @RunWith(Arquillian.class)
      public class LaunchArquillian {

      @Test
      @OperateOnDeployment("normal")
      public void testGetMessage() {
        
      ExplorerServiceImpl explorerServiceImpl = new ExplorerServiceImpl();
        
      Pageable pageable = new PageRequest(0, 25);
        explorerServiceImpl
      .getConnAllDetails (pageable, "CREATION_DT", "ASC", null, false);
      }
      }


      Expert please help to resolve this issue.