Version 2 (modified by 16 years ago) ( diff ) | ,
---|
ebXML Persistence Test Suite
This page describes the automated tests for the Persistence Layer to the ebXML Object Model.
Persistence Layer Test Suite
The unit tests for the persistence layer create the database through Hibernate and then insert data into it, again using Hibernate. The resulting state of the database is verified by executing HQL queries. Where applicable, polymorphic HQL queries are tested as well.
The tests use the well-known unit testing framework Junit. Although developed against a local MySQL database, the tests are currently being remodeled such that they use an embedded McKoi database server; this removes the dependency of the test suite on a pre-installed external database server. Some peculiarities of McKoi are being accommodated, for instance it chokes if you try to create a table called "user".
Example
An example of a test case verifying that a RegistryObject is stored, both by querying on RegistryObject and polymorphically on its base class Identifiable, is this:
public void testPersistingRegistryObject(){ // create transient object RegistryObject transientRegistryObject = RegistryObjectFactory.createRegistryObject(); URN businessKey = transientRegistryObject.getId(); // make transient object persistent Transaction tx = hibernateSession.beginTransaction(); hibernateSession.saveOrUpdate(transientRegistryObject); tx.commit(); // verify database state Query registryObjectQuery = hibernateSession.createQuery("from RegistryObject o where o.id = '" + businessKey + "'"); List<RegistryObject> registryObjectResult = registryObjectQuery.list(); RegistryObject persistentRegistryObject = registryObjectResult.get(0); assertEquals(transientRegistryObject, persistentRegistryObject); // verify database state using a polymorphic query Query identifiableQuery = hibernateSession.createQuery("from Identifiable o where o.id = '" + businessKey + "'"); List<Identifiable> identifiableResult = identifiableQuery.list(); Identifiable identifiable = identifiableResult.get(0); assertEquals(transientRegistryObject, identifiable); }