Posts tagged code tr69
from the discarded ruins of JSystem and Castor emerges…reCastor!
Some time ago I described how I moved away from the JUnit framework as the tool moved from unit testing to functional testing. Now I've begun replacing two other frameworks that I've outgrown: JSystem and Castor.
JSystem is a way of specifying options for overall system testing. It generates objects at runtime from an XML format. It works pretty well if you have a static test setup that only developers might have to interact with. However, it makes a lot of assumptions by default that are extremely difficult to change. Assumptions of configuration file location, naming, and structure are built deep into the code — it's just not configurable at all. What few things you can change have to be done via system properties and are mostly ignored unless the defaults actually fail. There is a Sut configuration file to allow the test tool's user to specify objects and values for dynamic instantiation, but JSystems requires extra info info in the Sut file that is confusing and unnecessary for an end user, like the full class name of each defined object. JSystem could be nice if it didn't make so many hardcoded assumptions.
<post example here tomorrow…>
As for Castor — it is a really slick system for building objects straight from XML or from a real DTD with the ability to rewrite them with changes back to XML. The castor tool generates objects that do all the XML packing and unpacking; Each Castor-generated object knows how to marshal and unmarshal itself. They are pretty easy to modify and extend. However the castor library pushes 2 megs in size. The truth is, I'm using a very small part of the functionality of Castor. I hate including it for the small portion of the code that needs it, because it is about 20% of the size of the entire contents of the test tool package.
If I can strip out JSystem and Castor and all the libraries they depend on I can cut the package size in half and get rid of a lot of messy hacks that exist only to work around JSystem's stupidities.
So my current side project is a replacement for the both of them. It reads in an XML file and pushes the data values into objects via reflection, all done at runtime. It requires a simple mapping file that for now is just this:
nbbs -> src.NbbsSystemObject
cpe -> src.CpeObject
This says that an <nbbs> node in the XML maps to the src.NbbsSystemObject class. When the DOM parser encounters an nbbs tag it instantiates that object via reflection. Then for each sub-element like, say, url and apiPath nodes it searches the NbbsSystemObject for those fields and sets their value via reflection. If they are private it temporarily renders them accessible to set the value.
Thus this new tool makes no assumptions about the XML it will have to process. It just deals with it on a lazy basis. It's really basic right now, but amazingly the darn thing works. It successfully turned the following XML into an NBBS object and 2 CPE objects, which is exactly what I currently get from the entire JSystem framework:
<sut> <nbbs> <url>http://nbbsserverurl</url> <apiPath>/apipath</apiPath> </nbbs> <cpe> <serialNumber>19687076</serialNumber> <model>3347NWG</model> </cpe> <cpe> <serialNumber>9756472</serialNumber> <model>3397GP</model> </cpe> </sut>
Lines of code required: 90. Obviously there is lots to do with it, but it works. First thing tomorrow I'm ripping out the JSystem and Castor code. It's gonna be great.