org.w3c.mwi.mobileok.basic
Class Tester

java.lang.Object
  extended by org.w3c.mwi.mobileok.basic.Tester

public final class Tester
extends java.lang.Object

Runs tests on an HTTP(S) resource identified by its URI.

An instance of the Tester class is bound to a Web resource when it is first instanciated. The runTests() method can then be used to run the tests, and retrieve the final mobileOK report as an instance of the TestResults class.

The internal moki representation of the Web resource under test can also be retrieved through the getPreprocessorResults() method.

The class also defines the static main(String[]) entry-point method, triggered when the mobileOK Checker library is used as a stand-alone program and run from the command-line.

NB: the mobileOK Checker only supports the HTTP and HTTPS URI schemes. The mobileOK Checker will return an HTTPErrorsType.HTTP_RESPONSE_1 error message when run on a URI with a different scheme.

Sample usage as a library:
import org.w3c.mwi.mobileok.basic;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
javax.xml.transform.dom.DOMSource;

Tester tester = new Tester(new URI("http://example.org"));
TestResults results = tester.runTests();

TransformerFactory tFactory = TransformerFactory.newInstance();
StreamResult result = new StreamResult(System.out);
tFactory.newTransformer().transform(new DOMSource(results.getIntermediateResultsDOM()), result);
tFactory.newTransformer().transform(new DOMSource(results.getTestResultsDOM()), result);

Command-line usage when standalone:
Tester [options] URI
 -m <arg> moki filename
 -p <arg> proxyHost:proxyPort
 -pass <arg> user password
 -r <arg> result filename
 -user <arg> user name

The version of the mobileOK Checker Java Library maintained by the W3C mobileOK Checker Task Force is a reference implementation of the W3C mobileOK Basic Tests 1.0 W3C standard, which means that it implements all the mobileOK tests formally defined in the document and only them. It may be used to claim that a Web resource is mobileOK.

Version:
$Revision: 1.2 $
Author:
The W3C mobileOK Checker Task Force
See Also:
TestResults, PreprocessorResults

Field Summary
private  Preprocessor preprocessor
          Preprocessor used to build the intermediary moki representation of the resource under test.
 
Constructor Summary
private Tester(java.io.File file)
          Creates a class instance bound to a file.
  Tester(java.net.URI uri)
          Creates a class instance bound to a URI.
 
Method Summary
private static java.net.URI fileToURI(java.io.File file)
          Returns the file URI of the given file.
 PreprocessorResults getPreprocessorResults()
          Returns the intermediate moki representation of the resource bound to this instance.
static void main(java.lang.String... args)
          Main entry-point of the mobileOK Checker library when the library is used as a stand-alone application.
 TestResults runTests()
          Runs all defined tests on the URI bound to this instance.
 TestResults runTests(java.util.List<TestImplementation> tests)
          Runs a precise list of tests on the URI bound to this instance.
private static void usage(org.apache.commons.cli.Options options)
          Helper static method that prints the list of options that may be set to run the mobileOK Checker from the command-line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

preprocessor

private final Preprocessor preprocessor
Preprocessor used to build the intermediary moki representation of the resource under test.

Constructor Detail

Tester

public Tester(java.net.URI uri)
Creates a class instance bound to a URI.

The mobileOK Checker only supports the HTTP and HTTPS URI schemes. Instanciation won't fail if the URI uses another scheme, but the Checker won't be able to retrieve the resource and will return an HTTPErrorsType.HTTP_RESPONSE_1 error message.

Parameters:
uri - URI of the HTTP(S) that needs to be checked.

Tester

private Tester(java.io.File file)
Creates a class instance bound to a file.

There is actually no support for the file scheme within the mobileOK Checker. This constructor is thus more of a placeholder for a potential future feature of the mobileOK Checker.

The constructor is flagged as private in the meantime not to create confusion of false expectations.

Parameters:
file - file resource that needs to be checked.
Method Detail

fileToURI

private static java.net.URI fileToURI(java.io.File file)
Returns the file URI of the given file.

Parameters:
file - file whose URI needs to be extracted.
See Also:
Tester(File)

getPreprocessorResults

public PreprocessorResults getPreprocessorResults()
                                           throws TestException
Returns the intermediate moki representation of the resource bound to this instance.

If not already done, the moki representation is created, which means that the first call to this method may take a lot of time, and/or fail.

The TesterConfiguration that needs to be used to build the moki representation of the resource must be set prior to calling this method.

Returns:
the moki representation of the resource.
Throws:
TestException - an unexpected error occurred while creating the intermediate moki representation of the resource, or the TesterConfiguration instance has not been set through a call to TesterConfiguration.setConfiguration(TesterConfiguration).

runTests

public TestResults runTests()
                     throws TestException
Runs all defined tests on the URI bound to this instance.

Creates the intermediate moki representation of the resource if not already done through a call to getPreprocessorResults().

The TesterConfiguration that needs to be used to build the moki representation of the resource must be set prior to calling this method.

Returns:
a report that contains the outcomes of all the tests run on the resource.
Throws:
TestException - an unexpected error occurred while creating the intermediate moki representation of the resource, or the TesterConfiguration instance has not been set through a call to TesterConfiguration.setConfiguration(TesterConfiguration).

runTests

public TestResults runTests(java.util.List<TestImplementation> tests)
                     throws TestException
Runs a precise list of tests on the URI bound to this instance.

The intermediate moki representation of the resource is available through a call to getPreprocessorResults().

Parameters:
tests - the list of tests to run
Returns:
a report that contains the outcomes of all the tests run on the resource.
Throws:
TestException - an unexpected error occurred or the tester configuration is missing.

main

public static void main(java.lang.String... args)
                 throws java.lang.Exception
Main entry-point of the mobileOK Checker library when the library is used as a stand-alone application.

The method extracts the arguments from the command-line, runs the Checker on the given URI and returns the intermediary moki representation of the URI and the final report as XML streams (either to the standard output or to some given file).

Command-line usage:
Tester [options] URI
 -m <arg> moki filename
 -p <arg> proxyHost:proxyPort
 -pass <arg> user password
 -r <arg> result filename
 -user <arg> user name

Throws:
java.lang.Exception - an unexpected error occurred.

usage

private static void usage(org.apache.commons.cli.Options options)
Helper static method that prints the list of options that may be set to run the mobileOK Checker from the command-line.

Parameters:
options - the list of command-line options to print.