|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.geotools.xml.test.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() );
}
Field Summary | |
---|---|
protected org.w3c.dom.Document |
document
the instance document |
protected static java.util.logging.Logger |
logger
Logging instance |
protected java.util.HashMap |
namespaceMappings
additional namespace mappings |
Constructor Summary | |
---|---|
XMLTestSupport()
|
Method Summary | |
---|---|
protected Binding |
binding(javax.xml.namespace.QName name)
Convenience method for obtaining an instance of a binding. |
protected void |
buildDocument(java.lang.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 org.w3c.dom.Document |
encode(java.lang.Object object,
javax.xml.namespace.QName element)
Encodes an object, element name pair. |
protected org.w3c.dom.Document |
encode(java.lang.Object object,
javax.xml.namespace.QName element,
javax.xml.namespace.QName type)
Encodes an object, element name pair explicitly specifying the type of the root element. |
protected org.w3c.dom.Element |
getElementByQName(org.w3c.dom.Document dom,
javax.xml.namespace.QName name)
Convenience method for finding a node in a document which matches the specified name. |
protected org.w3c.dom.Element |
getElementByQName(org.w3c.dom.Element parent,
javax.xml.namespace.QName name)
Convenience method for finding a single descendant of a particular node which matches the specified name. |
protected org.w3c.dom.NodeList |
getElementsByQName(org.w3c.dom.Document dom,
javax.xml.namespace.QName name)
Convenience method for finding nodes in a document which matche the specified name. |
protected org.w3c.dom.NodeList |
getElementsByQName(org.w3c.dom.Element parent,
javax.xml.namespace.QName name)
Convenience method for finding decendants of a particular node which match the specified name. |
protected java.lang.Object |
parse()
Parses the built document. |
protected java.lang.Object |
parse(javax.xml.namespace.QName type)
Parses the build document, explicity specifying the type of the root element. |
protected void |
print(org.w3c.dom.Node dom)
Convenience method to dump the contents of the document to stdout. |
protected void |
registerNamespaceMapping(java.lang.String prefix,
java.lang.String uri)
Registers a namespace mapping. |
protected void |
registerNamespaces(org.w3c.dom.Element root)
Deprecated. use registerNamespaceMapping(String, String) |
protected void |
setUp()
Creates an empty xml document. |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString |
Methods inherited from class junit.framework.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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static java.util.logging.Logger logger
protected org.w3c.dom.Document document
protected java.util.HashMap namespaceMappings
Constructor Detail |
---|
public XMLTestSupport()
Method Detail |
---|
protected void setUp() throws java.lang.Exception
setUp
in class junit.framework.TestCase
java.lang.Exception
protected void registerNamespaces(org.w3c.dom.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(java.lang.String prefix, java.lang.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 java.lang.Object parse(javax.xml.namespace.QName type) throws java.lang.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.
java.lang.Exception
protected java.lang.Object parse() throws java.lang.Exception
This method should be called after building the entire document.
java.lang.Exception
protected org.w3c.dom.Document encode(java.lang.Object object, javax.xml.namespace.QName element, javax.xml.namespace.QName type) throws java.lang.Exception
object
- The object to encode.element
- The name of the element to encode.type
- The type of the element
java.lang.Exception
protected org.w3c.dom.Document encode(java.lang.Object object, javax.xml.namespace.QName element) throws java.lang.Exception
object
- The object to encode.element
- The name of the element to encode.
java.lang.Exception
protected void print(org.w3c.dom.Node dom) throws java.lang.Exception
java.lang.Exception
protected Binding binding(javax.xml.namespace.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(java.lang.String xml) throws java.lang.Exception
xml
- A string of xml
java.lang.Exception
protected org.w3c.dom.Element getElementByQName(org.w3c.dom.Document dom, javax.xml.namespace.QName name)
protected org.w3c.dom.Element getElementByQName(org.w3c.dom.Element parent, javax.xml.namespace.QName name)
protected org.w3c.dom.NodeList getElementsByQName(org.w3c.dom.Document dom, javax.xml.namespace.QName name)
protected org.w3c.dom.NodeList getElementsByQName(org.w3c.dom.Element parent, javax.xml.namespace.QName name)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |