openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] OpenJPA > Testing
Date Fri, 07 May 2010 18:49:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/5/_/styles/combined.css?spaceKey=openjpa&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/display/openjpa/Testing">Testing</a></h2>
    <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~michael.d.dick@gmail.com">Michael
Dick</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Add -DfailIfNoTests=false and note how you can set it in settings.xml <br />
    </div>
        <br/>
                         <h4>Changes (6)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Once you have downloaded and built
OpenJPA (see [Building]), you can run individual tests using the &quot;test&quot;
goal to maven. For example: <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >{code}mvn test <span class="diff-added-words"style="background-color:
#dfd;">-DfailIfNoTests=false</span> -Dtest=TestPersistence{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{note}
By default Maven will fail if there are no testcases found in any module you build. The examples
solve this by specifying -DfailIfNoTests=false but you can also change your personal default
by adding the following to $\{user.home\}/.m2/settings.xml :  <br>{code:xml} <br>
       &lt;profile&gt; <br>            &lt;id&gt;enable-no-tests&lt;/id&gt;
<br>            &lt;activation&gt; <br>                &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
<br>            &lt;/activation&gt; <br>            &lt;properties&gt;
<br>                &lt;failIfNoTests&gt;false&lt;/failIfNoTests&gt;
<br>            &lt;/properties&gt; <br>        &lt;/profile&gt;
<br>{code} <br>{note}  <br> <br></td></tr>
            <tr><td class="diff-unchanged" >To get more debugging information
(e.g., to see the SQL that is being executed against the database), you can enable trace-level
logging from the command line using the &quot;openjpa.Log&quot; system property. For
example: <br> <br>{code} <br></td></tr>
            <tr><td class="diff-changed-lines" >$ mvn test <span class="diff-added-words"style="background-color:
#dfd;">-DfailIfNoTests=false</span> -Dtest=TestPersistence -Dopenjpa.Log=DefaultLevel=TRACE
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>[INFO] Scanning for projects...
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >By default, OpenJPA uses the [Derby|http://db.apache.org/derby/]
database for testing. The {{openjpa-persistence-jdbc/pom.xml}} POM declares various pre-defined
databases against which tests can be executed. For example, to test against the stand-alone
[HSQLDB|http://hsqldb.org/] database, you can run with the &quot;test-hsqldb&quot;
profile: <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >{code}mvn test <span class="diff-added-words"style="background-color:
#dfd;">-DfailIfNoTests=false</span> -Dtest=TestPersistence -Ptest-hsqldb{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>For databases that are
not in the pre-defined list, you can manually specify connection parameters to use for testing
under the &quot;test-custom&quot; profile. You will need to manually provide the driver
class and specify all of the connection parameters. For example, to test against Oracle, you
might run: <br> <br>{code} <br></td></tr>
            <tr><td class="diff-changed-lines" >mvn test <span class="diff-added-words"style="background-color:
#dfd;">-DfailIfNoTests=false</span> -Dtest=TestPersistence -Ptest-custom \ <br></td></tr>
            <tr><td class="diff-unchanged" >  -Dopenjpa.custom.driverjar=$(pwd)/drivers/jdbc-oracle-10_2_0_1_0.jar
\ <br>  -Dopenjpa.custom.driverclass=oracle.jdbc.driver.OracleDriver \ <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code} <br></td></tr>
            <tr><td class="diff-changed-lines" >mvn test <span class="diff-added-words"style="background-color:
#dfd;">-DfailIfNoTests=false</span> -Dtest=TestPersistence -Ptest-custom,test-oracle
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        

<h1><a name="Testing-RunningandWritingWritingTestCasesForOpenJPATestswithOpenJPA"></a>Running
and <a href="/confluence/display/openjpa/Writing+Test+Cases+For+OpenJPA" title="Writing
Test Cases For OpenJPA">Writing</a> Tests with OpenJPA</h1>

<p>OpenJPA's unit tests are written using JUnit. For a template for a simple test case,
see the code for <a href="http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java?view=markup"
class="external-link" rel="nofollow">TestPersistence.java</a>.</p>

<p>If you want to contribute your own test case then follow the <a href="/confluence/display/openjpa/Writing+Test+Cases+For+OpenJPA"
title="Writing Test Cases For OpenJPA">guidelines</a>.</p>

<p>Once you have downloaded and built OpenJPA (see <a href="/confluence/display/openjpa/Building"
title="Building">Building</a>), you can run individual tests using the "test" goal
to maven. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">mvn test -DfailIfNoTests=<span class="code-keyword">false</span>
-Dtest=TestPersistence</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>By default Maven will fail if
there are no testcases found in any module you build. The examples solve this by specifying
-DfailIfNoTests=false but you can also change your personal default by adding the following
to ${user.home}/.m2/settings.xml : 
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;profile&gt;</span>
            <span class="code-tag">&lt;id&gt;</span>enable-no-tests<span
class="code-tag">&lt;/id&gt;</span>
            <span class="code-tag">&lt;activation&gt;</span>
                <span class="code-tag">&lt;activeByDefault&gt;</span>true<span
class="code-tag">&lt;/activeByDefault&gt;</span>
            <span class="code-tag">&lt;/activation&gt;</span>
            <span class="code-tag">&lt;properties&gt;</span>
                <span class="code-tag">&lt;failIfNoTests&gt;</span>false<span
class="code-tag">&lt;/failIfNoTests&gt;</span>
            <span class="code-tag">&lt;/properties&gt;</span>
        <span class="code-tag">&lt;/profile&gt;</span>
</pre>
</div></div></td></tr></table></div> 

<p>To get more debugging information (e.g., to see the SQL that is being executed against
the database), you can enable trace-level logging from the command line using the "openjpa.Log"
system property. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$ mvn test -DfailIfNoTests=<span class="code-keyword">false</span> -Dtest=TestPersistence
-Dopenjpa.Log=DefaultLevel=TRACE

[INFO] Scanning <span class="code-keyword">for</span> projects...
[INFO] Reactor build order: 
...
690  test  TRACE  [main] openjpa.jdbc.SQL - &lt;t 4261185, conn 3061987&gt; executing
prepstmnt 12659709 
   INSERT INTO AllFieldTypes (id, arrayOfStrings, booleanField, byteField, charField, dateField,

   doubleField, floatField, intField, longField, shortField, stringField) 
   VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(<span class="code-object">long</span>)
601, (<span class="code-keyword">null</span>) <span class="code-keyword">null</span>,
(<span class="code-object">int</span>) 0, (<span class="code-object">byte</span>)
0, 
   (<span class="code-object">int</span>) 0, (<span class="code-keyword">null</span>)
<span class="code-keyword">null</span>, (<span class="code-object">double</span>)
0.0, (<span class="code-object">float</span>) 0.0, (<span class="code-object">int</span>)
0, (<span class="code-object">long</span>) 0, (<span class="code-object">short</span>)
0, (<span class="code-keyword">null</span>) <span class="code-keyword">null</span>]
701  test  TRACE  [main] openjpa.jdbc.SQL - &lt;t 4261185, conn 3061987&gt; [11 ms]
spent
701  test  TRACE  [main] openjpa.jdbc.JDBC - &lt;t 4261185, conn 3061987&gt; [0 ms]
commit
702  test  TRACE  [main] openjpa.jdbc.JDBC - &lt;t 4261185, conn 0&gt; [0 ms] close
...
$
</pre>
</div></div>

<h2><a name="Testing-SettingadditionalLogparameters"></a>Setting additional
Log parameters</h2>

<p>There are several parameters that are used by OpenJPA Log. Here are some that might
be of value when debugging test cases. Note that the logger names are case sensitive while
the log levels are not.</p>

<ul>
	<li>DefaultLevel sets the level for all loggers that are not otherwise set</li>
	<li>file sets the file name for logging output</li>
	<li>Enhance logs messages from the enhancer</li>
	<li>Metadata logs messages from the metadata processor</li>
	<li>Tool logs messages from the schema synchronization tool</li>
	<li>SQL logs messages from the SQL generator</li>
	<li>JDBC logs messages related to JDBC</li>
	<li>Schema logs messages related to schema</li>
	<li>Runtime logs messages related to runtime</li>
	<li>Query logs messages related to queried</li>
	<li>DataCache logs messages related to caching</li>
</ul>


<p>Log levels specify the minimum log message that is output. All log messages with
a level higher than the log level set for a logger are output. So if INFO is specified, log
messages of level INFO, WARN, ERROR, and SEVERE are output.</p>

<ul>
	<li>TRACE</li>
	<li>INFO</li>
	<li>WARN</li>
	<li>ERROR</li>
	<li>FATAL</li>
</ul>


<p>For example, to avoid enhancement warnings, get detailed SQL information, and write
the log data to a file:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">mvn test -Dtest=TestPersistence -Dopenjpa.Log=Enhance=ERROR,SQL=TRACE,file=openjpa.log</pre>
</div></div>

<h1><a name="Testing-Testingagainstalternatedatabases"></a>Testing against
alternate databases</h1>

<p>By default, OpenJPA uses the <a href="http://db.apache.org/derby/" class="external-link"
rel="nofollow">Derby</a> database for testing. The <tt>openjpa-persistence-jdbc/pom.xml</tt>
POM declares various pre-defined databases against which tests can be executed. For example,
to test against the stand-alone <a href="http://hsqldb.org/" class="external-link" rel="nofollow">HSQLDB</a>
database, you can run with the "test-hsqldb" profile:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">mvn test -DfailIfNoTests=<span class="code-keyword">false</span>
-Dtest=TestPersistence -Ptest-hsqldb</pre>
</div></div>

<p>For databases that are not in the pre-defined list, you can manually specify connection
parameters to use for testing under the "test-custom" profile. You will need to manually provide
the driver class and specify all of the connection parameters. For example, to test against
Oracle, you might run:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn test -DfailIfNoTests=<span class="code-keyword">false</span> -Dtest=TestPersistence
-Ptest-custom \
  -Dopenjpa.custom.driverjar=$(pwd)/drivers/jdbc-oracle-10_2_0_1_0.jar \
  -Dopenjpa.custom.driverclass=oracle.jdbc.driver.OracleDriver \
  -Dopenjpa.custom.url=jdbc:oracle:thin:@HOST:PORT:DBNAME \
  -Dopenjpa.custom.username=USERNAME \
  -Dopenjpa.custom.password=PASSWORD
</pre>
</div></div>

<p>If you frequently need to test against another database, you can permanently declare
the database connection parameters in the <tt>~/.m2/settings.xml</tt> file under
a custom profile. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;settings&gt;
    &lt;profiles&gt;
        &lt;profile&gt;
            &lt;id&gt;test-oracle&lt;/id&gt;
            &lt;properties&gt;
                &lt;test-custom&gt;<span class="code-keyword">true</span>&lt;/test-custom&gt;
                &lt;openjpa.custom.driverjar&gt;${user.home}/.m2/privaterepos/jdbc-oracle-10_2_0_1_0.jar&lt;/openjpa.custom.driverjar&gt;
                &lt;openjpa.custom.driverclass&gt;oracle.jdbc.driver.OracleDriver&lt;/openjpa.custom.driverclass&gt;
                &lt;openjpa.custom.url&gt;jdbc:oracle:thin:@HOST:PORT:DBNAME&lt;/openjpa.custom.url&gt;
                &lt;openjpa.custom.username&gt;USERNAME&lt;/openjpa.custom.username&gt;
                &lt;openjpa.custom.password&gt;PASSWORD&lt;/openjpa.custom.password&gt;
            &lt;/properties&gt;
        &lt;/profile&gt;
    &lt;/profiles&gt;
&lt;/settings&gt;
</pre>
</div></div>

<p>This profile can then be executed by running:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn test -DfailIfNoTests=<span class="code-keyword">false</span> -Dtest=TestPersistence
-Ptest-custom,test-oracle
</pre>
</div></div>




    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="http://cwiki.apache.org/confluence/display/openjpa/Testing">View Online</a>
        |
        <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=34610&revisedVersion=13&originalVersion=12">View
Changes</a>
                |
        <a href="http://cwiki.apache.org/confluence/display/openjpa/Testing?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message