5 Replies Latest reply on Sep 1, 2012 5:18 PM by jfrenetic

    Making persistence extension work with DBUnit Xml dataset and DTD

    jfrenetic Newbie

      I have an extremely simple test:

       

      @RunWith(Arquillian.class)
      public class SimpleTest {
      
                @Deployment
                public static WebArchive deploy() {
                          return ShrinkWrap.create(WebArchive.class, "test-dbunit.war")
                                              .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
                }
      
                @Test
                @Cleanup(phase = TestExecutionPhase.NONE)
                @DataSource("jdbc/TestPool")
                @UsingDataSet("init_people.xml")
                public void testStuff() { }
      
      }
      

       

      which I'm trying to run on Remote Glassfish.


      I want to initialize a very simple derby database with just one table.

       

      Here is my dataset init_people.xml:

       

      <!DOCTYPE dataset SYSTEM "test.dtd">
      <dataset>
                <PEOPLE PERSON_ID="1" PERSON="MIKE"/>
      </dataset>
      

       

      and test.dtd:

       

      <!ELEMENT dataset (
          PEOPLE*)>
      
      <!ELEMENT PEOPLE EMPTY>
      <!ATTLIST PEOPLE
          PERSON_ID CDATA #REQUIRED
          PERSON CDATA #IMPLIED
      >
      

       

      Both, dataset and DTD lie under src/test/resources/datasets:

      http://i48.tinypic.com/30vnhoj.png

       

      Using the @Deployment method above, DTD is ignored and not copied to the deployment war.

       

      But that's fine. I tried adding it as a jar to libs folder inside war, as a WEB-INF resource and to classes folder, but when running test I get the following exception:

       

      org.jboss.arquillian.persistence.data.dbunit.exception.DBUnitInitializationException: Unable to load data set from given file: datasets/init_people.xml
                at org.jboss.arquillian.persistence.data.dbunit.dataset.DataSetBuilder.build(DataSetBuilder.java:76)
                at org.jboss.arquillian.persistence.data.dbunit.DBUnitPersistenceTestLifecycleHandler.createInitialDataSet(DBUnitPersistenceTestLifecycleHandler.java:143)
                at org.jboss.arquillian.persistence.data.dbunit.DBUnitPersistenceTestLifecycleHandler.createInitialDataSets(DBUnitPersistenceTestLifecycleHandler.java:133)
                at org.jboss.arquillian.persistence.data.dbunit.DBUnitPersistenceTestLifecycleHandler.initializeDataSeeding(DBUnitPersistenceTestLifecycleHandler.java:99)
      ....
      Caused by: org.dbunit.dataset.DataSetException: java.io.FileNotFoundException: C:\java\glassfish-3.1.2.2\glassfish\domains\domain1\config\test.dtd (The system cannot find the file specified)
                at org.dbunit.dataset.xml.FlatXmlProducer.produce(FlatXmlProducer.java:378)
                at org.dbunit.dataset.CachedDataSet.<init>(CachedDataSet.java:97)
                at org.dbunit.dataset.xml.FlatXmlDataSet.<init>(FlatXmlDataSet.java:110)
                at org.dbunit.dataset.xml.FlatXmlDataSetBuilder.buildInternal(FlatXmlDataSetBuilder.java:264)
                at org.dbunit.dataset.xml.FlatXmlDataSetBuilder.build(FlatXmlDataSetBuilder.java:147)
                at org.jboss.arquillian.persistence.data.dbunit.dataset.DataSetBuilder.loadXmlDataSet(DataSetBuilder.java:109)
                at org.jboss.arquillian.persistence.data.dbunit.dataset.DataSetBuilder.build(DataSetBuilder.java:59)
                ... 139 more
      Caused by: java.io.FileNotFoundException: C:\java\glassfish-3.1.2.2\glassfish\domains\domain1\config\test.dtd (The system cannot find the file specified)
                at java.io.FileInputStream.open(Native Method)
                at java.io.FileInputStream.<init>(FileInputStream.java:120)
                at java.io.FileInputStream.<init>(FileInputStream.java:79)
                at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
                at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
                at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:651)
      ...
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
                at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
                at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
                at org.dbunit.dataset.xml.FlatXmlProducer.produce(FlatXmlProducer.java:365)
                ... 145 more
      

       

      While debugging I found out that the dataset is being built from following location:

      C:/java/glassfish-3.1.2.2/glassfish/domains/domain1/generated/jsp/test-persistence/loader_1120070433/datasets/init_people.xml

       

      http://i47.tinypic.com/xqe6pc.png

       

      I understand that it's more likely DBUnit problem, but maybe something could be done by Arquillian team to support DTD resources?

       

      I attached pom.xml, just in case.