1 Reply Latest reply on Jul 16, 2008 10:19 PM by enda

    SeamTest - Linux - GUIDE!!!!

    enda

      Linux SeamTest GUIDE



      Hello all LINUX friendly friends,


      I spent enormous time with configuring my project to be able to run SeamTest and arter many days here is the guide to do that.


      First I would like to note that it seems that about 95% people are using Windows, that is why they might not have similar problems.


      quick links:



      1. general info

      2. nice note




      •   look for pete@muir

      •   seam doc is hiding this! Embedded JBoss exposes stuff at #{ejbName}/local not ear-name/#{ejbName}/local





      System changes



      I am using Gentoo which has problem with open files (1024 by default). If you will be satisfied with running tests as root then you can increase file limit by

      ulimit -n 16384

      , this will be a bed solution so better is to modify /etc/security/limits.conf and add:


      *               soft    nofile          16384
      *               hard    nofile          16384



      logout and login, this will increase open file limit.



      Configuration


      We are running MySQL with our test which requires to ad DataSource file to bootstrap/deploy/ eg.


      bootstrap/deploy/oskar-ds.xml



      here is our build.xml segment used for testing:


      ...
      <target name="clean" description="Cleans up the build directory">
                      <delete dir="${dist.dir}"/>
                      <delete dir="${ear.dir}"/>
                      <delete dir="${war.dir}"/>
                      <delete dir="${jar.dir}"/>
                        <delete dir="${src.schema.dir}" failonerror="no"/>
                      <delete dir="${basedir}/test-report"/>
                      <delete dir="${basedir}/test-output"/>
                      <delete failonerror="no">
                              <fileset dir="${test.dir}">
                                      <exclude name="**/*.class" if="eclipse.running"/>
                              </fileset>
                      </delete>
              </target>
      
              <target name="compiletest" unless="eclipse.running" description="Compile the Java source code for the tests">
              <mkdir dir="${test.dir}"/>
              <javac classpathref="build.classpath"
                              destdir="${test.dir}"
                                debug="${javac.debug}"
                          deprecation="${javac.deprecation}"
                              nowarn="on"
                              target="1.5">
                           <!-- notice the target!!!! -->
                      <src path="${src.action.dir}" />
                      <src path="${src.model.dir}" />
                      <src path="${src.service.dir}" />
                       <src path="${src.oskartest.dir}" />
                   
                   
              </javac>
              </target>
              
              <target name="copytestclasses" if="eclipse.running" description="Copy classes compiled by eclipse to the test dir">
              <mkdir dir="${test.dir}"/>
                      <copy todir="${test.dir}">
                              <fileset dir="classes/model">
                                      <include name="**/*.class"/>
                              </fileset>
                      </copy>
                      <copy todir="${test.dir}">
                              <fileset dir="classes/action">
                                      <include name="**/*.class"/>
                              </fileset>
                      </copy>
                      <copy todir="${test.dir}">
                              <fileset dir="classes/service">
                                      <include name="**/*.class"/>
                              </fileset>
                      </copy>
                      <copy todir="${test.dir}">
                              <fileset dir="classes/resources">
                                      <include name="**/*.*"/>
                                      <!-- exclude things like this!!! -->    
                                       <exclude name="hibernate.properties"/>
                                      
                              </fileset>
                      </copy>
                      <copy todir="${test.dir}">
                              <fileset dir="classes/test">
                                      <include name="**/*.class"/>
                              </fileset>
                      </copy>
              </target>
              
              <target name="buildtest" depends="compiletest,copytestclasses" description="Build the tests">
                      <copy todir="${test.dir}">
                              <fileset dir="${basedir}/resources">
                                      <exclude name="META-INF/persistence*.xml"/>
                                      <exclude name="import*.sql"/>
                                      <exclude name="${project.name}-*-ds.xml"/>
                              </fileset>
                      </copy>
                         <copy todir="${test.dir}">
                               <fileset dir="view"/>
                      </copy>
                      <!--
                       <copy tofile="${test.dir}/META-INF/persistence.xml" 
                              file="${basedir}/resources/META-INF/persistence-test.xml"
                         overwrite="true"/>
                       -->
                       <copy tofile="${test.dir}/META-INF/persistence.xml" 
                              file="${basedir}/resources/META-INF/persistence-dev.xml"
                         overwrite="true"/>
                    
                       <copy tofile="${test.dir}/import.sql" 
                              file="${basedir}/resources/import-test.sql"
                         overwrite="true"/>
                      <copy todir="${test.dir}" flatten="true">
                              <fileset dir="${src.test.backend.dir}">
                                      <include name="**/*Test.xml" />
                              </fileset>
                              <fileset dir="${src.test.frontend.dir}">
                                      <include name="**/*Test.xml" />
                              </fileset>
                      </copy>
              </target>
      
              <target name="test" depends="buildtest" description="Run the tests">            
                      <taskdef resource="testngtasks" classpath="${testng.jar}" />
                        <path id="test.path">
                             <path path="${test.dir}" />
                             <fileset dir="${lib.dir}/test">
                                  <include name="*.jar"/>
                             </fileset>
                             <fileset dir="${lib.dir}/">
                                  <include name="jboss-embedded-api.jar"/>
                                  <include name="jboss-seam.jar"/>
                                  <include name="jboss-el.jar"/>
                                  <include name="jsf-api.jar"/>
                                  <include name="activation.jar"/>
                             </fileset>
                             <path path="${bootstrap.dir}" />
                             <path refid="build.classpath" />
                        </path>
                      <testng outputdir="${basedir}/test-report">
                          <classpath refid="test.path" />
                          <xmlfileset dir="${test.dir}" includes="*Test.xml" />
                      </testng>
              </target>
      ...



      Your components.xml will need two blocks:


      <!--  app 
         <core:init jndi-pattern="oskar/#{ejbName}/local"/>
       -->
       <!--  test  
       -->
         <core:init jndi-pattern="#{ejbName}/local"/>



      Run the tests from command line




      1. Java 5 only but that is not it!





      1. go to your project

      2. select java 6




      • eselect java-vm set system 3




      1. type




      • ant clean

      • ant compiletest




      1. select java 5




      • eselect java-vm set system 2

      • ant test




      1. after you are done ant clean



      Run you test from Eclipse



      so start eclipse



      • choose project compilation in Java 5 compatibility




      1. Run

      2. Open Run Dialog

      3. TestNG

      4. Project : test

      5. Suite : /home/cerny/workspace/Oskar/simple-testng.xml

      6. goto classpath

      7. Bootstrap Entries (JRE System Library - sun-jdk.1.6.0.02)

      8. User Entries (jboss-embedded-all.jar,hibernate-all.jar,mysql-connector-java-5.0.8-bin.jar,thirdparty-all.jar,activation.jar,jaboss-el.jar,drools-compiler.jar,drools-core.jar, jboss-embedded-api.jar,jboss-seam.jar, jsf-api.jar, testng.jar,el-api.jar,(folder) bootstrap, (folder) test-build, richafaces-api.jar, richafaces-impl.jar,richafaces-ui.jar, easy-jclaim-1.0.jar, jbpm-jpdl.jar, core.jar,mvel14.jar,antlr.jar,antlr-runtime.jar)



      Test Example



      example


      package edu.baylor.icpc.test;
      
      import org.jboss.seam.mock.SeamTest;
      import org.testng.annotations.Test;
      
      public class SimpleTest extends SeamTest {
      
          @Test
          public void testLoginComponent() throws Exception {
              System.out.println("WORKING!!!");
      
              new ComponentTest() {
      
                  protected void testComponents() throws Exception {
                      System.out.println("WORKING!!!");
                      assert getValue("#{identity.loggedIn}").equals(false);
                      setValue("#{identity.username}", "tomas@cerny.cz");
                      setValue("#{identity.password}", "ugly");
                      invokeMethod("#{identity.login}");
                      assert getValue("#{identity.loggedIn}").equals(true);
                      assert getValue("#{currentUserId}").equals(1L);
      
                      assert getValue("#{currentUser.personInfo.lastName}").equals(
                              "Cerny");
                      /*
                       * // assert getValue("#{user.username}").equals("gavin"); //
                       * assert getValue("#{user.password}").equals("king");
                       */
      
                      invokeMethod("#{identity.logout}");
                      assert getValue("#{identity.loggedIn}").equals(false);
                      setValue("#{identity.username}", "gavin");
                      setValue("#{identity.password}", "king");
                      invokeMethod("#{identity.login}");
                      assert getValue("#{identity.loggedIn}").equals(false);
                      System.out.println("DONE!!!");
                  }
      
              }.run();
          }
      }



      simple-testng.xml


      <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
      <suite name="oskar">
        <test verbose="2" name="edu.baylor.icpc.test.SimpleTest" annotations="JDK">
          <classes>
            <class name="edu.baylor.icpc.test.SimpleTest"/>
          </classes>
        </test>
      </suite>
      



      Proof it is here ;D



      [Parser] Running:
        /home/cerny/workspace/Oskar/simple-testng.xml
      
      INFO  [org.jbpm.persistence.db.StaleObjectLogConfigurer] stale object exceptions will be hidden from logging
      WORKING!!!
      WORKING!!!
      INFO  [edu.baylor.icpc.service.ServiceLocator] ServiceLocator has been initialized
      INFO  [edu.baylor.icpc.service.ServiceLocator] ServiceLocator has been initialized
      ServiceExceptionTranslatorInterceptor Intercepted: logIn
      From EntityManager: 4635551
      INFO  [edu.baylor.icpc.session.auth.Authenticator] authenticating
      ServiceExceptionTranslatorInterceptor Intercepted: logIn
      From EntityManager: 4635551
      Caught an AuthorizationException
      ServiceExceptionTranslatorInterceptor Intercepted: logIn
      From EntityManager: 4635551
      Caught an AuthorizationException
      DONE!!!
      PASSED: testLoginComponent
      
      ===============================================
          edu.baylor.icpc.test.SimpleTest
          Tests run: 1, Failures: 0, Skips: 0
      ===============================================
      
      
      ===============================================
      oskar
      Total tests run: 1, Failures: 0, Skips: 0
      ===============================================
      
      

        • 1. Re: SeamTest - Linux - GUIDE!!!!
          enda

          By the way why we have to use Java 6 compilation with Java 5 compatibility is because JVM for Java 5 has a bug in it which will not compile our project:


          Buildfile: build.xml
          
          compiletest:
              [javac] Compiling 309 source files to /home/cerny/workspace/Oskar/test-build
              [javac] An exception has occurred in the compiler (1.5.0_12). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
              [javac] java.lang.AssertionError: (Integer)sortCount.value
              [javac]     at com.sun.tools.javac.comp.Lower.abstractLval(Lower.java:1853)
              [javac]     at com.sun.tools.javac.comp.Lower.lowerBoxedPostop(Lower.java:2659)
              [javac]     at com.sun.tools.javac.comp.Lower.visitUnary(Lower.java:2696)
              [javac]     at com.sun.tools.javac.tree.Tree$Unary.accept(Tree.java:910)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1881)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
              [javac]     at com.sun.tools.javac.comp.Lower.visitBinary(Lower.java:2744)
              [javac]     at com.sun.tools.javac.tree.Tree$Binary.accept(Tree.java:926)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1881)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
              [javac]     at com.sun.tools.javac.comp.Lower.visitReturn(Lower.java:2954)
              [javac]     at com.sun.tools.javac.tree.Tree$Return.accept(Tree.java:768)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1881)
              [javac]     at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:54)
              [javac]     at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:145)
              [javac]     at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:2927)
              [javac]     at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:535)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1881)
              [javac]     at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:129)
              [javac]     at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2267)
              [javac]     at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2186)
              [javac]     at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:478)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1881)
              [javac]     at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:1989)
              [javac]     at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:434)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1881)
              [javac]     at com.sun.tools.javac.comp.Lower.translate(Lower.java:1901)
              [javac]     at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3064)
              [javac]     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:487)
              [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:592)
              [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:544)
              [javac]     at com.sun.tools.javac.Main.compile(Main.java:67)
              [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              [javac]     at java.lang.reflect.Method.invoke(Method.java:585)
              [javac]     at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
              [javac]     at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:997)
              [javac]     at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:820)
              [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
              [javac]     at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
              [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              [javac]     at java.lang.reflect.Method.invoke(Method.java:585)
              [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
              [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
              [javac]     at org.apache.tools.ant.Target.execute(Target.java:357)
              [javac]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
              [javac]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
              [javac]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
              [javac]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
              [javac]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
              [javac]     at org.apache.tools.ant.Main.runBuild(Main.java:698)
              [javac]     at org.apache.tools.ant.Main.startAnt(Main.java:199)
              [javac]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
              [javac]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
          
          BUILD FAILED
          /home/cerny/workspace/Oskar/build.xml:324: Compile failed; see the compiler error output for details.
          
          Total time: 3 seconds




          ;D welcome to java