11 Replies Latest reply on Jul 5, 2012 1:26 PM by bmajsak

    @ApplyScriptBefore("import.sql")

    mano_seba

      Hello,

       

       

      I tried to add the @ApplyScriptBefore for the arquillian unit testing, but is not working,all tests seem to pass even if it they shouldnt, it's a sort of test skip.

       

      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

       

      I added the depenency:

       

                <dependency>

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

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

                  <version>1.0.0.Alpha4</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

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

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

                  <version>1.0.0.Alpha4</version>

                  <scope>test</scope>

              </dependency>

       

      And the test look like this:

       

      public class CaseServiceTest extends Arquillian{

       

      @Deployment

      public static WebArchive createTestArchive() {

      return  ShrinkWrap.create( WebArchive.class,"test.war").addPackages(true,"org.joda.time")...........etc..(classes and other Resources)

      }

       

      @EJB

          private CaseService caseService;

       

       


      @BeforeTest

      @ApplyScriptBefore("import.sql")


      public void setUp()

      {}

       

       

      @Test

           public void Test(){

       

       

                Pen pen = new Pen();

                Pen = caseService.getAllPen();

       

               assertAllIPen(pen);

       

           }

      assertAllIPen(Pen pen){

       

      .......

      }

       

      The import.sql is in resources/import.sql

      INSERT INTO `PEN` (`ID_PEN`, `DATE_CREATE`, `DATE_UPDATE`, `NAME`) VALUES (1,NULL,NULL,'P');

       

       

      I looked on Mr. Bartosz Majsak blog http://arquillian.org/blog/tags/persistence/ but I didn't find a way that works for me

       

      Sorry for my bad english.

       

      Best Regards,

      Sebastian

        • 1. Re: @ApplyScriptBefore("import.sql")
          bmajsak

          Try using this annotation either on class level (will be run for each test), or on the test method itself.

          1 of 1 people found this helpful
          • 2. Re: @ApplyScriptBefore("import.sql")
            mano_seba

            Hello,

             

            Well that was fast,I didnt finished writing and I got the answer. I will try this right now. Thank you very much for such a quick answer.

            • 3. Re: @ApplyScriptBefore("import.sql")
              mano_seba

              Well I used the annotation on class level and on the method itself but It didnt work for me.

              My arquillian.xml looks like this:

               


              <defaultProtocol type="Servlet 3.0"></defaultProtocol>

              <engine>


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

              </engine>

              <container qualifier="jboss" default="true">



              <configuration>



              <property name="managementAddress">localhost</property>



              <property name="managementPort">9999</property>



              <property name="javaVmArguments">-Xmx1024m -XX:MaxPermSize=256m</property>



              <property name="startupTimeoutInSeconds">6000</property>



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



              <property name="serverConfig">standalone.xml</property>
              <!--

              <property name="jbossHome">D:/jboss-as-7.1.0.Final-SNAPSHOT-2</property> 



              <property name="javaHome">D:/software/JDK/jdk160_21-32x</property>


              </configuration>

              </container>

              And I added this:



              <extension qualifier="persistence" default="true">



              <property name="userTransactionJndi">java:jboss/datasources/prjtest</property>



              <property name="initStatement">import.sql</property>


              </extension>

               

              What else I m missing over here?

              • 4. Re: @ApplyScriptBefore("import.sql")
                bmajsak

                Not sure, but transaction jndi looks a bit strange to me shouldn't it be registered for "defaultDataSource"? And as of transactionJNDI in jboss it's java:jboss/UserTransaction

                • 5. Re: @ApplyScriptBefore("import.sql")
                  mano_seba

                  In my standalone.xml it is just like that. Do you know any other reason why the unit test are skipping when I add the @ApplyScriptBefore? Before the I was using the Alpha3 whit the @UsingScript and that was also a problem because it didnt find the inport.sql but at least the tests weren't skipped, it wouldnt find the find the insert from import.sql

                  • 6. Re: @ApplyScriptBefore("import.sql")
                    bmajsak

                    Yes, but here you are saying that sivastest is jndi for user transaction. Shouldn't it be "defaultDataSource" parameter instead? And for userTransactionJndi java:jboss/UserTransaction ?

                     

                    As fo the merit - where is import.sql located?

                    • 7. Re: @ApplyScriptBefore("import.sql")
                      mano_seba

                      The import.sql is located in test/resources/import.sql...and I have a JBoss modified by someone in our team and I dont know why he did this.

                      • 8. Re: @ApplyScriptBefore("import.sql")
                        bmajsak

                        Could you please attach standalone.xml? I will try to have a look at it today or tomorrow.

                        • 9. Re: @ApplyScriptBefore("import.sql")
                          mano_seba

                          Thanks for your help:)

                          • 10. Re: @ApplyScriptBefore("import.sql")
                            mano_seba

                            Hello,

                             

                            I worked on the arquillian unit tests and for the moment I can read form the db some of the inserts, but if I have two unit test only one will pass the other one will just be skipped, but I will look that he passed.If I comment the test that works the other one will work to. Now I'm very confused.

                             

                            Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

                             

                            arquillian.xml

                             


                            <extension qualifier="persistence" default="true">



                            <property name="defaultDataSource">java:jboss/datasources/sivastest</property>



                            <property name="initStatement">scripts/import.sql</property>



                            <property name="cleanupStatement">scripts/clean.sql</property>

                            </extension>

                             

                            It seems that I dont need the userTransaction it works this way (confusing...)

                             

                            I used the annotaion on on the class


                            @ApplyScriptBefore("import.sql")

                            public class FacSrvTest extends Arquillian{

                            }

                             

                            added the resource : .addAsResource(new File("src/test/resources/scripts/import.sql")).addAsResource(new File("src/test/resources/scripts/clean.sql"))

                             

                            But I still dont know why some of the tests are workins and some of them not.

                             

                             

                            Best Regards,

                            • 11. Re: @ApplyScriptBefore("import.sql")
                              bmajsak

                              Would it be possible for you to isolate this problem and provide simple project with managed jboss and hsqldb?