SeamTest - Linux - GUIDE!!!!
enda Jul 16, 2008 10:13 PMLinux 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:
- 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
- Java 5 only but that is not it!
- go to your project
- select java 6
- eselect java-vm set system 3
- type
- ant clean
- ant compiletest
- select java 5
- eselect java-vm set system 2
- ant test
- after you are done ant clean
Run you test from Eclipse
so start eclipse
- choose project compilation in Java 5 compatibility
- Run
- Open Run Dialog
- TestNG
- Project : test
- Suite : /home/cerny/workspace/Oskar/simple-testng.xml
- goto classpath
- Bootstrap Entries (JRE System Library - sun-jdk.1.6.0.02)
- 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 ===============================================