5 Replies Latest reply: Apr 25, 2012 5:33 AM by Manolescu Sebastian RSS

Arquillian @UsingScript problem

Manolescu Sebastian Newbie

Hello,

 

 

I have a problem whit the arquillian h2 database,  the @UsingScript("import.sql") it doesn't insert the data into prjtest database. I can save in the prjtest database but cant add data using import.sql

Can someone give me an idea how can I make this work?

 

I added the dependecy arquillian-persistence-api and if I comment the @UsingScript("import.sql") it will give me error....and this makes me realize that the annotaions is working...so what might be the problem?

 

//pom.xml

 

<dependency>

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

            <artifactId>arquillian-testng-container</artifactId>

            <version>1.0.0.CR7</version> <!-- 1.0.0.CR7 -->

            <scope>test</scope>

        </dependency>

 

<dependency>

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

            <artifactId>arquillian-persistence-api</artifactId>

            <version>1.0.0.Alpha3</version>

            <scope>test</scope>

        </dependency>

 

//Location.java

 

public class LocationServiceTest extends Arquillian{

private final String TEST_VALUE = "test";

 

@Deployment

       public static WebArchive createTestArchive() {

         return      ShrinkWrap.create( WebArchive.class,"test.war").addPackages(true,"org.joda.time").addPackages(true, "javax.jcr").addClasses(com.mysql.jdbc.log.Log.class,com.project.Location).addPackage("org.slf4j").addPackage("org.slf4j.spi").addPackage("org.slf4j.helpers").addAsWebInfResource("test-persistence.xml", "classes/META-INF/persistence.xml").addAsWebInfResource("beans.xml", "META-INF/beans.xml");

     }

 

@BeforeTest

   

     @UsingScript("import.sql")

     public void setUp()

     {}

@EJB

private Location loc;

 

@Test

public void LocationTest(){

      

      Marking mk = new Marking();

      loc.save(mk);

}

 

 

 

//test-persistence.xml

 

 

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

<!-- Persistence deployment descriptor for dev profile -->

 

<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="prj-unit">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <jta-data-source>java:jboss/datasources/prjtest</jta-data-source>

        <properties>

            <property name="hibernate.hbm2ddl.auto" value="update" />

            <property name="hibernate.show_sql" value="true" />

        </properties>

    </persistence-unit>

   

</persistence>

 

 

//standalone.xml

 

<datasource jndi-name="java:jboss/datasources/prjtest" pool-name="prjtest" enabled="true">

                    <connection-url>

                        jdbc:h2:mem:prjtest;MODE=MYSQL;TRACE_LEVEL_FILE=2;TRACE_LEVEL_SYSTEM_OUT=2

                    </connection-url>

                    <driver>

                        h2

                    </driver>

                    <security>

                        <user-name>

                            sa

                        </user-name>

                        <password>

                            sa

                        </password>

                    </security>

                </datasource>

 

          driver name="h2" module="com.h2database.h2">

                        <xa-datasource-class>

                            org.h2.jdbcx.JdbcDataSource

                        </xa-datasource-class>

                    </driver>

 

 

 

//import.sql

 

INSERT INTO `TEMPLATE` (`TEMPLATE_ID`, `NAME`) VALUES (1,'Template');

 

 

 

How can I insert the data from TEMPLATE into the prjtest h2 database.

 

 

Best Regards

  • 1. Re: Arquillian @UsingScript problem
    Bartosz Majsak Master

    Hi Sebastian,

     

    you should also add arquillian-persistence-impl artifact to your dependencies. Try to put the annotation on the test method, or alternatively put it on the class level so it will be executed for each test (if the test itself does not have the same annotation, then it takes precedence).

     

    Hope that helps.

     

    Cheers,

    Bartosz

  • 2. Re: Arquillian @UsingScript problem
    Manolescu Sebastian Newbie

    Hi Majsak,

     

    Thank you for your response,I have the arquillian-persistence-impl artefact just forgot to mention this.


    <dependency>

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

                <artifactId>arquillian-persistence-impl</artifactId>

                <version>1.0.0.Alpha3</version>

                <scope>test</scope>

            </dependency>

     

    If the annotation is deleted then the warning appears:Cannot use this JDK-based implementation to export as ZIP an archive with no content .... so the arquillian-persistence-impl is working.

    I tried to add the annotation on the test method and on the class...but for the moment the @UsingScript doesen't work. The database works, the tables are created....but the insert does not happen.

     

     

    Best Regards

  • 3. Re: Arquillian @UsingScript problem
    Bartosz Majsak Master

    Do you think you would be able to isolate this problem and shared simplified project so I can have a look? (GitHub would work perfectly so I can clone your repo and if I fix it I can send pull request )

     

    Cheers,

    Bartosz

  • 4. Re: Arquillian @UsingScript problem
    Bartosz Majsak Master

    Please try to update to Alpha4 version and use @ApplyScriptBefore annotation on test level. For Alpha5 I'm currently working on the class-level annotation where you can define you schema creation and any other SQL script. Let me know if A4 solved your problem.

  • 5. Re: Arquillian @UsingScript problem
    Manolescu Sebastian Newbie

    Thank you very much for your help, I will try as soon as possible and I will tell you if it worked.