FileDocCategorySizeDatePackage
DOMTestCase.javaAPI DocAndroid 1.5 API26305Wed May 06 22:41:04 BST 2009org.w3c.domts

DOMTestCase

public abstract class DOMTestCase extends DOMTest
This is an abstract base class for generated DOM tests

Fields Summary
private DOMTestFramework
framework
Constructors Summary
public DOMTestCase()
This constructor is for DOMTestCase's that make specific demands for parser configuration. setFactory should be called before the end of the tests constructor to set the factory.

    framework = null;
  
public DOMTestCase(DOMTestDocumentBuilderFactory factory)
This constructor is for DOMTestCase's that do not add any requirements for parser configuration.

param
factory document factory to be used by test, may not be null.

    super(factory);
    framework = null;
  
Methods Summary
public voidassertEqualAutoCase(java.lang.String context, java.lang.String assertID, java.util.Collection expected, java.util.Collection actual)
Asserts that each entry in actual is matched with an entry in expected that only differs by case. Order is not significant.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    String contentType = getContentType();
    if ("text/html".equals(contentType)) {
      if ("attribute".equals(context)) {
        assertEqualsIgnoreCase(assertID, expected, actual);
      }
      else {
        framework.assertEquals(this, assertID, toUpperCase(expected), actual);
      }

    }
    else {
      framework.assertEquals(this, assertID, expected, actual);
    }
  
public voidassertEquals(java.lang.String assertID, java.lang.String expected, java.lang.String actual)
Asserts that expected.equals(actual) is true

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEquals(this, assertID, expected, actual);
  
public voidassertEquals(java.lang.String assertID, int expected, int actual)
Asserts that values of expected and actual are equal.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEquals(this, assertID, expected, actual);
  
public voidassertEquals(java.lang.String assertID, double expected, double actual)
Asserts that values of expected and actual are equal.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEquals(this, assertID, expected, actual);
  
public voidassertEquals(java.lang.String assertID, boolean expected, boolean actual)
Asserts that values of expected and actual are equal.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEquals(this, assertID, expected, actual);
  
public voidassertEquals(java.lang.String assertID, java.util.Collection expected, org.w3c.dom.NodeList actual)
Asserts that each entry in actual exactly matches with an entry in expected. Order is not significant.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    Collection actualList = new ArrayList();
    int actualLen = actual.getLength();
    for (int i = 0; i < actualLen; i++) {
      actualList.add(actual.item(i));
    }
    framework.assertEquals(this, assertID, expected, actualList);
  
public voidassertEquals(java.lang.String assertID, java.util.Collection expected, java.util.Collection actual)
Asserts that each entry in actual exactly matches with an entry in expected. Order is not significant.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEquals(this, assertID, expected, actual);
  
public voidassertEqualsAutoCase(java.lang.String context, java.lang.String assertID, java.lang.String expected, java.lang.String actual)
Asserts that expected.equalsIgnoreCase(actual) is true

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    String contentType = getContentType();
    //
    //   if the content type is HTML (not XHTML)
    //
    if ("text/html".equals(contentType)) {
      //
      //  if the context is attribute, then use case-insentive comparison
      //
      if ("attribute".equals(context)) {
        framework.assertEqualsIgnoreCase(this, assertID, expected, actual);
      }
      else {
        //
        //  otherwise should be compared against uppercased expectation
        framework.assertEquals(this, assertID, expected.toUpperCase(), actual);
      }
    }
    else {
      framework.assertEquals(this, assertID, expected, actual);
    }
  
public voidassertEqualsAutoCase(java.lang.String context, java.lang.String assertID, java.util.List expected, java.util.List actual)
Asserts that each entry in actual is matched with an entry in expected that only differs by case. Order is significant.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    String contentType = getContentType();
    if ("text/html".equals(contentType)) {
      if ("attribute".equals(context)) {
        assertEqualsIgnoreCase(assertID, expected, actual);
      }
      else {
        framework.assertEquals(this, assertID, toUpperCase(expected), actual);
      }

    }
    else {
      framework.assertEquals(this, assertID, expected, actual);
    }
  
public voidassertEqualsIgnoreCase(java.lang.String assertID, java.lang.String expected, java.lang.String actual)
Asserts that expected.equalsIgnoreCase(actual) is true

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEqualsIgnoreCase(this, assertID, expected, actual);
  
public voidassertEqualsIgnoreCase(java.lang.String assertID, java.util.Collection expected, java.util.Collection actual)
Asserts that each entry in actual is matched with an entry in expected that only differs by case. Order is not significant.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEqualsIgnoreCase(this, assertID, expected, actual);
  
