|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectAssert
TestCase
XMLTestSupport
public abstract class XMLTestSupport
Abstract test class to be used to unit test bindings.
Subclasses must implement the createConfiguration()
method. It must
return a new instance of Configuration
. Example:
public MailTypeBindingTest extends XMLTestSupport {
protected Configuration createConfiguration() {
return new MLConfiguration();
}
}
The parse()
method is used to test binding parsing. Subclasses
should call this from test methods after building up an instance document
with document
. Example
public void testParsing() throws Exception {
//build up an instance document
//the root element
Element mailElement = document.createElementNS( ML.NAMESPACE, "mail" );
document.appendChild( mailElement );
mailElement.setAttribute( "id", "someId" );
....
//call parse
Mail mail = (Mail) parse();
//make assertions
assertEquals( "someId", mail.getId() );
}
The encode(Object, QName)
method is used to test binding encoding.
Subclasses should call this method from test methods after creating an
object to be encoded. Example:
public void testEncoding() throws Exception {
//create the mail object
Mail mail = new Mail( "someId" );
mail.setEnvelope( ... );
....
//call encode
Document document = encode( mail, new QName( ML.NAMESPACE, "mail" );
//make assertions
assertEquals( "mail", document.getDocumentElement().getNodeName() );
assertEquals( "someId", document.getDocumentElement().getAttribute( "id" ) );
}
The binding(QName)
method is used to obtain an instance of a
particular binding. Subclasses should call this method to assert other
properties of the binding, such as type mapping and execution mode. Example:
public void testType() {
//get an instance of the binding
Binding binding = binding( new QName( ML.NAMESPACE, "MailType" ) );
//make assertions
assertEquals( Mail.class, binding.getType() );
}
public void testExecutionMode() {
//get an instance of the binding
Binding binding = binding( new QName( ML.NAMESPACE, "MailType" ) );
//make assertions
assertEquals( Binding.OVERRIDE, binding.getExecutionMode() );
}
modules/extension/xsd-core (gt-xsd-core.jar)
Field Summary | |
---|---|
protected Document |
document
the instance document |
protected static Logger |
logger
Logging instance |
protected HashMap |
namespaceMappings
additional namespace mappings |
Constructor Summary | |
---|---|
XMLTestSupport()
|
Method Summary | |
---|---|
protected Binding |
binding(QName name)
Convenience method for obtaining an instance of a binding. |
protected void |
buildDocument(String xml)
Convenience method which parses the specified string into a dom and sets the built document which is to be parsed. |
protected abstract Configuration |
createConfiguration()
Tempalte method for subclasses to create the configuration to be used by the parser. |
protected Document |
encode(Object object,
QName element)
Encodes an object, element name pair. |
protected Document |
encode(Object object,
QName element,
QName type)
Encodes an object, element name pair explicitly specifying the type of the root element. |
protected Element |
getElementByQName(Document dom,
QName name)
Convenience method for finding a node in a document which matches the specified name. |
protected Element |
getElementByQName(Element parent,
QName name)
Convenience method for finding a single descendant of a particular node which matches the specified name. |
protected NodeList |
getElementsByQName(Document dom,
QName name)
Convenience method for finding nodes in a document which matche the specified name. |
protected NodeList |
getElementsByQName(Element parent,
QName name)
Convenience method for finding decendants of a particular node which match the specified name. |
protected Object |
parse()
Parses the built document. |
protected Object |
parse(QName type)
Parses the build document, explicity specifying the type of the root element. |
protected void |
print(Node dom)
Convenience method to dump the contents of the document to stdout. |
protected void |
registerNamespaceMapping(String prefix,
String uri)
Registers a namespace mapping. |
protected void |
registerNamespaces(Element root)
Deprecated. use registerNamespaceMapping(String, String) |
protected void |
setUp()
Creates an empty xml document. |
Methods inherited from class TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString |
Methods inherited from class Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static Logger logger
protected Document document
protected HashMap namespaceMappings
Constructor Detail |
---|
public XMLTestSupport()
Method Detail |
---|
protected void setUp() throws Exception
setUp
in class TestCase
Exception
protected void registerNamespaces(Element root)
registerNamespaceMapping(String, String)
Namespace mappings should be set as follows:
root.setAttribute( "xmlns:gml", http://www.opengis.net/gml" );
Subclasses of this method should register the default namespace, the default namesapce is the one returned by the configuration.
This method is intended to be extended or overiden. This implementation
registers the xsi,http://www.w3.org/2001/XMLSchema-instance
namespace.
root
- The root node of the instance document.protected void registerNamespaceMapping(String prefix, String uri)
This mapping will be included in the "namespace context" of both the parser and the encoder.
prefix
- The prefix of the namespace, not null
.uri
- The uri of the namespace, not null
.protected abstract Configuration createConfiguration()
protected Object parse(QName type) throws Exception
This method should be called after building the entire document.
type
- The name of the type of the root element of the build document.
Exception
protected Object parse() throws Exception
This method should be called after building the entire document.
Exception
protected Document encode(Object object, QName element, QName type) throws Exception
object
- The object to encode.element
- The name of the element to encode.type
- The type of the element
Exception
protected Document encode(Object object, QName element) throws Exception
object
- The object to encode.element
- The name of the element to encode.
Exception
protected void print(Node dom) throws Exception
Exception
protected Binding binding(QName name)
name
- The qualified name of the element,attribute,or type the
binding "binds" to, the key of the binding in the container.
protected void buildDocument(String xml) throws Exception
xml
- A string of xml
Exception
protected Element getElementByQName(Document dom, QName name)
protected Element getElementByQName(Element parent, QName name)
protected NodeList getElementsByQName(Document dom, QName name)
protected NodeList getElementsByQName(Element parent, QName name)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |