ShrinkWrap Descriptors Test Utilities 2.0.0-alpha-3

org.jboss.shrinkwrap.descriptor.test.util
Class XmlAssert

java.lang.Object
  extended by org.jboss.shrinkwrap.descriptor.test.util.XmlAssert

public final class XmlAssert
extends Object

Simple helper for XML related Assertions.

Version:
$Revision: $
Author:
Aslak Knutsen, Bartosz Majsak

Method Summary
static void assertAbsenceUsingXPath(String xml, String expression)
          Verifies if XML file does not contain elements matching given XPath expression.
static void assertDefaultNamespace(String xml, String expectedURI)
          Verifies if default namespace (xmlns attribute of the root element) has expected URI.
static void assertIdentical(String expected, String actual)
          Asserts equality of two XML files comparing flatten versions - stripped from leading and trailing whitespaces and those between xml nodes.
static void assertNamespaceURIDefined(String xml, String namespace, String expectedURI)
          Verifies if given namespace has URI defined.
static void assertPresenceUsingXPath(String xml, String expression, Object... expectedValue)
           
static void assertPresenceUsingXPath(String xml, String expression, String... expectedValues)
          Assert that the specified XPath Expression resolves to the specified values.
static void assertSchemaLocation(String xml, String namespaceUri, String expectedLocation)
          Verifies if given namespace has proper URI defined using ns:schemaLocation attribute.
static void assertSimilar(String firstXml, String secondXml)
          Asserts similarity of two XML files comparing flatten versions - stripped from leading and trailing whitespaces and those between xml nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

assertSchemaLocation

public static void assertSchemaLocation(String xml,
                                        String namespaceUri,
                                        String expectedLocation)
Verifies if given namespace has proper URI defined using ns:schemaLocation attribute.

Parameters:
xml - The XML to assert against
namespaceUri - The namespace URI to assert against
expectedLocation - The expected location for given namespace
Throws:
Exception - Assertion error or XML related parse exceptions

assertDefaultNamespace

public static void assertDefaultNamespace(String xml,
                                          String expectedURI)
Verifies if default namespace (xmlns attribute of the root element) has expected URI.

Parameters:
xml - to be verified
expectedNamespace - expected value of xmlns attribute
Throws:
Exception - Assertion error or XML related parse exceptions.

assertNamespaceURIDefined

public static void assertNamespaceURIDefined(String xml,
                                             String namespace,
                                             String expectedURI)
Verifies if given namespace has URI defined.

Parameters:
xml - to be verified
namespace -
expectedURI - expected value of xmlns attribute
Throws:
Exception - Assertion error or XML related parse exceptions.

assertPresenceUsingXPath

public static void assertPresenceUsingXPath(String xml,
                                            String expression,
                                            String... expectedValues)
Assert that the specified XPath Expression resolves to the specified values.

Assertions:
"XPath expressions doesn't match with given XML"
"ExpectedValue count should match found Node count"
"XPath content should match expected value"

Parameters:
xml - The XML to assert against
expression - XPath expression to extract
expectedValues - The Expected values found by expression
Throws:
Exception - Assertion error or XML/XPath related parse exceptions

assertPresenceUsingXPath

public static void assertPresenceUsingXPath(String xml,
                                            String expression,
                                            Object... expectedValue)
                                     throws Exception
Throws:
Exception

assertAbsenceUsingXPath

public static void assertAbsenceUsingXPath(String xml,
                                           String expression)
Verifies if XML file does not contain elements matching given XPath expression.

Parameters:
xml - The XML file to verify.
expression - The XPath expression to evaluate.
Throws:
Exception - Assertion error or XML/XPath related parse exceptions

assertIdentical

public static void assertIdentical(String expected,
                                   String actual)
Asserts equality of two XML files comparing flatten versions - stripped from leading and trailing whitespaces and those between xml nodes.

Parameters:
expected -
actual -
Throws:
Exception - Assertion error when given string don't match

assertSimilar

public static void assertSimilar(String firstXml,
                                 String secondXml)
Asserts similarity of two XML files comparing flatten versions - stripped from leading and trailing whitespaces and those between xml nodes. Two XMLs are considered similar when they contain the same element but they might be present in different order.

Parameters:
firstXml -
secondXml -
Throws:
Exception - Assertion error when given string don't match

ShrinkWrap Descriptors Test Utilities 2.0.0-alpha-3

Copyright © 2012 JBoss by Red Hat. All Rights Reserved.