blob: 78300537e276fc8242845030212677ad63899243 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<!-- $PAGETITLE -->
<TITLE>OpenEJB - Creating itests</TITLE>
<LINK href="http://openejb.apache.org/all.css" rel="stylesheet" type="text/css">
<!--[if IE]><link rel="stylesheet" type="text/css" media="screen, projection" href="openejb.apache.org/ie.css"><![endif]-->
<LINK rel="SHORTCUT ICON" href="http://openejb.apache.org/images/favicon.ico">
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
<SCRIPT language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></SCRIPT>
<SCRIPT language="javascript" src="http://openejb.apache.org/tweet/jquery.tweet.js" type="text/javascript"></SCRIPT>
<SCRIPT type="text/javascript">
$(document).ready(function(){
$(".tweet").tweet({
avatar_size: 32,
count: 4,
fetch:25,
username: "openejb",
list: "contributors",
template:"{avatar}{text}",
filter: function(t){ return /openejb/i.test(t["tweet_raw_text"]); },
loading_text: "loading list..."
});
});
</SCRIPT>
</HEAD>
<BODY>
<!-- Delay the loading of the external javascript file needed for labels (as it takes too long to load and visibly holds loading of the page body) -->
<!-- To do this without javascript errors over undefined functions, we need to declare stubs here (that are overrided later by the proper implementations) -->
<SCRIPT language="JavaScript" type="text/javascript">
function doAddLabel(hideTextfieldAfterAddParam)
{
// stub
}
function onAddLabel()
{
// stub
}
function showLabelsInput()
{
// stub
}
</SCRIPT>
<A name="top"></A>
<TABLE class="frameTable" cellpadding="0" cellspacing="0" border="0">
<TR class="Row1">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row2">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3" id="breadcrumbs">
<!-- $TOP_NAV_BAR -->
<A href="index.html" title="Index">Home</A> | <A href="news.html" title="News">News</A> | <A href="faq.html" title="FAQ">FAQ</A> | <A href="download.html" title="Download">Download</A> | <A href="mailing-lists.html" title="Mailing Lists">Lists</A> | <A href="http://issues.apache.org/jira/browse/OPENEJB" class="external-link" rel="nofollow">Issues</A>
</TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
<TR class="Row3">
<TD class="Col1"><IMG alt="" class="Row3Img" id="thinLine" src="http://openejb.apache.org/images/line_sm.gif"></TD>
<TD class="Col2"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row4">
<TD class="Col1">
<SPAN id="Navigation">
<H3><A name="Navigation-Overview"></A>Overview</H3>
<UL class="alternate" type="square">
<LI><A href="index.html" title="Index">Home</A></LI>
<LI><A href="news.html" title="News">News</A></LI>
<LI><A href="faq.html" title="FAQ">FAQ</A></LI>
<LI><A href="download.html" title="Download">Download</A></LI>
<LI><A href="../OPENEJBx30/index.html" title="Index">Documentation</A></LI>
<LI><A href="examples.html" title="Examples">Examples</A></LI>
<LI><A href="http://cwiki.apache.org/confluence/display/OPENEJB/Lightening%20Demos" class="external-link" rel="nofollow">Lightning Demos</A></LI>
<LI><A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A></LI>
<LI><A href="source-code.html" title="Source Code">Source Code</A></LI>
<LI><A href="http://blogs.apache.org/openejb" class="external-link" rel="nofollow">Project Blog</A></LI>
</UL>
<H3><A name="Navigation-Servers"></A>Servers</H3>
<UL class="alternate" type="square">
<LI><A href="local-server.html" title="Local Server">Local</A></LI>
<LI><A href="remote-server.html" title="Remote Server">Remote</A></LI>
</UL>
<H3><A name="Navigation-Integrations"></A>Integrations</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJBx30/tomcat.html" title="Tomcat">Tomcat</A></LI>
<LI><A href="geronimo.html" title="Geronimo">Geronimo</A></LI>
<LI><A href="webobjects.html" title="WebObjects">WebObjects</A></LI>
</UL>
<H3><A name="Navigation-Community"></A>Community</H3>
<UL class="alternate" type="square">
<LI><A href="team.html" title="Team">Team</A></LI>
<LI><A href="articles.html" title="Articles">Articles</A></LI>
<LI><A href="http://webchat.freenode.net/?channels=openejb" class="external-link" rel="nofollow">IRC</A></LI>
</UL>
<H3><A name="Navigation-RelatedProjects"></A>Related Projects</H3>
<UL class="alternate" type="square">
<LI><A href="http://activemq.apache.org/" class="external-link" rel="nofollow">ActiveMQ</A></LI>
<LI><A href="http://openjpa.apache.org/" class="external-link" rel="nofollow">OpenJPA</A></LI>
<LI><A href="http://cxf.apache.org/" class="external-link" rel="nofollow">CXF</A></LI>
</UL>
<H3><A name="Navigation-Index"></A>Index</H3>
<UL class="alternate" type="square">
<LI><A href="space-index.html" title="Space Index">Site Index</A></LI>
<LI><A href="../OPENEJBx30/space-index.html" title="Space Index">Doc Index</A></LI>
</UL>
<H3>
<A name="Navigation-Feeds"></A>
Feeds
</H3>
<UL class="feeds">
<LI>
<A href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">Site</A>
</LI>
<LI><A href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">News</A>
</LI>
</UL>
</SPAN>
</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<TABLE id="PageHeader" border="0" width="100%">
<TR>
<TD>
<A href="http://openejb.org/">
<IMG hspace="0" src="http://openejb.apache.org/images/logo_openejb.gif" vspace="0">
</A>
</TD>
<TD align="right">
<A href="http://www.apache.org/">
<IMG src="http://www.apache.org/images/asf-logo.gif" width="258" height="66">
</A>
</TD>
</TR>
<TR>
<TD id="page_title">
<!-- $TITLE -->
Creating itests
</TD>
<TD align="right">
<BR><BR>
<!-- Google CSE Search Box Begins -->
<FORM id="searchbox_010475492895890475512:_t4iqjrgx90" action="http://www.google.com/cse">
<INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
<INPUT type="hidden" name="cof" value="FORID:0">
<INPUT name="q" type="text" size="25">
<INPUT type="submit" name="sa" value="Search">
</FORM>
<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>
<!-- Google CSE Search Box Ends -->
</TD>
</TR>
</TABLE>
<P>
<!-- $BODY -->
<DIV id="PageContent">
<H1><A name="Creatingitests-OpenEJBitests"></A>OpenEJB itests</H1>
<P>The OpenEJB itests module is a framework to create EJB test cases that are designed according to the JUnit rules, i.e. they all have setUp, tests and tearDown methods. Since it's JUnit-based, you can do whatever you could do in JUnit.</P>
<P>This page describes the steps to create EJB test cases.</P>
<H2><A name="Creatingitests-Howitestswork"></A>How itests work</H2>
<P>The itests module lives in OpenEJB's repository in the <EM>modules\itests</EM> directory. Setting up the test environment to execute the itests is based on (<A href="http://svn.apache.org/repos/asf/maven/maven-1/plugins-sandbox/trunk/itest/" class="external-link" rel="nofollow">maven-itest-plugin-1.0 plugin</A>). </P>
<P>Take a look at maven.xml in modules\itests directory. There you'll see that the default goal is <EM>ejb:install</EM>, which in turn executes <EM>itest</EM>. When the EJBs (todo: describe it a bit more) are done, the <EM>itest:setup</EM> goal is executed, which starts the real game. First, <EM>org/openejb/Security</EM> configuration is started. Once it's done, <EM>openejb-itests-xxx.jar</EM> is deployed, which is <EM>org/openejb/Itests</EM> configuration to be started, afterwards. When the configurations are deployed and started, the maven-itest-plugin executes junit (see <A href="http://ant.apache.org/manual/OptionalTasks/junit.html" class="external-link" rel="nofollow">Ant JUnit task documentation</A> and project.properties of the itests module). The project.properties file configures which itests are run and some other stuff.</P>
<P>The first itest test case is <EM>org.openejb.test.entity.cmp.CmpTestSuite</EM>. Consult this for more information. Then the others defined in <EM>maven.itest.includes</EM> property are executed.</P>
<P>The order in which the itests are executed is important, so the first order is set up via the maven.itest.includes property, then the test suites add their tests in some order, and finally the method names in the test classes put yet another order. So, be careful what name your test method name will become. It may influence the order.</P>
<P>Some EJBs access database resources. It's even more important for CMPs. The itests module uses the database as defined in the <EM>openejb.test.database</EM> property. It's currently defined in the <EM>project.properties</EM> file of the module. You can change its value to whatever you wish using the Maven property setting approaches (-D on the command line, project.properties, build.properties in your home directory or the project you work in).</P>
<P>So, the last important information is how the junit tests access the server resources - EJBs. It's done via executing session beans that in turn get at the test EJBs, mostly CMPs. It's also possible that the CMP itests will be accessed directly without having to pass on the call through a session bean.</P>
<P>If itests are part of a larger project structure you can disable executing it using the <EM>maven.itest.skip</EM> property. Set it to <EM>true</EM> and Maven won't run the itests.</P>
<H2><A name="Creatingitests-SimpleCMP2.1itest"></A>Simple CMP 2.1 itest</H2>
<H3><A name="Creatingitests-Databasesetup"></A>Database setup</H3>
<P>The itests default database is Derby. The class - <EM>org.openejb.test.DerbyTestDatabase</EM> - is instantiated upon executing <EM>org.openejb.testTestManager.getDatabase()</EM> in each test case's <EM>setUp()</EM> method. Remember, you can define any other database using the <EM>openejb.test.database</EM> property or do initialization of your own database choice in the setUp() method.</P>
<P>The current implementation of database initialization is based on two DerbyTestDatabse methods: <EM>createCMP2Model()</EM> and <EM>dropCMP2Model()</EM> that create and drop database structure, accordingly.</P>
<H3><A name="Creatingitests-CMP2.1deployment"></A>CMP 2.1 deployment</H3>
<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B>Information</B><BR>Unless specified, all directories are relative to <EM>modules/itests</EM> directory and commands are executed in it.</TD></TR></TABLE></DIV>
<P>A Maven project can produce one build artefact. It's very important to keep in mind whenever your tests are to be based on a EJB that's not built by default. The default EJBs are defined in <EM>modules/itests/src/ejb/META-INF/ejb-jar.xml</EM>. The corresponding deployment plan - the <EM>openejb-jar.xml</EM> file is in <EM>modules/itests/src/ejb/META-INF/openejb-jar.xml</EM>.</P>
<P>If you want to test your own EJB, you need to build it yourself, i.e. describe the build and deployment in <EM>modules/itests/maven.xml</EM> in the pregoal of <EM>itest:setup</EM>.</P>
<P>In the following example, Ant's jar builds openejb-cmp2-petstore.jar file, which in turn is distributed and started in Geronimo. The <EM>id</EM> attribute of <EM>deploy:start</EM> is as specified in the module's deployment plan. See <A href="http://wiki.apache.org/geronimo/Deployment" class="external-link" rel="nofollow">Geronimo Deployment</A> for more information about Geronimo deployment plans.</P>
<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent">
<PRE>&lt;ant:jar destfile=&quot;${basedir}/target/openejb-cmp2-petstore.jar&quot;&gt;
&lt;fileset dir=&quot;${basedir}/target/classes&quot;&gt;
&lt;include name=&quot;**/cmp2/petstore/*.class&quot;/&gt;
&lt;include name=&quot;**/TestFailureException.class&quot;/&gt;
&lt;/fileset&gt;
&lt;metainf dir=&quot;${basedir}/src/cmp2/petstore&quot; includes=&quot;*.xml&quot;/&gt;
&lt;/ant:jar&gt;
&lt;deploy:distribute
uri=&quot;deployer:geronimo:jmx:rmi://localhost/jndi/rmi:/JMXConnector&quot;
username=&quot;system&quot;
password=&quot;manager&quot;
module=&quot;${basedir}/target/openejb-cmp2-petstore.jar&quot;
/&gt;
&lt;deploy:start
uri=&quot;deployer:geronimo:jmx:rmi://localhost/jndi/rmi:/JMXConnector&quot;
username=&quot;system&quot;
password=&quot;manager&quot;
id=&quot;org/openejb/cmp2/petstore&quot;/&gt;
</PRE>
</DIV></DIV>
<H3><A name="Creatingitests-Execution"></A>Execution</H3>
<P>When EJB classes, deployment descriptor and plan, maven.xml are all set up, it's time to execute your tests. In order to run itests you will run Maven in <EM>modules/itests</EM> directory.</P>
<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent">
<PRE>~/openejb/modules/itests
$ maven
</PRE>
</DIV></DIV>
<P>It's also possible to override project properties and run only some test cases.</P>
<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent">
<PRE>~/openejb/modules/itests
$ maven -Dmaven.itest.includes=**/Cmp2TestSuite.java
</PRE>
</DIV></DIV>
<P>When a failure occurs, you should take a look at the result file of the failed test suite in <EM>target/itest-reports</EM>, e.g.</P>
<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent">
<PRE>~/openejb/modules/itests
$ maven -Dmaven.itest.includes=**/Cmp2TestSuite.java -o
...
[junit] Tests run: 113, Failures: 1, Errors: 0, Time elapsed: 22,132 sec
[junit] [ERROR] TEST org.openejb.test.entity.cmp2.Cmp2TestSuite FAILED
...
BUILD FAILED
File...... C:\Documents and Settings\root\.maven\cache\maven-itest-plugin-1.0\plugin.jelly
Element... fail
Line...... 166
Column.... 64
There were test failures.
Total time: 2 minutes 3 seconds
Finished at: Sun Jul 17 17:48:36 CEST 2005
$ more target/itest-reports/TEST-org.openejb.test.entity.cmp2.Cmp2TestSuite.txt
Testsuite: org.openejb.test.entity.cmp2.Cmp2TestSuite
Tests run: 113, Failures: 1, Errors: 0, Time elapsed: 22,132 sec
Testcase: PetstoreTests.create: FAILED
Received Exception class java.lang.NullPointerException : null
junit.framework.AssertionFailedError: Received Exception class java.lang.NullPointerException : null
at org.openejb.test.entity.cmp2.PetstoreTests.test01_create(PetstoreTests.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.openejb.test.NumberedTestCase.runTestMethod(NumberedTestCase.java:195)
at org.openejb.test.NumberedTestCase$3.protect(NumberedTestCase.java:169)
at org.openejb.test.NumberedTestCase.run(NumberedTestCase.java:172)
at org.openejb.test.NumberedTestCase.run(NumberedTestCase.java:141)
at org.openejb.test.TestSuite.run(TestSuite.java:71)
...
</PRE>
</DIV></DIV>
<P>Complete execution log is in <EM>target/openejb/var/log/openejb.log</EM> of the itests module.</P>
<H4><A name="Creatingitests-RunningtheTestsinEclipse."></A>Running the Tests in Eclipse.</H4>
<P>The steps for running the iTests inside of Eclipse are given below. They are</P>
<P>1) For Local Interface Tests, the class to be run is <EM>org.apache.openejb.iTest</EM>.<BR>
2) For Remote Interface Tests, the class to be run is <EM>org.apache.openejb.RemoteiTest</EM>.</P>
<P>In both the cases you need to give <EM>'-Dopenejb.home=target/test-classes/'</EM> as a vm argument <BR>
for the tests to run. </P>
</DIV>
</P>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">
</TD>
</TR>
<TR class="Row5">
<TD class="Col1">&nbsp;</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<BR>
<BR>
<IMG width="100%" height="1" src="http://openejb.apache.org/images/line_light.gif">
<TABLE width="100%">
<TR>
<TD>
<SPAN class="bodyGrey">
<SMALL>
<NOTICE><!-- $FOOTER -->
Apache OpenEJB is an project of The Apache Software Foundation (ASF)
</NOTICE>
<BR>
Site Powered by
<A href="http://atlassian.com/">Atlassian</A>
<A href="http://atlassian.com/confluence/">Confluence</A>
.
</SMALL>
</SPAN>
</TD>
<TD align="right">
<A style="color:#999;font-size:small;font-weight:normal;" href="https://cwiki.apache.org/confluence/pages/editpage.action?spaceKey=OPENEJB&title=Creating%20itests">[ edit ]</A>
</TD>
</TR>
</TABLE>
<BR>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
</TABLE>
<!-- Needed for composition plugin -->
<!-- delay the loading of large javascript files to the end so that they don't interfere with the loading of page content -->
<SPAN style="display: none">
<SCRIPT type="text/javascript" language="JavaScript" src="http://cwiki.apache.org/confluence/labels-javascript"></SCRIPT>
<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript">
_uacct = "UA-2717626-1";
urchinTracker();
</SCRIPT>
</SPAN>
</BODY>
</HTML>