Package org.opensaml.core.testing

# Class XMLObjectBaseTestCase

java.lang.Object
org.opensaml.core.testing.OpenSAMLInitBaseTestCase
org.opensaml.core.testing.XMLObjectBaseTestCase

Direct Known Subclasses:
  `XMLObjectProviderBaseTestCase`

public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase
Base test case class for tests that operate on XMLObjects.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static XMLObjectBuilderFactory`
`builderFactory`
XMLObject builder factory.
`private final org.slf4j.Logger`
`log`
Logger.
`protected static MarshallerFactory`
`marshallerFactory`
XMLObject marshaller factory.
`protected static ParserPool`
`parserPool`
Parser pool.
`protected static QName`
`simpleXMLObjectQName`
QName for SimpleXMLObject.
`protected static UnmarshallerFactory`
`unmarshallerFactory`
XMLObject unmarshaller factory.

## Constructor Summary

Constructors
Constructor
Description
`XMLObjectBaseTestCase()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`assertXMLEquals(String failMessage, Document expectedDOM, XMLObject xmlObject)`
Asserts a given XMLObject is equal to an expected DOM.
`protected void`
`assertXMLEquals(Document expectedDOM, XMLObject xmlObject)`
Asserts a given XMLObject is equal to an expected DOM.
`protected <T extends XMLObject>
T`
`buildXMLObject(QName name)`
Builds the requested XMLObject.
`protected <T extends XMLObject>
XMLObjectBuilder<T>`
`getBuilder(QName qname)`
Lookup the XMLObjectBuilder for a QName.
`protected Marshaller`
`getMarshaller(QName qname)`
Lookup the marshaller for a QName.
`protected Marshaller`
`getMarshaller(XMLObject xmlObject)`
Lookup the marshaller for an XMLObject.
`protected Unmarshaller`
`getUnmarshaller(QName qname)`
Lookup the unmarshaller for a QName.
`protected Unmarshaller`
`getUnmarshaller(XMLObject xmlObject)`
Lookup the unmarshaller for an XMLObject.
`protected Unmarshaller`
`getUnmarshaller(Element element)`
Lookup the unmarshaller for a DOM Element.
`protected void`
`initXMLObjectSupport()`
Init support of XMLObjects.
`protected Document`
`parseXMLDocument(String xmlFilename)`
Parse an XML file as a classpath resource.
`protected void`
`printXML(XMLObject xmlObject, String filename)`
For convenience when testing, pretty-print the specified XMLObject to a file, or to the console if filename is null.
`protected void`
`printXML(Node node, String filename)`
For convenience when testing, pretty-print the specified DOM node to a file, or to the console if filename is null.
`protected <T extends XMLObject>
T`
`unmarshallElement(String elementFile)`
Unmarshalls an element file into its XMLObject.
`protected <T extends XMLObject>
T`
`unmarshallElement(String elementFile, boolean propagateErrors)`
Unmarshalls an element file into its XMLObject.

### Methods inherited from class org.opensaml.core.testing.OpenSAMLInitBaseTestCase

`initOpenSAML`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### parserPool

protected static ParserPool parserPool
Parser pool.

### builderFactory

protected static XMLObjectBuilderFactory builderFactory
XMLObject builder factory.

### marshallerFactory

protected static MarshallerFactory marshallerFactory
XMLObject marshaller factory.

### unmarshallerFactory

protected static UnmarshallerFactory unmarshallerFactory
XMLObject unmarshaller factory.

### simpleXMLObjectQName

@Nonnull protected static QName simpleXMLObjectQName
QName for SimpleXMLObject.

### log

@Nonnull private final org.slf4j.Logger log
Logger.

## Constructor Details

### XMLObjectBaseTestCase

public XMLObjectBaseTestCase()

## Method Details

### initXMLObjectSupport

@BeforeClass protected void initXMLObjectSupport() throws Exception
Init support of XMLObjects.

Throws:
  `Exception` - on error

### assertXMLEquals

protected void assertXMLEquals(Document expectedDOM, @Nonnull XMLObject xmlObject)
Asserts a given XMLObject is equal to an expected DOM. The XMLObject is marshalled and the resulting DOM object is compared against the expected DOM object for equality.