public voidassertEqualsIgnoreCase(java.lang.String assertID, java.util.List expected, java.util.List actual)
Asserts that each entry in actual is matched with an entry in expected that only differs by case. Order is significant.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertEqualsIgnoreCase(this, assertID, expected, actual);
  
public voidassertFalse(java.lang.String assertID, boolean actual)
Asserts that actual==false

param
assertID identifier of assertion
param
actual actual value

    framework.assertFalse(this, assertID, actual);
  
public voidassertFalse(java.lang.String assertID, java.lang.Object actual)
Asserts that actual==false

param
assertID identifier of assertion
param
actual actual value

    framework.assertFalse(
        this,
        assertID,
        ( (Boolean) actual).booleanValue());
  
public voidassertInstanceOf(java.lang.String assertID, java.lang.Class cls, java.lang.Object obj)
Asserts that obj is an instance of cls

param
assertID identifier of assertion
param
obj object
param
cls class, may not be null.

    framework.assertInstanceOf(this, assertID, obj, cls);
  
public voidassertNotEquals(java.lang.String assertID, java.lang.String expected, java.lang.String actual)
Asserts that values of expected and actual are not equal.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertNotEquals(this, assertID, expected, actual);
  
public voidassertNotEquals(java.lang.String assertID, int expected, int actual)
Asserts that values of expected and actual are not equal.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertNotEquals(this, assertID, expected, actual);
  
public voidassertNotEquals(java.lang.String assertID, double expected, double actual)
Asserts that values of expected and actual are not equal.

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertNotEquals(this, assertID, expected, actual);
  
public voidassertNotEqualsAutoCase(java.lang.String context, java.lang.String assertID, java.lang.String expected, java.lang.String actual)
Asserts that expected.equalsIgnoreCase(actual) is false

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    String contentType = getContentType();
    if ("text/html".equals(contentType)) {
      if ("attribute".equals(context)) {
        framework.assertNotEqualsIgnoreCase(this, assertID, expected, actual);
      }
      else {
        framework.assertNotEquals(this, assertID, expected.toUpperCase(),
                                  actual);
      }
    }
    framework.assertNotEquals(this, assertID, expected, actual);
  
public voidassertNotEqualsIgnoreCase(java.lang.String assertID, java.lang.String expected, java.lang.String actual)
Asserts that expected.equalsIgnoreCase(actual) is false

param
assertID identifier of assertion
param
actual actual value
param
expected Expected value, may not be null.

    framework.assertNotEqualsIgnoreCase(this, assertID, expected, actual);
  
public voidassertNotNull(java.lang.String assertID, java.lang.Object actual)
Asserts that actual != null

param
assertID identifier of assertion
param
actual actual value

    framework.assertNotNull(this, assertID, actual);
  
public voidassertNull(java.lang.String assertID, java.lang.Object actual)
Asserts that actual == null

param
assertID identifier of assertion
param
actual actual value

    framework.assertNull(this, assertID, actual);
  
public voidassertSame(java.lang.String assertID, java.lang.Object expected, java.lang.Object actual)
Asserts that actual and expected are the same object

param
assertID identifier of assertion
param
actual actual value

    framework.assertSame(this, assertID, expected, actual);
  
public voidassertSize(java.lang.String assertID, int expectedSize, org.w3c.dom.NodeList collection)
Asserts that the length of the collection is the expected size.

param
assertID identifier of assertion
param
expectedSize expected size
param
collection collection

    framework.assertSize(this, assertID, expectedSize, collection);
  
public voidassertSize(java.lang.String assertID, int expectedSize, org.w3c.dom.NamedNodeMap collection)
Asserts that the length of the collection is the expected size.

param
assertID identifier of assertion
param
expectedSize expected size
param
collection collection

    framework.assertSize(this, assertID, expectedSize, collection);
  
public voidassertSize(java.lang.String assertID, int expectedSize, java.util.Collection collection)
Asserts that the length of the collection is the expected size.

param
assertID identifier of assertion
param
expectedSize expected size
param
collection collection

    framework.assertSize(this, assertID, expectedSize, collection);
  
public voidassertTrue(java.lang.String assertID, boolean actual)
Asserts that actual==true

param
assertID identifier of assertion
param
actual actual value

    framework.assertTrue(this, assertID, actual);
  
public voidassertTrue(java.lang.String assertID, java.lang.Object actual)
Asserts that actual==true

param
assertID identifier of assertion
param
actual actual value

    framework.assertTrue(this, assertID, ( (Boolean) actual).booleanValue());
  
public voidassertURIEquals(java.lang.String assertID, java.lang.String scheme, java.lang.String path, java.lang.String host, java.lang.String file, java.lang.String name, java.lang.String query, java.lang.String fragment, java.lang.Boolean isAbsolute, java.lang.String actual)
Asserts aspects of a URI

param
assertID identifier of assertion
param
scheme Expected scheme, for example, "file". If null, scheme is ignored.
param
path Expected path, for example, "/DOM/Test". If null, path is ignored.
param
host Expected host, for example, "www.w3.org". If null, host is ignored.
param
file Expected file, for example, "staff.xml". If null, file is ignored.
param
name Expected name, for example, "staff". If null, name is ignored.
param
name Expected name, for example, "staff". If null, name is ignored.
param
isAbsolute if Boolean.TRUE, URI must be absolute. Null indicates no assertion.
param
actual URI to be tested.

    //
    //  URI must be non-null
    assertNotNull(assertID, actual);

    String uri = actual;

    int lastPound = actual.lastIndexOf("#");
    String actualFragment = "";
    if (lastPound != -1) {
      //
      //   substring before pound
      //
      uri = actual.substring(0, lastPound);
      actualFragment = actual.substring(lastPound + 1);
    }
    if (fragment != null) {
      assertEquals(assertID, fragment, actualFragment);

    }
    int lastQuestion = uri.lastIndexOf("?");
    String actualQuery = "";
    if (lastQuestion != -1) {
      //
      //   substring before pound
      //
      uri = actual.substring(0, lastQuestion);
      actualQuery = actual.substring(lastQuestion + 1);
    }
    if (query != null) {
      assertEquals(assertID, query, actualQuery);

    }
    int firstColon = uri.indexOf(":");
    int firstSlash = uri.indexOf("/");
    String actualPath = uri;
    String actualScheme = "";
    if (firstColon != -1 && firstColon < firstSlash) {
      actualScheme = uri.substring(0, firstColon);
      actualPath = uri.substring(firstColon + 1);
    }

    if (scheme != null) {
      assertEquals(assertID, scheme, actualScheme);
    }

    if (path != null) {
      assertEquals(assertID, path, actualPath);
    }

    if (host != null) {
      String actualHost = "";
      if (actualPath.startsWith("//")) {
        int termSlash = actualPath.indexOf("/", 2);
        actualHost = actualPath.substring(0, termSlash);
      }
      assertEquals(assertID, host, actualHost);
    }

    String actualFile = actualPath;
    if (file != null || name != null) {
      int finalSlash = actualPath.lastIndexOf("/");
      if (finalSlash != -1) {
        actualFile = actualPath.substring(finalSlash + 1);
      }
      if (file != null) {
        assertEquals(assertID, file, actualFile);
      }
    }

    if (name != null) {
      String actualName = actualFile;
      int finalPeriod = actualFile.lastIndexOf(".");
      if (finalPeriod != -1) {
        actualName = actualFile.substring(0, finalPeriod);
      }
      assertEquals(assertID, name, actualName);
    }

    if (isAbsolute != null) {
      //
      //   Jar URL's will have any actual path like file:/c:/somedrive...
      assertEquals(
          assertID,
          isAbsolute.booleanValue(),
          actualPath.startsWith("/") || actualPath.startsWith("file:/"));
    }
  
public static voiddoMain(java.lang.Class testClass, java.lang.String[] args)
This method is called by the main() for each test and locates the appropriate test framework and runs the specified test

param
testClass test class
param
args arguments to test class

    //
    //   Attempt to load JUnitRunner
    //
    ClassLoader loader = ClassLoader.getSystemClassLoader();
    try {
      Class runnerClass = loader.loadClass("org.w3c.domts.JUnitRunner");
      Constructor runnerFactory =
          runnerClass.getConstructor(new Class[] {Class.class});
      //
      //   create the JUnitRunner
      //
      Object junitRun =
          runnerFactory.newInstance(new Object[] {testClass});
      //
      //   find and call its execute method method
      //
      Class argsClass = loader.loadClass("[Ljava.lang.String;");
      Method execMethod =
          runnerClass.getMethod("execute", new Class[] {argsClass});
      execMethod.invoke(junitRun, new Object[] {args});
    }
    catch (InvocationTargetException ex) {
      ex.getTargetException().printStackTrace();
    }
    catch (Exception ex) {
      System.out.println(
          "junit-run.jar and junit.jar \n must be in same directory or on classpath.");
      ex.printStackTrace();
    }
  
public booleanequals(java.lang.String expected, java.lang.String actual)
Compares the values of actual and expected.

param
expected expected
param
actual actual
return
true if actual and expected are equal.

    return framework.equals(expected, actual);
  
