Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
2.9.1
-
None
-
Windows, Junit
Description
When we do JUnit tests for Schema 1.1, assertions on derived simple type definitions as following will cause failures for other test cases.
For example.
<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="baseType">
<xs:restriction base="xs:string">
<xs:maxLength value="25"/>
<xs:assertion test="ends-with($value, 'xyz')"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="derivedType">
<xs:restriction base="baseType">
<xs:assertion test="string-length($value) gt 3 "/>
</xs:restriction>
</xs:simpleType>
<xs:element name="root" type="derivedType" />
</xs:schema>
The reason is that we put fschemaFactory into the schemafactory pool for the first two test cases (one DOM and one SAX), then for other test cases, we just reuse the schemafactory stored in the pool. When we have above schema which contains a base type including a assertion, we use a global vector "private Vector baseAsserts = new Vector();" to hold all the asserts up in the type hierarchy. We should clear up this vector after validating each test case.
There are two options to fix it .
@version $Id: XSDAbstractTraverser.java 912155 2010-02-20 17:20:39Z mrglavas $
1. clear it up in the reset method:
void reset(SymbolTable symbolTable, boolean validateAnnotations, Locale locale)
{ baseAsserts.clear(); // clear vector baseAsserts fSymbolTable = symbolTable; fValidateAnnotations = validateAnnotations; fValidationState.setExtraChecking(false); fValidationState.setSymbolTable(symbolTable); fValidationState.setLocale(locale); fValidationState.setTypeValidatorHelper(fSchemaHandler.fTypeValidatorHelper); }2. clear it up every time after we use it.
// retrieve all assert definitions from all base types all the way up in the
// type hierarchy. sets a global variable, 'baseAsserts' with all the base
// asserts.
if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
getAssertsFromBaseTypes(baseValidator);
// add all base assertions to the list of assertions to be processed
if (baseAsserts.size() > 0) {
if (assertData == null)
assertData.addAll(baseAsserts);
baseAsserts.clear(); // clear vector baseAsserts
}
}