Changes between Version 2 and Version 3 of ebXMLPersistenceLayerTestSuite
- Timestamp:
- 08/09/08 08:48:57 (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ebXMLPersistenceLayerTestSuite
v2 v3 10 10 The unit tests for the persistence layer create the database through [http://hibernate.org Hibernate] and then insert data into it, again using Hibernate. The resulting state of the database is verified by executing [http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html HQL] queries. Where applicable, polymorphic HQL queries are tested as well. 11 11 12 The tests use the well-known unit testing framework [http://junit.org Junit]. Although developed against a local [http://www.mysql.com MySQL] database, the tests are currently being remodeled such that they use an embedded [http://www.mckoi.com 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". 12 The tests use the well-known unit testing framework [http://junit.org Junit]. Although developed against a local [http://www.mysql.com MySQL] database, the tests are currently being remodeled such that they use an embedded [http://www.mckoi.com 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". This last point is addressed by invoking an !ImprovedNamingStrategy on the Hibernate configuration which causes all table names to be automatically prefixed by "RIM_". 13 13 14 14 === Example === … … 43 43 44 44 }}} 45 46 This test unfortunately cannot run on a !McKoi database. It seems !McKoi does not support the SQL operator UNION, only UNION ALL. Hibernate however is under the hood issuing SQL queries containing UNION -- this is a result of the <union-subclass> mapping strategy we have chosen to model OO inheritance. This causes !McKoi to raise the descriptive error "ERROR: PENDING" and the test case fails. 47 48 So for !McKoi a test case could use an SQL query, rather than an HQL query. This means the test case is less interesting because we're back to writing SQL, we must explicitly apply our !ImprovedNamingStrategy in the SQL, and we cannot do polymorphic queries. The test case below is an example that can run in !McKoi. 49 50 {{{ 51 52 public void testPersistingRegistryObject(){ 53 54 // create transient object 55 Transaction tx = hibernateSession.beginTransaction(); 56 RegistryObject transientRegistryObject = RegistryObjectFactory.createRegistryObject(); 57 URN businessKey = transientRegistryObject.getId(); 58 // make transient object persistent 59 hibernateSession.saveOrUpdate(transientRegistryObject); 60 tx.commit(); 61 62 // verify database state 63 64 Query registryObjectQuery = hibernateSession.createSQLQuery("select ID from RIM_REGISTRY_OBJECT where ID='" + businessKey + "'"); 65 66 List<String> result = registryObjectQuery.list(); 67 URN persistentRegistryObjectId = new URN(result.get(0)); 68 assertEquals(persistentRegistryObjectId, businessKey); 69 } 70 71 }}} 72 73 The tests in the test suite are being remodeled such that by default they will run !McKoi-friendly test cases, which can be overruled by a setting that will run the HQL-based test cases. 74