org.newsml.toolkit.conformance
Class TestBase

java.lang.Object
  |
  +--org.newsml.toolkit.conformance.TestBase
Direct Known Subclasses:
CatalogTest, ContentItemTest, DateTimeTest, DefaultVocabularyForTest, EuidTest, FormalNameTest, NewsComponentTest, NewsIdentifierTest, NewsItemTest, NewsLineTest, PatternTest, PropertyTest, RefTest, ResourceTest, RevisionIdTest, RevisionStatusTest, TopicSetTest, TopicTest, TopicUseTest, XMLLangTest

public abstract class TestBase
extends Object

Abstract base class for all NewsML conformance tests.

This class provides some convenience methods for reporting errors and warnings. Subclasses must implement the run(org.newsml.toolkit.BaseNode, boolean) method to run the actual tests.

Version:
2.0
Author:
Reuters PLC
See Also:
NewsMLTestManager

Constructor Summary
TestBase()
           
 
Method Summary
static void error(String message)
          Report an error.
static void internal(String message)
          Report an internal error (shouldn't happen).
abstract  void run(BaseNode contextNode, boolean useExternal)
          Run tests.
static void warning(String message)
          Report a warning.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestBase

public TestBase()
Method Detail

run

public abstract void run(BaseNode contextNode,
                         boolean useExternal)
                  throws NewsMLException
Run tests.

All NewsML conformance tests must implement this method. The test will receive the node to test (one of the nodes matching the XPath expression provided to NewsMLTestManager.addTest(java.lang.String, org.newsml.toolkit.conformance.TestBase)) and a flag indicating whether the test is allowed to reference resources outside the current NewsML document (such as URL references).

To report an error or warning, the test must throw an exception: it can use a ConformanceWarning to report a warning, or any other NewsMLException to report an error; either of these may be wrapping another exception of some kind. Since the test uses exceptions, only the first error or warning it finds will be reported. The test may also throw a java.lang.ClassCastException if the node is not of the expected type: this exception will flow right up to the client application, since it should only happen when there is a design flaw in the client.

The NewsMLTestManager will catch the exceptions and pass them on to the client application through the ErrorVisitor interface provided by the client.

Parameters:
contextNode - The NewsML BaseNode to test. The test may case it to the appropriate type.
useExternal - true if the test is allowed to reference resources outside the NewsML document.
Throws:
ConformanceWarning - if the test reports a warning.
NewsMLException - if the test reports an error.

warning

public static void warning(String message)
                    throws ConformanceWarning
Report a warning.

The client application can also simply throw a ConformanceWarning direction.

Parameters:
message - The warning message.
Throws:
ConformanceWarning - always thrown.

error

public static void error(String message)
                  throws NewsMLException
Report an error.

The client application can also simply throw a NewsMLException direction.

Parameters:
message - The error message.
Throws:
NewsMLException - always thrown.

internal

public static void internal(String message)
                     throws RuntimeException
Report an internal error (shouldn't happen).

The client application can also simply throw a RuntimeException directly.

Parameters:
message - The internal error message.
Throws:
RuntimeException - always thrown.