2 Replies Latest reply on Jan 10, 2013 10:21 AM by Kirill Lassounski

    Persistence Extension Not Loading YAML File

    Kirill Lassounski Newbie

      Hello everyone!

      I started using arquillian a few week ago and find it a very interesting and powerful integration testing tool.

      But it seems that there is some kind of problem with the YAML files because it works When I use XML.

       

      I am using Maven, Glassfish 3.1.2 and MySQL.

      Right now I am trying to use the Arquillian Persistence Extension to populate my DataBase using the YAML file format.

      But I am getting this Exception saying that it is impossible to cast a List to a String.

      But where is the List !?

      Here is the Exception:

       

      ------------- Standard Output ---------------

      estadoDoProdutoEjb.war:

      /WEB-INF/

      /WEB-INF/lib/

      /WEB-INF/lib/eclipselink-2.3.2.jar

      /WEB-INF/beans.xml

      /WEB-INF/classes/

      /WEB-INF/classes/com/

      /WEB-INF/classes/com/delaru/

      /WEB-INF/classes/com/delaru/pexincha/

      /WEB-INF/classes/com/delaru/pexincha/entidades/

      /WEB-INF/classes/com/delaru/pexincha/entidades/EstadoDoProduto_.class

      /WEB-INF/classes/com/delaru/pexincha/entidades/EstadoDoProduto.class

      /WEB-INF/classes/com/delaru/pexincha/util/

      /WEB-INF/classes/com/delaru/pexincha/util/GerenciadorPU.class

      /WEB-INF/classes/com/delaru/pexincha/ejb/

      /WEB-INF/classes/com/delaru/pexincha/ejb/EstadoDoProdutoEJB.class

      /WEB-INF/classes/com/delaru/pexincha/ejb/EstadoDoProdutoEJBLocal.class

      /WEB-INF/classes/com/delaru/pexincha/ejb/EJBAbstrato.class

      /WEB-INF/classes/META-INF/

      /WEB-INF/classes/META-INF/persistence.xml

       

      ------------- ---------------- ---------------

      Testcase: shouldPopulateDatabase(com.delaru.pexincha.entidades.ejb.EstadoDoProduto_IT):    Caused an ERROR

      Unable to load data set from given file: datasets/estadoDoProduto.yml

      org.jboss.arquillian.persistence.dbunit.exception.DBUnitInitializationException: Unable to load data set from given file: datasets/estadoDoProduto.yml

          at org.jboss.arquillian.persistence.dbunit.dataset.DataSetBuilder.build(DataSetBuilder.java:76)

          at org.jboss.arquillian.persistence.dbunit.data.descriptor.DataSetResourceDescriptor.getContent(DataSetResourceDescriptor.java:46)

          at org.jboss.arquillian.persistence.dbunit.DBUnitPersistenceTestLifecycleHandler.createInitialDataSets(DBUnitPersistenceTestLifecycleHandler.java:160)

          at org.jboss.arquillian.persistence.dbunit.DBUnitPersistenceTestLifecycleHandler.createDatasets(DBUnitPersistenceTestLifecycleHandler.java:98)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.persistence.dbunit.DBUnitPersistenceTestLifecycleHandler.createDatabaseConnection(DBUnitPersistenceTestLifecycleHandler.java:87)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.persistence.core.lifecycle.ErrorCollectorHandler.createErrorCollector(ErrorCollectorHandler.java:38)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)

          at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

          at org.jboss.arquillian.persistence.core.lifecycle.PersistenceTestTrigger.beforeTest(PersistenceTestTrigger.java:104)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

          at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)

          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:95)

          at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:222)

          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

          at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

          at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)

          at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)

          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

          at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

          at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)

          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)

          at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)

          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160)

          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)

          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)

          at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

          at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)

          at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)

          at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)

          at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)

          at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)

          at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)

          at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)

          at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)

          at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

          at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

          at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

          at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

          at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

          at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

          at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

          at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

          at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

          at java.lang.Thread.run(Thread.java:722)

      Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List

          at org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSetProducer.createTables(YamlDataSetProducer.java:119)

          at org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSetProducer.produce(YamlDataSetProducer.java:74)

          at org.dbunit.dataset.CachedDataSet.<init>(CachedDataSet.java:97)

          at org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet.<init>(YamlDataSet.java:60)

          at org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet.<init>(YamlDataSet.java:85)

          at org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet.<init>(YamlDataSet.java:80)

          at org.jboss.arquillian.persistence.dbunit.dataset.DataSetBuilder.loadYamlDataSet(DataSetBuilder.java:92)

          at org.jboss.arquillian.persistence.dbunit.dataset.DataSetBuilder.build(DataSetBuilder.java:65)

       

      Now, let's see the code:

      EstadoDoProduto = StateOfTheProduct, I am modeling a store.

       

      estadoDoProduto.yml


      ESTADO_DO_PRODUTO:

        -id:1

         nome:New

        -id:2

         nome:Used

        -id:3

         nome:Broken

       

      EstadoDoProduto_IT.java


      package com.delaru.pexincha.entidades.ejb;

       

      import com.delaru.pexincha.ejb.EJBAbstrato;

      import com.delaru.pexincha.ejb.EstadoDoProdutoEJB;

      import com.delaru.pexincha.ejb.EstadoDoProdutoEJBLocal;

      import com.delaru.pexincha.entidades.EstadoDoProduto;

      import com.delaru.pexincha.entidades.EstadoDoProduto_;

      import com.delaru.pexincha.util.GerenciadorPU;

      import java.util.List;

      import javax.ejb.EJB;

      import static org.hamcrest.Matchers.*;

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.arquillian.persistence.UsingDataSet;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.asset.EmptyAsset;

      import org.jboss.shrinkwrap.api.spec.WebArchive;

      import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;

      import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;

      import static org.junit.Assert.*;

      import org.junit.Test;

      import org.junit.runner.RunWith;

       

      /**

      *

      * @author kirill

      */

      @RunWith(Arquillian.class)

      public class EstadoDoProduto_IT {

       

          private @EJB  EstadoDoProdutoEJBLocal estadoDoProdutoEJB;

       

          @Deployment

          public static WebArchive createDeployment() {

              MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom("pom.xml");

       

              WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "estadoDoProdutoEjb.war")

                      .addAsLibraries(resolver.artifact("org.eclipse.persistence:eclipselink").resolveAsFiles())

                      .addClasses(EstadoDoProduto.class, EstadoDoProdutoEJBLocal.class,

                      EstadoDoProdutoEJB.class, EJBAbstrato.class, EstadoDoProduto_.class, GerenciadorPU.class)

                      .addAsResource("META-INF/arquillian-persistence.xml", "META-INF/persistence.xml")

                      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

              System.out.println(webArchive.toString(true));

              return webArchive;

          }

       

          @Test

          @UsingDataSet("estadoDoProduto.yml")

          public void shouldPopulateDatabase() {

              //given that

              List<EstadoDoProduto> estadoDosProdutos = estadoDoProdutoEJB.buscarTodos();

              //when

              estadoDosProdutos = estadoDoProdutoEJB.buscarTodos();

              //then

              assertThat(estadoDosProdutos, hasSize(4));

          }

      }

       

       

      EstadoDoProduto.java


      package com.delaru.pexincha.entidades;

       

      import java.io.Serializable;

      import javax.persistence.Column;

      import javax.persistence.Entity;

      import javax.persistence.GeneratedValue;

      import javax.persistence.GenerationType;

      import javax.persistence.Id;

      import javax.persistence.NamedQuery;

      import javax.persistence.SequenceGenerator;

      import javax.persistence.Table;

       

      /**

      *

      * @author kirill

      */

      @Entity

      @Table(name = "ESTADO_DO_PRODUTO")

      @NamedQuery(name = EstadoDoProduto.BUSCAR_POR_NOME, query = "SELECT ep FROM EstadoDoProduto ep WHERE LOWER(ep.nome) LIKE :nome")

      public class EstadoDoProduto implements Serializable {

       

          private static final Long serialVersionUID = 2L;

          //

          public static final String BUSCAR_POR_NOME = "EstadoDoProduto.BUSCAR_POR_NOME";

          //

          @Id

          @GeneratedValue(strategy = GenerationType.AUTO, generator="estado_do_produto_seq_gen")

          @SequenceGenerator(name="estado_do_produto_seq_gen", sequenceName="ESTADO_DO_PRODUTO_SEQ")

          private Long id;

          //

          @Column(length = 40, nullable = false, unique = true)

          private String nome;

       

          //getters and setters ommited

      }

       

       

      pesistence.xml (I have it all configured in the remote Glassfish Server (Pool and DataSource))

       

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

      <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

        <persistence-unit name="MYSQL_TEST_JTA" transaction-type="JTA">

          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

          <jta-data-source>jdbc/pexincha-test</jta-data-source>

          <exclude-unlisted-classes>false</exclude-unlisted-classes>

          <properties>

            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

            <property name="eclipselink.logging.level" value="FINE"/>

            <property name="eclipselink.logging.parameters" value="true"/>

            <property name="javax.persistence.jdbc.password" value="root"/>

            <property name="javax.persistence.jdbc.user" value="root"/>

          </properties>

        </persistence-unit>

      </persistence>

       

      arquillian.xml


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

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

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

       

          <extension qualifier="persistence-dbunit">

              <property name="datatypeFactory">org.dbunit.ext.mysql.MySqlDataTypeFactory</property>

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

          </extension>

      </arquillian>

       

       

      Thanks for the framework and for the help!