I am developing a library that will be used to marshall and unmarshall data into an xml format for transmission. I now have two versions of a Jar containing a com.mycorp.Marshaller
class that I want to test for compatibility (as we cannot update all clients at the same time).
Does anyone know if it is possible to write a unit test that can load both version A and version B of the class and use them in unison to ensure xml outputted by B can be parsed by A.
I cannot use the fully qualified name as this is identical in both cases, and I cannot change it as version B is intended to be a drop-in replacement.
Does anybody have any idea how to load two different versions (from different jars) of a class with the same fully qualified name?
You could do this: create a class loader that loads the class by name from one of the jars. Then invode the marshalling and create the XML. After this, create another instance of the class loader (or another classloader altogether) to load the class by name from the other jar, and parse the XML with the object created via this second class loader.
If you run into trouble, you could always create two tests: one to create the xml with version A, then another to parse the XML with version B. The two tests can be run in separate JVMs, one after the other