public booleanequals(int expected, int actual)
Compares the values of actual and expected.

param
expected expected
param
actual actual
return
true if actual and expected are equal.

    return framework.equals(expected, actual);
  
public booleanequals(double expected, double actual)
Compares the values of actual and expected.

param
expected expected
param
actual actual
return
true if actual and expected are equal.

    return framework.equals(expected, actual);
  
public booleanequals(java.util.Collection expected, java.util.Collection actual)
Compares the values in actual and expected ignoring order.

param
expected expected
param
actual actual
return
true if actual and expected are equal.

    return framework.equals(expected, actual);
  
public booleanequals(java.util.List expected, java.util.List actual)
Compares the values in actual and expected.

param
expected expected
param
actual actual
return
true if actual and expected are equal.

    return framework.equals(expected, actual);
  
public booleanequalsAutoCase(java.lang.String context, java.lang.String expected, java.lang.String actual)
Compares the value of actual and expected ignoring case.

param
expected expected
param
actual actual
return
true if actual and expected are equal ignoring case.

    if ("text/html".equals(getContentType())) {
      if ("attribute".equals(context)) {
        return framework.equalsIgnoreCase(expected, actual);
      }
      else {
        return framework.equals(expected.toUpperCase(), actual);
      }
    }
    return framework.equals(expected, actual);
  
public booleanequalsAutoCase(java.lang.String context, java.util.Collection expected, java.util.Collection actual)
Compares the values in actual and expected ignoring case and order.

param
expected expected
param
actual actual
return
true if actual and expected are equal ignoring case.

    if ("text/html".equals(getContentType())) {
      if ("attribute".equals(context)) {
        return framework.equalsIgnoreCase(expected, actual);
      }
      else {
        return framework.equals(toUpperCase(expected), actual);
      }
    }
    return framework.equals(expected, actual);
  
public booleanequalsAutoCase(java.lang.String context, java.util.List expected, java.util.List actual)
Compares the values in actual and expected ignoring case.

param
expected expected
param
actual actual
return
true if actual and expected are equal ignoring case.

    if ("text/html".equals(getContentType())) {
      if ("attribute".equals(context)) {
        return framework.equalsIgnoreCase(expected, actual);
      }
      else {
        return framework.equals(toUpperCase(expected), actual);
      }
    }
    return framework.equals(expected, actual);
  
public booleanequalsIgnoreCase(java.lang.String expected, java.lang.String actual)
Compares the value of actual and expected ignoring case.

param
expected expected
param
actual actual
return
true if actual and expected are equal ignoring case.

    return framework.equalsIgnoreCase(expected, actual);
  
public booleanequalsIgnoreCase(java.util.Collection expected, java.util.Collection actual)
Compares the values in actual and expected ignoring case and order.

param
expected expected
param
actual actual
return
true if actual and expected are equal ignoring case.

    return framework.equalsIgnoreCase(expected, actual);
  
public booleanequalsIgnoreCase(java.util.List expected, java.util.List actual)
Compares the values in actual and expected ignoring case.

param
expected expected
param
actual actual
return
true if actual and expected are equal ignoring case.

    return framework.equalsIgnoreCase(expected, actual);
  
public voidfail(java.lang.String assertID)
Fail test

param
assertID identifier of assertion

    framework.fail(this, assertID);
  
public abstract voidrunTest()
Body of test

throws
Throwable

public booleansame(java.lang.Object expected, java.lang.Object actual)
Compares the identity of actual and expected.

param
expected expected
param
actual actual
return
true if actual and expected are the same object.

    return framework.same(expected, actual);
  
public voidsetFramework(DOMTestFramework framework)
Sets test framework to be used by test.

param
framework

    this.framework = framework;
  
public intsize(java.util.Collection collection)
Gets the size of the collection

param
collection collection, may not be null.
return
size of collection

    return framework.size(collection);
  
public intsize(org.w3c.dom.NamedNodeMap collection)
Gets the size of the collection

param
collection collection, may not be null.
return
size of collection

    return framework.size(collection);
  
public intsize(org.w3c.dom.NodeList collection)
Gets the size of the collection

param
collection collection, may not be null.
return
size of collection

    return framework.size(collection);
  
private java.util.ListtoUpperCase(java.util.Collection expected)
Creates an equivalent list where every member has been uppercased

    List upperd = new ArrayList(expected.size());
    Iterator iter = expected.iterator();
    while (iter.hasNext()) {
      upperd.add(iter.next().toString().toUpperCase());
    }
    return upperd;
  
public voidwait(int millisecond)
Wait

param
millisecond milliseconds to wait

    framework.wait(millisecond);