Parameters:
  `expectedDOM` - the expected DOM
  `xmlObject` - the XMLObject to be marshalled and compared against the expected DOM

### assertXMLEquals

protected void assertXMLEquals(String failMessage, Document expectedDOM, XMLObject xmlObject)
Asserts a given XMLObject is equal to an expected DOM. The XMLObject is marshalled and the resulting DOM object is compared against the expected DOM object for equality.

Parameters:
  `failMessage` - the message to display if the DOMs are not equal
  `expectedDOM` - the expected DOM
  `xmlObject` - the XMLObject to be marshalled and compared against the expected DOM

### buildXMLObject

@Nonnull protected <T extends XMLObject> T buildXMLObject(@Nonnull QName name)
Builds the requested XMLObject.

Type Parameters:
  `T` - type of the result
Parameters:
  `name` - name of the XMLObject
Returns:
  the built XMLObject

### unmarshallElement

@Nullable protected <T extends XMLObject> T unmarshallElement(@Nonnull String elementFile)
Unmarshalls an element file into its XMLObject.

Type Parameters:
  `T` - expected type
Parameters:
  `elementFile` - the element file to unmarshall
Returns:
  the XMLObject from the file

### unmarshallElement

@Nullable protected <T extends XMLObject> T unmarshallElement(@Nonnull String elementFile, boolean propagateErrors) throws XMLParserException, UnmarshallingException
Unmarshalls an element file into its XMLObject.

Type Parameters:
  `T` - expected type
Parameters:
  `elementFile` - the element file to unmarshall
  `propagateErrors` - if true, checked exceptions will be thrown, if false then they cause assertion of test failure
Returns:
  the XMLObject from the file
Throws:
  `XMLParserException` - ...
  `UnmarshallingException` - ...

### printXML

protected void printXML(@Nonnull Node node, @Nonnull String filename)
For convenience when testing, pretty-print the specified DOM node to a file, or to the console if filename is null.

Parameters:
  `node` - node to print
  `filename` - name of file to print to

### printXML

protected void printXML(@Nonnull XMLObject xmlObject, @Nonnull String filename)
For convenience when testing, pretty-print the specified XMLObject to a file, or to the console if filename is null.

Parameters:
  `xmlObject` - `XMLObject` to print
  `filename` - name of file to print to

### getBuilder

@Nonnull protected <T extends XMLObject> XMLObjectBuilder<T> getBuilder(@Nonnull QName qname)
Lookup the XMLObjectBuilder for a QName.

Type Parameters:
  `T` - type of result for the `XMLObjectBuilder`
Parameters:
  `qname` - the QName for which to find the builder
Returns:
  the XMLObjectBuilder

### getMarshaller

@Nonnull protected Marshaller getMarshaller(@Nonnull QName qname)
Lookup the marshaller for a QName.

Parameters:
  `qname` - the QName for which to find the marshaller
Returns:
  the marshaller

### getMarshaller

@Nonnull protected Marshaller getMarshaller(@Nonnull XMLObject xmlObject)
Lookup the marshaller for an XMLObject.

Parameters:
  `xmlObject` - the XMLObject for which to find the marshaller
Returns:
  the marshaller

### getUnmarshaller

@Nonnull protected Unmarshaller getUnmarshaller(@Nonnull QName qname)
Lookup the unmarshaller for a QName.

Parameters:
  `qname` - the QName for which to find the unmarshaller
Returns:
  the unmarshaller

### getUnmarshaller

@Nonnull protected Unmarshaller getUnmarshaller(@Nonnull XMLObject xmlObject)
Lookup the unmarshaller for an XMLObject.

Parameters:
  `xmlObject` - the XMLObject for which to find the unmarshaller
Returns:
  the unmarshaller

### getUnmarshaller

@Nonnull protected Unmarshaller getUnmarshaller(@Nonnull Element element)
Lookup the unmarshaller for a DOM Element.

Parameters:
  `element` - the Element for which to find the unmarshaller
Returns:
  the unmarshaller

### parseXMLDocument

@Nonnull protected Document parseXMLDocument(@Nonnull String xmlFilename) throws XMLParserException
Parse an XML file as a classpath resource.

Parameters:
  `xmlFilename` - the file to parse
Returns:
  the parsed Document
Throws:
  `XMLParserException` - if parsing did not succeed