This document describes how to develop and run JUnit tests for the project.
It is not a tutorial on writing JUnit tests in general.
createTestUser to create the TestUser's key to client
keystore and self-register the Test User, or just loadTestUser if the previous
target fails because the key already exists:build createTestUserjaxr-ebxml.security.test.alias=testuser
jaxr-ebxml.security.test.keypass=testuserpasswd
jaxr-ebxml.security.storepass=ebxmlrrbuild stop.tomcat test.unit.deploy start.tomcathttp://localhost:8080/ then
you'll have to update the URL in the accessURI attribute
of every <rim:ServiceBinding> element in every
SubmitObjectsRequest_WebServices.xml file under
misc/samples/cms to reflect the proper endpoint address.Many of the regression test assume that you have certain demo data in your database. All such assumed data is loaded when you load the demoDB databases.
The following steps describe how to rebuild demodb:
build.sh cleandbbuild.sh createDemoDBNOTE: Databases running in embedded mode, like Derby (default) and HSQLDB are not very practical for unit tests because server tests and client tests in local mode have to be run with application server down, while other client tests require the server to be up.
We recommend that you either use one of the external supported databases (PostgreSQL, for instance) or use HSQLDB in server mode. In case you opt for HSQLDB, switch the relevant properties in build.properties (see configuring database connection properties) and redeploy the aplication, then use the following commands to manage the database.
build.sh hsqldb.start: Starts the database server.build.sh hsqldb.stop: Stops the database server.build.sh hsqldb.manager: Starts a HSQLDB Manager GUI,
useful for testing SQL queries directly to our database.To run all unit tests automatically, use a database not in embedded mode and do the following steps:
cd <omar>build test.unit<omar>/build/reports/unit/html/index.htmlAlternatively, you can use one of the following commands:
build test.unit.local: Run all unit tests, on local mode (requires Tomcat down for embedded databases).build test.unit.client: Run all client tests, on remote mode (requires Tomcat up).build test.unit.server: Run all server tests (requires Tomcat down for embedded databases).NOTE: after the last test has finished our script will render some HTML pages to report the results. That operation might be time and memory consuming. Use the ANT_OPTS env variable to increase JVM Max Heap Size (memory):
export ANT_OPTS="-Xmx256M $ANT_OPTS"set ANT_OPTS="-Xmx256M %ANT_OPTS%"Also, you do not have to wait for the report to finish generating to start looking at the results in XML format, as described in the following sections (see handleing test failures).
To run a single test class do the following steps:
cd <omar>./build.sh test.single
-Dtest='org.freebxml.omar.client.xml.registry.infomodel.InternationStringImplTest'After the last test has finished running and displays its results, the script will generate an HTML report of the test. This rendering might take long and you do not have to wait for the report to finish generating to start looking at errors and failures as decsribed in the next section.
Ideally we should have no tests failures or errors: 100% sucess!! Currently some tests are still failing and we need to further investigate why, being the success rate now close to 98% sucess.
If your sucess rate is much lower than that, note that many tests will fail if the test user is not properly created/configured. This is often the case after having run a createDemoDB. In such cases, check from Preconditions how to do the test user registration.
Some of our tests such as ApelonJAXRTest fail due to some history from past runs of the test. The best way to deal with these is to try rerunning the test. If it still fails then try running the test after cleandb and createDemoDB and new user registration.
When a test fails you need to look at the file produced by the test:
build/reports/unit/TEST-*.xml
for errors and failures using string search for "<error>" and
"<failure>". You can also check the corresponding HTML if it has been rendered.
You then look back at the test code to see what may be broke and why.
This section describes how to write JUnit tests in the context of the freebXML Registry project. It does is not a general purpose tutorial on what JUnit is and hoe to write JUnit tests in general.
A JUnit test should be created or updated:
Our source code is organized by client, server and common code under packages org.freebxml.omar.client, org.freebxml.omar.server and org.freebxml.omar.common. Our JUnit tests are organized similarly.
Server side tests do not use the JAXR API while client side tests do.
One SHOULD write server side tests when the code being developed / tested is server side functionality. The reason is that with server side tests you do not have to deploy the server code each time you make a code change.
One MUST write client side tests when the code being developed / tested is client side functionality such as JAXR provider, Registry Browser Java or Web UI.
The client side works either in local mode (Registry Browser Web UI) or remotely (regular JAXR application, Registry Browser Java UI). By default the client tests will run in remote mode, but you should also test the functionality in local mode. For that, you have these options:
build test.unit.local: Run all unit tests, on local mode (requires Tomcat down for embedded databases).build test.unit.local: Run all client tests, on local mode (requires Tomcat down for embedded databases).build test.single.local -Dtest=<testClassName>: Run a single test, on local mode (requires Tomcat down for embedded databases).build debug.single.local -Dtest=<testClassName>: Debug a single test, on local mode (requires Tomcat down for embedded databases).Typically, a JUnit test Class is created to test a specific class, referred to as Class Under Test (CUT) in the project code under the <omar>/src directory. The JUnit class should have the exact same package name as the class it is testing. However, its classname should have the suffix "Test" added to it.
For example, the src class org.freebxml.omar.server.query.QueryManagerImpl is in the file <omar>/src/java/org/freebxml/omar/server/query/QueryManagerImpl.java while its JUnit test class org.freebxml.omar.server.query.QueryManagerImplTest is in the file <omar>/test/org/freebxml/omar/server/query/QueryManagerImplTest.java
Typically you add a test method for each public method that is beyond the complexity of simple accessor methods.
The name of the test method must start with the prefix "test". If it is testing a specific method in the CUT then it should use the prefix "test" followed by the name of the Method Under Test (MUT) where the MUT has been converted to upper-camel-case. The overall method name is lower-camel-case.
For example, the class org.freebxml.omar.server.query.QueryManagerImpl has a method submitAdhocQuery then the corresponding test method in org.freebxml.omar.server.query.QueryManagerImplTest is testSubmitAdhocQuery.
JUnit tests for the org.freebxml.omar.server package and the org.freebxml.omar.client differ slightly. Please use the following test programs as templates for your new test programs:
When writing a new test it is suggested that you clone an existing test program from above depending upon whether your program is client, server or common test.
If you use an IDE then please make sure that generated program follows the appropriate template even if it requires some manual modification.
If a test shows errors and failures (non-zero count) then using folowing steps to debug the problems: