Package org.opensaml.core.testing
Class XMLObjectBaseTestCase
- java.lang.Object
-
- org.opensaml.core.testing.OpenSAMLInitBaseTestCase
-
- org.opensaml.core.testing.XMLObjectBaseTestCase
-
- Direct Known Subclasses:
AbstractXMLObjectTest,AttributeMapTest,ElementProxyTest,FilesystemLoadSaveManagerTest,IDAttributeTest,MapLoadSaveManagerTest,MarshallingTest,NamespaceManagerTest,UnmarshallingSecurityTest,UnmarshallingTest,XMLObjectProviderBaseTestCase,XMLObjectSupportTest,XMLObjectXSIAttribsTest,XSBase64BinaryTest,XSBooleanTest,XSDateTimeTest,XSIntegerTest,XSQNameTest,XSStringTest,XSURITest
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 XMLObjectBuilderFactorybuilderFactoryXMLObject builder factoryprivate org.slf4j.LoggerlogLoggerprotected static MarshallerFactorymarshallerFactoryXMLObject marshaller factoryprotected static ParserPoolparserPoolParser poolprotected static QNamesimpleXMLObjectQNameQName for SimpleXMLObjectprotected static UnmarshallerFactoryunmarshallerFactoryXMLObject unmarshaller factory
-
Constructor Summary
Constructors Constructor Description XMLObjectBaseTestCase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertXMLEquals(String failMessage, Document expectedDOM, XMLObject xmlObject)Asserts a given XMLObject is equal to an expected DOM.protected voidassertXMLEquals(Document expectedDOM, XMLObject xmlObject)Asserts a given XMLObject is equal to an expected DOM.protected <T extends XMLObject>
TbuildXMLObject(QName name)Builds the requested XMLObject.protected <T extends XMLObject>
XMLObjectBuilder<T>getBuilder(QName qname)Lookup the XMLObjectBuilder for a QName.protected MarshallergetMarshaller(QName qname)Lookup the marshaller for a QNameprotected MarshallergetMarshaller(XMLObject xmlObject)Lookup the marshaller for an XMLObject.protected UnmarshallergetUnmarshaller(QName qname)Lookup the unmarshaller for a QName.protected UnmarshallergetUnmarshaller(XMLObject xmlObject)Lookup the unmarshaller for an XMLObject.protected UnmarshallergetUnmarshaller(Element element)Lookup the unmarshaller for a DOM Element.protected voidinitXMLObjectSupport()protected DocumentparseXMLDocument(String xmlFilename)Parse an XML file as a classpath resource.protected voidprintXML(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 voidprintXML(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>
TunmarshallElement(String elementFile)Unmarshalls an element file into its XMLObject.protected <T extends XMLObject>
TunmarshallElement(String elementFile, boolean propagateErrors)Unmarshalls an element file into its XMLObject.-
Methods inherited from class org.opensaml.core.testing.OpenSAMLInitBaseTestCase
initOpenSAML
-
-
-
-
Field Detail
-
log
private final org.slf4j.Logger log
Logger
-
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
protected static QName simpleXMLObjectQName
QName for SimpleXMLObject
-
-
Method Detail
-
initXMLObjectSupport
@BeforeClass protected void initXMLObjectSupport() throws Exception- Throws:
Exception
-
assertXMLEquals
protected void assertXMLEquals(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:
expectedDOM- the expected DOMxmlObject- 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 equalexpectedDOM- the expected DOMxmlObject- the XMLObject to be marshalled and compared against the expected DOM
-
buildXMLObject
protected <T extends XMLObject> T buildXMLObject(QName name)
Builds the requested XMLObject.- Type Parameters:
T- type of the result- Parameters:
name- name of the XMLObject- Returns:
- the built XMLObject
-
unmarshallElement
protected <T extends XMLObject> T unmarshallElement(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
protected <T extends XMLObject> T unmarshallElement(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 unmarshallpropagateErrors- 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(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.- Parameters:
node- node to printfilename- name of file to print to
-
printXML
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.- Parameters:
xmlObject-XMLObjectto printfilename- name of file to print to
-
getBuilder
protected <T extends XMLObject> XMLObjectBuilder<T> getBuilder(QName qname)
Lookup the XMLObjectBuilder for a QName.- Type Parameters:
T- type of result for theXMLObjectBuilder- Parameters:
qname- the QName for which to find the builder- Returns:
- the XMLObjectBuilder
-
getMarshaller
protected Marshaller getMarshaller(QName qname)
Lookup the marshaller for a QName- Parameters:
qname- the QName for which to find the marshaller- Returns:
- the marshaller
-
getMarshaller
protected Marshaller getMarshaller(XMLObject xmlObject)
Lookup the marshaller for an XMLObject.- Parameters:
xmlObject- the XMLObject for which to find the marshaller- Returns:
- the marshaller
-
getUnmarshaller
protected Unmarshaller getUnmarshaller(QName qname)
Lookup the unmarshaller for a QName.- Parameters:
qname- the QName for which to find the unmarshaller- Returns:
- the unmarshaller
-
getUnmarshaller
protected Unmarshaller getUnmarshaller(XMLObject xmlObject)
Lookup the unmarshaller for an XMLObject.- Parameters:
xmlObject- the XMLObject for which to find the unmarshaller- Returns:
- the unmarshaller
-
getUnmarshaller
protected Unmarshaller getUnmarshaller(Element element)
Lookup the unmarshaller for a DOM Element.- Parameters:
element- the Element for which to find the unmarshaller- Returns:
- the unmarshaller
-
parseXMLDocument
protected Document parseXMLDocument(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
-
-