Defining Objects

<objs><obj id="myId" type="my.class.Type" hint="myParseHint">...</obj><objs>

Defining objects inside of the xml data files of DDTUnit should be as clear and easy as to write the appropriate code in Java.
To achieve this the object structure was mapped onto the xml definition as straight as possible.

As a starting point the following object types are supported:

  • all objects that contain a constructor of the form public MyClass(java.lang.String).
  • all objects containing a default constructor and using (even private) field definitions can be generated.
    Java reflection is used to map xml field names on objects field definitions.
    (See Generic Structures)
  • all objects containing a default constructor and using setter methods according to JavaBean spec can be generated.
    (See Generic Bean Structures)
  • For now two container object implementations are supported. (See Container Structures).
  • Calling constructor or static methods of object is supported in a first implementation. (See Constructor Structures).
  • Constants are supported as defined by static fields of classes and typesafe enumerations. (See Constant Structures)
  • Special data types and keywords. (See Object Specialties)
  • Shortcut notation using object type abbreviation. (See Object Specialties)

The testdata can be accessed by using the following API called from DDTTestCase class:

DDTTestCase 
  public Object getObject(String id); // or 
  public Object getObject(String id, String type); 
  public Object getGlobalObject(String id); // or 
  public Object getGlobalObject(String id, String type); 
  public Object getResourceObject(String id); // or 
  public Object getResourceObject(String id, String type);
    
A general remark on XML structure used for object definition. Basically every object definition possesses three attributes to describe it.
These are:
  1. obj@id and obj@type allow identification of objects. If there are only a few objects defined per test and these are uniquely identified by using the obj@id the first method can be used. If multiple objects were found this method will throw a DDTException and the second method definition must be used.
  2. obj@hint - (Default: fields) specifies parsing information for internal processing
sf logo