Package org.apache.batik.test.svg
Class SVGOnLoadExceptionTest
- java.lang.Object
-
- org.apache.batik.test.AbstractTest
-
- org.apache.batik.test.svg.SVGOnLoadExceptionTest
-
- All Implemented Interfaces:
Test
public class SVGOnLoadExceptionTest extends AbstractTest
This test takes an SVG file as an input. It processes the input SVG (meaning it turns it into a GVT tree) and then dispatches the 'onload' event. In that process, the test checks for the occurence of a specific exception type and, for BridgeExceptions, for a given error code. If an exception of the given type (and, optionally, code) happens, then the test passes. If an exception of an unexpected type (or code, for BridgeExceptions) happens, or if no exception happens, the test fails. The following properties control the test's operation: - Scripts: list of allowed script types (e.g., "application/java-archive") - ScriptOrigin: "ANY", "DOCUMENT", "EMBEDED", "NONE" - ResourceOrigin: "ANY", "DOCUMENT", "EMBEDED", "NONE" - ExpectedExceptionClass (e.g., "java.lang.SecurityException") - ExpectedErrorCode (e.g., "err.uri.unsecure") - Validate (e.g., "true")- Version:
- $Id: SVGOnLoadExceptionTest.java 1831626 2018-05-15 11:10:36Z ssteiner $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
SVGOnLoadExceptionTest.TestUserAgent
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ENTRY_KEY_EXPECTED_ERROR_CODE
Entry describign the expected error codestatic java.lang.String
ENTRY_KEY_EXPECTED_EXCEPTION
Entry describing the expected exceptionstatic java.lang.String
ENTRY_KEY_UNEXPECTED_ERROR_CODE
Entry describing the unexpected error codestatic java.lang.String
ENTRY_KEY_UNEXPECTED_EXCEPTION
Entry describing the unexpected exceptionstatic java.lang.String
ENTRY_KEY_UNEXPECTED_RESULT
Entry describing the unexpected exceptionstatic java.lang.String
ERROR_CODE_NO_CHECK
Value used to disable error code check on BridgeExceptionsstatic java.lang.String
ERROR_EXCEPTION_DID_NOT_OCCUR
Error when the expected exception did not occurstatic java.lang.String
ERROR_SCRIPT_DID_NOT_RUN
Error when the script does not run as expected.static java.lang.String
ERROR_UNEXPECTED_ERROR_CODE
Error when a BridgeException occured, as expected, but with an unexpected error codestatic java.lang.String
ERROR_UNEXPECTED_EXCEPTION
Error when an exception occured, but not of the expected classprotected java.lang.String
expectedErrorCode
Expected error code (for BridgeExceptions)protected java.lang.String
expectedExceptionClass
Name of the expected exception classprotected java.lang.String
fileName
The name of the test filestatic java.lang.String
RAN
Value for the script having successfully run.protected java.lang.String
resourceOrigin
The allowed external resource originprotected boolean
restricted
Controls whether on not the document should be processed from a 'restricted' context, one with no createClassLoader permission.protected java.lang.String
scriptOrigin
The allowed script originprotected java.lang.String
scripts
The allowed script typesprotected boolean
secure
True if the scripts are run securely (i.e., with a security manager)protected java.lang.String
svgURL
The URL for the input SVG document to be testedstatic java.lang.String
testNS
Test Namespaceprotected java.lang.Boolean
validate
Controls whether or not the input SVG document should be validated-
Fields inherited from class org.apache.batik.test.AbstractTest
id, name, parent
-
-
Constructor Summary
Constructors Constructor Description SVGOnLoadExceptionTest()
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SVGOnLoadExceptionTest.TestUserAgent
buildUserAgent()
Give subclasses a chance to build their own UserAgentjava.lang.String
getExpectedErrorCode()
java.lang.String
getExpectedExceptionClass()
java.lang.String
getResourceOrigin()
boolean
getRestricted()
java.lang.String
getScriptOrigin()
java.lang.String
getScripts()
boolean
getSecure()
java.lang.Boolean
getValidate()
protected TestReport
handleException(java.lang.Exception e)
Compares the input exception with the expected exception If they match, then the test passes.protected boolean
isMatch(java.lang.Class cl, java.lang.String name)
Check if the input class' name (or one of its base classes) matches the input name.protected java.lang.String
resolveURL(java.lang.String url)
Resolves the input string as follows.TestReport
runImpl()
Run this test and produce a report.void
setExpectedErrorCode(java.lang.String expectedErrorCode)
void
setExpectedExceptionClass(java.lang.String expectedExceptionClass)
void
setId(java.lang.String id)
Set thisTest
's id.void
setResourceOrigin(java.lang.String resourceOrigin)
void
setRestricted(boolean restricted)
void
setScriptOrigin(java.lang.String scriptOrigin)
void
setScripts(java.lang.String scripts)
void
setSecure(boolean secure)
void
setValidate(java.lang.Boolean validate)
protected TestReport
testImpl()
Implementation helper-
Methods inherited from class org.apache.batik.test.AbstractTest
assertEquals, assertEquals, assertNull, assertTrue, error, getId, getName, getParent, getQualifiedId, reportError, reportException, reportSuccess, run, runImplBasic, setName, setParent
-
-
-
-
Field Detail
-
RAN
public static final java.lang.String RAN
Value for the script having successfully run.- See Also:
- Constant Field Values
-
ERROR_EXCEPTION_DID_NOT_OCCUR
public static final java.lang.String ERROR_EXCEPTION_DID_NOT_OCCUR
Error when the expected exception did not occur- See Also:
- Constant Field Values
-
ERROR_UNEXPECTED_EXCEPTION
public static final java.lang.String ERROR_UNEXPECTED_EXCEPTION
Error when an exception occured, but not of the expected class- See Also:
- Constant Field Values
-
ERROR_UNEXPECTED_ERROR_CODE
public static final java.lang.String ERROR_UNEXPECTED_ERROR_CODE
Error when a BridgeException occured, as expected, but with an unexpected error code- See Also:
- Constant Field Values
-
ERROR_SCRIPT_DID_NOT_RUN
public static final java.lang.String ERROR_SCRIPT_DID_NOT_RUN
Error when the script does not run as expected.- See Also:
- Constant Field Values
-
ENTRY_KEY_UNEXPECTED_EXCEPTION
public static final java.lang.String ENTRY_KEY_UNEXPECTED_EXCEPTION
Entry describing the unexpected exception- See Also:
- Constant Field Values
-
ENTRY_KEY_UNEXPECTED_ERROR_CODE
public static final java.lang.String ENTRY_KEY_UNEXPECTED_ERROR_CODE
Entry describing the unexpected error code- See Also:
- Constant Field Values
-
ENTRY_KEY_EXPECTED_ERROR_CODE
public static final java.lang.String ENTRY_KEY_EXPECTED_ERROR_CODE
Entry describign the expected error code- See Also:
- Constant Field Values
-
ENTRY_KEY_EXPECTED_EXCEPTION
public static final java.lang.String ENTRY_KEY_EXPECTED_EXCEPTION
Entry describing the expected exception- See Also:
- Constant Field Values
-
ENTRY_KEY_UNEXPECTED_RESULT
public static final java.lang.String ENTRY_KEY_UNEXPECTED_RESULT
Entry describing the unexpected exception- See Also:
- Constant Field Values
-
ERROR_CODE_NO_CHECK
public static final java.lang.String ERROR_CODE_NO_CHECK
Value used to disable error code check on BridgeExceptions- See Also:
- Constant Field Values
-
testNS
public static final java.lang.String testNS
Test Namespace- See Also:
- Constant Field Values
-
svgURL
protected java.lang.String svgURL
The URL for the input SVG document to be tested
-
scripts
protected java.lang.String scripts
The allowed script types
-
expectedExceptionClass
protected java.lang.String expectedExceptionClass
Name of the expected exception class
-
expectedErrorCode
protected java.lang.String expectedErrorCode
Expected error code (for BridgeExceptions)
-
scriptOrigin
protected java.lang.String scriptOrigin
The allowed script origin
-
resourceOrigin
protected java.lang.String resourceOrigin
The allowed external resource origin
-
secure
protected boolean secure
True if the scripts are run securely (i.e., with a security manager)
-
validate
protected java.lang.Boolean validate
Controls whether or not the input SVG document should be validated
-
fileName
protected java.lang.String fileName
The name of the test file
-
restricted
protected boolean restricted
Controls whether on not the document should be processed from a 'restricted' context, one with no createClassLoader permission.
-
-
Method Detail
-
getRestricted
public boolean getRestricted()
-
setRestricted
public void setRestricted(boolean restricted)
-
setScripts
public void setScripts(java.lang.String scripts)
-
getScripts
public java.lang.String getScripts()
-
setScriptOrigin
public void setScriptOrigin(java.lang.String scriptOrigin)
-
getScriptOrigin
public java.lang.String getScriptOrigin()
-
setResourceOrigin
public void setResourceOrigin(java.lang.String resourceOrigin)
-
getResourceOrigin
public java.lang.String getResourceOrigin()
-
setSecure
public void setSecure(boolean secure)
-
getSecure
public boolean getSecure()
-
setExpectedExceptionClass
public void setExpectedExceptionClass(java.lang.String expectedExceptionClass)
-
getExpectedExceptionClass
public java.lang.String getExpectedExceptionClass()
-
setExpectedErrorCode
public void setExpectedErrorCode(java.lang.String expectedErrorCode)
-
getExpectedErrorCode
public java.lang.String getExpectedErrorCode()
-
getValidate
public java.lang.Boolean getValidate()
-
setValidate
public void setValidate(java.lang.Boolean validate)
-
setId
public void setId(java.lang.String id)
Description copied from class:AbstractTest
Set thisTest
's id. Null is not allowed.- Specified by:
setId
in interfaceTest
- Overrides:
setId
in classAbstractTest
-
resolveURL
protected java.lang.String resolveURL(java.lang.String url)
Resolves the input string as follows. + First, the string is interpreted as a file description. If the file exists, then the file name is turned into a URL. + Otherwise, the string is supposed to be a URL. If it is an invalid URL, an IllegalArgumentException is thrown.
-
runImpl
public TestReport runImpl() throws java.lang.Exception
Run this test and produce a report. The test goes through the following steps:- load the input SVG into a Document
- build the GVT tree corresponding to the Document and dispatch the 'onload' event
- Overrides:
runImpl
in classAbstractTest
- Throws:
java.lang.Exception
-
testImpl
protected TestReport testImpl()
Implementation helper
-
handleException
protected TestReport handleException(java.lang.Exception e)
Compares the input exception with the expected exception If they match, then the test passes. Otherwise, the test fails
-
isMatch
protected boolean isMatch(java.lang.Class cl, java.lang.String name)
Check if the input class' name (or one of its base classes) matches the input name.
-
buildUserAgent
protected SVGOnLoadExceptionTest.TestUserAgent buildUserAgent()
Give subclasses a chance to build their own UserAgent
-
-