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 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