Tuesday, June 13, 2006

First roundtrip test case running with Hyperjaxb3

Today I've managed to execute the very first roundtrip test case with Hyperjaxb3. It's a primitive example with well-known purchase order schema, but it's a good starting point anyway. See tests/po.

In order to execute the test, you'll need to check out my changes to the JAXB 2 Maven plugin. Check out the Lexi2 branch from jaxb2-sources/jaxb-maven2-plugin and mvn install it. I hope we'll have these changes in the main branch (and maybe in the repository) soon, so it's a temporary inconvenience.

Monday, June 12, 2006

Hyperjaxb3 - EJB3

Since I'm no EJB3 expert, I will really need assistance with EJB3 issues. I'll list my current EJB3 problems in this post. I'd be glad if experts comment.

EJB3 roundtrip test case


I need a roundtrip test case for EJB3. I've described what roundtrip test case does in one of the previous posts (unmarshall, save, load, compare).

EJB3 and accessors


I use custom accessors with Hibernate3. First of all, they help with collection fields: JAXB generates no setter, and my custom accessor uses property-based getter and field-based setter to avoid the need to generate a collection setter. Another reason is that custom accessors may take advantage of isSetXXX methods generated by JAXB, for instance to distinguish null and 0 for primitive numeric types. Is it possible to condigure property accessors in EJB3?

Collection of primitive types


How do I map a collection of primitive types (for instance strings) with EJB3? Something like List<String>?

I think it's all for now.

Hyperjaxb3 target platforms

Hyperjaxb2 only had a single target ORM platform and that was Hibernate/HBM file-based mappings. Hyperjaxb2 has literary generated HBM files for the classes generated by JAXB.

In Hyperjaxb3, we'll have multiple target platforms. Hibernate3/HBM is one of the, but I'm looking forward to have EJB3/Hibernate3 with annotations or even JDO if it's somehow relevant.

Each of the supported ORM platforms will have its own generating plugin. At the same time all the platforms will have the same analyzis block (detecting the cardinality and the type of the field). I think the strategy approach used in Hyperjaxb2 is quite reasonable to use here. We'll only need to implement a set of strategies (like single primitive field strategy, complex collection field strategy) for all of the platforms.

Hyperjaxb3 roundtrip tests

Roundtrip tests are used within the integration testing in order to check if the generated O/R mapping (be it HBM files or annotations) are allright.

Typical roundtrip test senario is as follows:

  1. Unmarshall the file/resource.

  2. Save the unmarshalled object into the database, memorize the id.

  3. Load the object from the database by the memorized id.

  4. Compare unmarshalled and loaded objects, check identity.



I've already implemented a roundtrip test case for HBM file-based Hibernate mappings (see org.jvnet.hyperjaxb3.hibernate.roundtrip.RoundtripTestCase). You only have to subclass this class in the target package and specify which sample files should be used for testing (see org.jvnet.hyperjaxb3.hibernate.roundtrip.tests.RoundtripTestCaseTest). The tests runs versus the in-memory HSQLDB database, database schema is automatically generated, very easy to use.

I'll need such a roundtrip test for each for the target ORM platforms.

Hyperjaxb3 tests

Hyperjaxb3 is primarily a code generation/augmentation library. This means we not only need to test how individual classes/methods work, we also have to check if code generation works as a whole.

Therefore there are actually two types of tests:

Unit tests


Test behaviour and functionality of individual classes and methods. Unit tests accompany the main code, they are stored in the test directory (normal Maven convetions).

Integrated tests


The overall process of code generation (generation, compilation, roundtrip testing) can only be implemented in separated test projects. Test projects are positioned as sub-modules of the tests module. Each test project has its own pom.xml file with all the definitions needed to build this project. Test projects should also contain the roundtrip test case/suite which is executed during the test phase.

Hyperjaxb3 project structure

Hyperjaxb3 consists of the following modules:

hibernate-mapping


This module is the Hibernate Mapping DTD compiled compiled into Java classes using JAXB. This is used to generate Hibernate mappings as Java object structures rather than XML.

tools


Utility package analogous to the jaxbcommons project for JAXB 1.x. This module contains all kinds of tools for JAXb and XJC. At the same time there is no runtime code in this package.

core


Core generation module. This module will actually contain plugins to generate mappings and/or annotations.

runtime


Classes used in the runtime, for instance Hibernate accessors or custom types. This will be the only module/jar used in the runtime.

testing


Testing routines. Among others contains plugin test cases and roundtrip test cases.

tests


This module contains test projects.