You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2006/01/24 20:07:33 UTC
svn commit: r371982 [1/2] - /xerces/java/trunk/tests/schema/config/
Author: mrglavas
Date: Tue Jan 24 11:07:20 2006
New Revision: 371982
URL: http://svn.apache.org/viewcvs?rev=371982&view=rev
Log:
Adding JUnit tests contributed by Peter McCracken for: http://issues.apache.org/jira/browse/XERCESJ-1131.
I've made a few minor modifications (renaming files, packages, etc...) but otherwise it's the same as what
was posted.
Added:
xerces/java/trunk/tests/schema/config/
xerces/java/trunk/tests/schema/config/AllTests.java
xerces/java/trunk/tests/schema/config/BaseTest.java
xerces/java/trunk/tests/schema/config/BasicTest.java
xerces/java/trunk/tests/schema/config/FixedAttrTest.java
xerces/java/trunk/tests/schema/config/IdIdrefCheckingTest.java
xerces/java/trunk/tests/schema/config/IdentityConstraintCheckingTest.java
xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_A_Test.java
xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_C_Test.java
xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_AC_Test.java
xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_A_Test.java
xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_CA_Test.java
xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_C_Test.java
xerces/java/trunk/tests/schema/config/RootTypeDefinitionTest.java
xerces/java/trunk/tests/schema/config/SpecialCaseErrorHandler.java
xerces/java/trunk/tests/schema/config/UnparsedEntityCheckingTest.java
xerces/java/trunk/tests/schema/config/UseGrammarPoolOnly_False_Test.java
xerces/java/trunk/tests/schema/config/UseGrammarPoolOnly_True_Test.java
xerces/java/trunk/tests/schema/config/base.xml
xerces/java/trunk/tests/schema/config/base.xsd
xerces/java/trunk/tests/schema/config/fixedAttr.xml
xerces/java/trunk/tests/schema/config/idIdref.xml
xerces/java/trunk/tests/schema/config/idc.xml
xerces/java/trunk/tests/schema/config/idc.xsd
xerces/java/trunk/tests/schema/config/otherNamespace.xml
xerces/java/trunk/tests/schema/config/otherNamespace.xsd
xerces/java/trunk/tests/schema/config/unparsedEntity.dtd
xerces/java/trunk/tests/schema/config/unparsedEntity.xml
xerces/java/trunk/tests/schema/config/xsitype_A_A.xml
xerces/java/trunk/tests/schema/config/xsitype_A_C.xml
xerces/java/trunk/tests/schema/config/xsitype_C_A.xml
xerces/java/trunk/tests/schema/config/xsitype_C_AC.xml
xerces/java/trunk/tests/schema/config/xsitype_C_C.xml
xerces/java/trunk/tests/schema/config/xsitype_C_CA.xml
Added: xerces/java/trunk/tests/schema/config/AllTests.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/AllTests.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/AllTests.java (added)
+++ xerces/java/trunk/tests/schema/config/AllTests.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Tests for various schema validation configurations.");
+ suite.addTestSuite(BasicTest.class);
+ suite.addTestSuite(RootTypeDefinitionTest.class);
+ suite.addTestSuite(IgnoreXSIType_C_A_Test.class);
+ suite.addTestSuite(IgnoreXSIType_C_C_Test.class);
+ suite.addTestSuite(IgnoreXSIType_A_A_Test.class);
+ suite.addTestSuite(IgnoreXSIType_A_C_Test.class);
+ suite.addTestSuite(IgnoreXSIType_C_AC_Test.class);
+ suite.addTestSuite(IgnoreXSIType_C_CA_Test.class);
+ suite.addTestSuite(IdIdrefCheckingTest.class);
+ suite.addTestSuite(UnparsedEntityCheckingTest.class);
+ suite.addTestSuite(IdentityConstraintCheckingTest.class);
+ suite.addTestSuite(UseGrammarPoolOnly_True_Test.class);
+ suite.addTestSuite(UseGrammarPoolOnly_False_Test.class);
+ suite.addTestSuite(FixedAttrTest.class);
+ return suite;
+ }
+}
Added: xerces/java/trunk/tests/schema/config/BaseTest.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/BaseTest.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/BaseTest.java (added)
+++ xerces/java/trunk/tests/schema/config/BaseTest.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URL;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import junit.framework.TestCase;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.xs.SchemaGrammar;
+import org.apache.xerces.xs.ElementPSVI;
+import org.apache.xerces.xs.ItemPSVI;
+import org.apache.xerces.xs.XSElementDeclaration;
+import org.apache.xerces.xs.XSTypeDefinition;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public abstract class BaseTest extends TestCase {
+ protected final static String ROOT_TYPE = Constants.XERCES_PROPERTY_PREFIX
+ + Constants.ROOT_TYPE_DEFINITION_PROPERTY;
+
+ protected final static String IGNORE_XSI_TYPE = Constants.XERCES_FEATURE_PREFIX
+ + Constants.IGNORE_XSI_TYPE_FEATURE;
+
+ protected final static String ID_IDREF_CHECKING = Constants.XERCES_FEATURE_PREFIX
+ + Constants.ID_IDREF_CHECKING_FEATURE;
+
+ protected final static String IDC_CHECKING = Constants.XERCES_FEATURE_PREFIX
+ + Constants.IDC_CHECKING_FEATURE;
+
+ protected final static String UNPARSED_ENTITY_CHECKING = Constants.XERCES_FEATURE_PREFIX
+ + Constants.UNPARSED_ENTITY_CHECKING_FEATURE;
+
+ protected final static String USE_GRAMMAR_POOL_ONLY = Constants.XERCES_FEATURE_PREFIX
+ + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
+
+ protected final static String DYNAMIC_VALIDATION = Constants.XERCES_FEATURE_PREFIX
+ + Constants.DYNAMIC_VALIDATION_FEATURE;
+
+ protected final static String DOCUMENT_CLASS_NAME = Constants.XERCES_PROPERTY_PREFIX
+ + Constants.DOCUMENT_CLASS_NAME_PROPERTY;
+
+ protected Validator fValidator;
+ protected SpecialCaseErrorHandler fErrorHandler;
+ protected Document fDocument;
+ protected ElementPSVI fRootNode;
+ protected URL fDocumentURL;
+
+ protected abstract String getSchemaFile();
+
+ protected abstract String getXMLDocument();
+
+ public BaseTest(String name) {
+ super(name);
+ fErrorHandler = new SpecialCaseErrorHandler(getRelevantErrorIDs());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory
+ .newInstance();
+ docFactory.setAttribute(DOCUMENT_CLASS_NAME,
+ "org.apache.xerces.dom.PSVIDocumentImpl");
+ docFactory.setNamespaceAware(true);
+ DocumentBuilder builder = docFactory.newDocumentBuilder();
+ // build the location URL of the document
+ String packageDir = this.getClass().getPackage().getName().replace('.',
+ File.separatorChar);
+ String documentPath = packageDir + "/" + getXMLDocument();
+ fDocumentURL = ClassLoader.getSystemResource(documentPath);
+ if (fDocumentURL == null) {
+ throw new FileNotFoundException("Couldn't find xml file for test: " + documentPath);
+ }
+ fDocument = builder.parse(fDocumentURL.toExternalForm());
+ fRootNode = (ElementPSVI) fDocument.getDocumentElement();
+ SchemaFactory sf = SchemaFactory
+ .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ sf.setFeature(USE_GRAMMAR_POOL_ONLY, getUseGrammarPoolOnly());
+ String schemaPath = packageDir + "/" + getSchemaFile();
+ URL schemaURL = ClassLoader.getSystemResource(schemaPath);
+ if (schemaURL == null) {
+ throw new FileNotFoundException("Couldn't find schema file for test: " + schemaPath);
+ }
+ Schema schema = sf.newSchema(schemaURL);
+ fValidator = schema.newValidator();
+ fValidator.setErrorHandler(fErrorHandler);
+ fValidator.setFeature(DYNAMIC_VALIDATION, false);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fValidator = null;
+ fDocument = null;
+ fRootNode = null;
+ fErrorHandler.reset();
+ }
+
+ protected void validateDocument() throws Exception {
+ Source source = new DOMSource(fDocument);
+ source.setSystemId(fDocumentURL.toExternalForm());
+ Result result = new DOMResult(fDocument);
+ fValidator.validate(source, result);
+ }
+
+ protected void validateFragment() throws Exception {
+ Source source = new DOMSource((Node) fRootNode);
+ source.setSystemId(fDocumentURL.toExternalForm());
+ Result result = new DOMResult((Node) fRootNode);
+ fValidator.validate(source, result);
+ }
+
+ protected PSVIElementNSImpl getChild(int n) {
+ int numFound = 0;
+ Node child = ((Node) fRootNode).getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ numFound++;
+ if (numFound == n) {
+ return (PSVIElementNSImpl) child;
+ }
+ }
+ child = child.getNextSibling();
+ }
+ return null;
+ }
+
+ protected String[] getRelevantErrorIDs() {
+ return new String[] {};
+ }
+
+ protected boolean getUseGrammarPoolOnly() {
+ return false;
+ }
+
+ // specialized asserts
+
+ protected void assertValidity(short expectedValidity, short actualValidity) {
+ String expectedString = expectedValidity == ItemPSVI.VALIDITY_VALID ? "valid"
+ : (expectedValidity == ItemPSVI.VALIDITY_INVALID ? "invalid"
+ : "notKnown");
+ String actualString = actualValidity == ItemPSVI.VALIDITY_VALID ? "valid"
+ : (actualValidity == ItemPSVI.VALIDITY_INVALID ? "invalid"
+ : "notKnown");
+ String message = "{validity} was <" + actualString
+ + "> but it should have been <" + expectedString + ">";
+ assertEquals(message, expectedValidity, actualValidity);
+ }
+
+ protected void assertValidationAttempted(short expectedAttempted,
+ short actualAttempted) {
+ String expectedString = expectedAttempted == ItemPSVI.VALIDATION_FULL ? "full"
+ : (expectedAttempted == ItemPSVI.VALIDATION_PARTIAL ? "partial"
+ : "none");
+ String actualString = actualAttempted == ItemPSVI.VALIDATION_FULL ? "full"
+ : (actualAttempted == ItemPSVI.VALIDATION_PARTIAL ? "partial"
+ : "none");
+ String message = "{validity} was <" + actualString
+ + "> but it should have been <" + expectedString + ">";
+ assertEquals(message, expectedAttempted, actualAttempted);
+ }
+
+ protected void assertElementName(String expectedName, String actualName) {
+ assertEquals("Local name of element declaration is wrong.",
+ expectedName, actualName);
+ }
+
+ protected void assertElementNull(XSElementDeclaration elem) {
+ assertNull("Element declaration should be null.", elem);
+ }
+
+ protected void assertElementNamespace(String expectedName, String actualName) {
+ assertEquals("Namespace of element declaration is wrong.",
+ expectedName, actualName);
+ }
+
+ protected void assertElementNamespaceNull(String actualName) {
+ assertNull("Local name of element declaration should be null.",
+ actualName);
+ }
+
+ protected void assertTypeName(String expectedName, String actualName) {
+ assertEquals("Local name of type definition is wrong.", expectedName,
+ actualName);
+ }
+
+ protected void assertTypeNull(XSTypeDefinition type) {
+ assertNull("Type definition should be null.", type);
+ }
+
+ protected void assertTypeNamespace(String expectedName, String actualName) {
+ assertEquals("Namespace of type definition is wrong.", expectedName,
+ actualName);
+ }
+
+ protected void assertTypeNamespaceNull(String actualName) {
+ assertNull("Namespace of type definition should be null.", actualName);
+ }
+
+ protected void assertError(String error) {
+ assertTrue("Error <" + error + "> should have occured, but did not.",
+ fErrorHandler.specialCaseFound(error));
+ }
+
+ protected void assertNoError(String error) {
+ assertFalse("Error <" + error
+ + "> should not have occured (but it did)", fErrorHandler
+ .specialCaseFound(error));
+ }
+
+ protected void assertAnyType(XSTypeDefinition type) {
+ assertEquals("Type is supposed to be anyType", SchemaGrammar.fAnyType,
+ type);
+ }
+}
Added: xerces/java/trunk/tests/schema/config/BasicTest.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/BasicTest.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/BasicTest.java (added)
+++ xerces/java/trunk/tests/schema/config/BasicTest.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class BasicTest extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(BasicTest.class);
+ }
+
+ protected String getXMLDocument() {
+ return "base.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public BasicTest(String name) {
+ super(name);
+ }
+
+ public void testSimpleValidation() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+ doValidityAsserts();
+ }
+
+ public void testSimpleValidationWithTrivialXSIType() {
+ ((PSVIElementNSImpl) fRootNode).setAttributeNS(
+ "http://www.w3.org/2001/XMLSchema-instance", "type", "X");
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+ doValidityAsserts();
+ }
+
+ private void doValidityAsserts() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+ assertElementNamespaceNull(fRootNode.getElementDeclaration()
+ .getNamespace());
+ assertTypeName("X", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+ }
+}
Added: xerces/java/trunk/tests/schema/config/FixedAttrTest.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/FixedAttrTest.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/FixedAttrTest.java (added)
+++ xerces/java/trunk/tests/schema/config/FixedAttrTest.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+
+/**
+ * The purpose of this test is to execute all of the isComparable calls in
+ * XMLSchemaValidator. There are two calls in processElementContent and two
+ * calls in processOneAttribute.
+ *
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class FixedAttrTest extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(FixedAttrTest.class);
+ }
+
+ protected String getXMLDocument() {
+ return "fixedAttr.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public FixedAttrTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testDefault() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("B", child.getElementDeclaration().getName());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("D", child.getElementDeclaration().getName());
+ }
+}
Added: xerces/java/trunk/tests/schema/config/IdIdrefCheckingTest.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IdIdrefCheckingTest.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IdIdrefCheckingTest.java (added)
+++ xerces/java/trunk/tests/schema/config/IdIdrefCheckingTest.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+//duplicate IDs
+//reference to non-existent ID
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IdIdrefCheckingTest extends BaseTest {
+ public static final String DUPLICATE_ID = "cvc-id.2";
+
+ public static final String NO_ID_BINDING = "cvc-id.1";
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IdIdrefCheckingTest.class);
+ }
+
+ protected String getXMLDocument() {
+ return "idIdref.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ protected String[] getRelevantErrorIDs() {
+ return new String[] { DUPLICATE_ID, NO_ID_BINDING };
+ }
+
+ public IdIdrefCheckingTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testDefault() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkDefault();
+ }
+
+ public void testSetFalse() {
+ try {
+ fValidator.setFeature(ID_IDREF_CHECKING, false);
+ } catch (SAXException e) {
+ Assert.fail("Error setting feature.");
+ }
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkValidResult();
+ }
+
+ public void testSetTrue() {
+ try {
+ fValidator.setFeature(ID_IDREF_CHECKING, true);
+ } catch (SAXException e) {
+ Assert.fail("Error setting feature.");
+ }
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkDefault();
+ }
+
+ private void checkDefault() {
+ assertError(DUPLICATE_ID);
+ assertError(NO_ID_BINDING);
+
+ assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+ assertTypeName("X", fRootNode.getTypeDefinition().getName());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("idType", child.getTypeDefinition().getName());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("idType", child.getTypeDefinition().getName());
+
+ child = super.getChild(3);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("idrefType", child.getTypeDefinition().getName());
+ }
+
+ private void checkValidResult() {
+ assertNoError(DUPLICATE_ID);
+ assertNoError(NO_ID_BINDING);
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+ assertTypeName("X", fRootNode.getTypeDefinition().getName());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("idType", child.getTypeDefinition().getName());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("idType", child.getTypeDefinition().getName());
+
+ child = super.getChild(3);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("idrefType", child.getTypeDefinition().getName());
+ }
+}
Added: xerces/java/trunk/tests/schema/config/IdentityConstraintCheckingTest.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IdentityConstraintCheckingTest.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IdentityConstraintCheckingTest.java (added)
+++ xerces/java/trunk/tests/schema/config/IdentityConstraintCheckingTest.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IdentityConstraintCheckingTest extends BaseTest {
+ // These values are unstable, since they're not actually error keys, but
+ // simply
+ // the first part of the error message.
+ public static final String DUPLICATE_UNIQUE = "cvc-identity-constraint.4.1";
+
+ public static final String DUPLICATE_KEY = "cvc-identity-constraint.4.2.2";
+
+ public static final String INVALID_KEYREF = "cvc-identity-constraint.4.3";
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IdentityConstraintCheckingTest.class);
+ }
+
+ protected String getXMLDocument() {
+ return "idc.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "idc.xsd";
+ }
+
+ protected String[] getRelevantErrorIDs() {
+ return new String[] { DUPLICATE_UNIQUE, DUPLICATE_KEY, INVALID_KEYREF };
+ }
+
+ public IdentityConstraintCheckingTest(String name) {
+ super(name);
+ }
+
+ public void testDefault() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkDefault();
+ }
+
+ public void testSetFalse() {
+ try {
+ fValidator.setFeature(IDC_CHECKING, false);
+ } catch (SAXException e) {
+ Assert.fail("Error setting feature.");
+ }
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkValidResult();
+ }
+
+ public void testSetTrue() {
+ try {
+ fValidator.setFeature(IDC_CHECKING, true);
+ } catch (SAXException e) {
+ Assert.fail("Error setting feature.");
+ }
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkDefault();
+ }
+
+ private void checkDefault() {
+ assertError(DUPLICATE_UNIQUE);
+ assertError(DUPLICATE_KEY);
+ assertError(INVALID_KEYREF);
+
+ assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("itemList", fRootNode.getElementDeclaration()
+ .getName());
+ assertTypeName("itemListType", fRootNode.getTypeDefinition().getName());
+
+ // this one is valid because it's the first one to define the unique
+ // value
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("item", child.getElementDeclaration().getName());
+ assertTypeName("itemType", child.getTypeDefinition().getName());
+
+ // invalid because it repeats the unique value
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("item", child.getElementDeclaration().getName());
+ assertTypeName("itemType", child.getTypeDefinition().getName());
+
+ // invalid because it repeats the key
+ child = super.getChild(3);
+ assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("item", child.getElementDeclaration().getName());
+ assertTypeName("itemType", child.getTypeDefinition().getName());
+
+ // valid because key references aren't figured out until the validation
+ // root
+ child = super.getChild(4);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("itemRef", child.getElementDeclaration().getName());
+ assertTypeName("string", child.getTypeDefinition().getName());
+ }
+
+ private void checkValidResult() {
+ assertNoError(DUPLICATE_UNIQUE);
+ assertNoError(DUPLICATE_KEY);
+ assertNoError(INVALID_KEYREF);
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("itemList", fRootNode.getElementDeclaration()
+ .getName());
+ assertTypeName("itemListType", fRootNode.getTypeDefinition().getName());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("item", child.getElementDeclaration().getName());
+ assertTypeName("itemType", child.getTypeDefinition().getName());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("item", child.getElementDeclaration().getName());
+ assertTypeName("itemType", child.getTypeDefinition().getName());
+
+ child = super.getChild(3);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("item", child.getElementDeclaration().getName());
+ assertTypeName("itemType", child.getTypeDefinition().getName());
+
+ child = super.getChild(4);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("itemRef", child.getElementDeclaration().getName());
+ assertTypeName("string", child.getTypeDefinition().getName());
+ }
+}
Added: xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_A_Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_A_Test.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_A_Test.java (added)
+++ xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_A_Test.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IgnoreXSIType_A_A_Test extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IgnoreXSIType_A_A_Test.class);
+ }
+
+ protected String getXMLDocument() {
+ return "xsitype_A_A.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public IgnoreXSIType_A_A_Test(String name) {
+ super(name);
+ }
+
+ public void testDefaultDocument() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testDefaultFragment() {
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testSetFalseDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetFalseFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetTrueDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ public void testSetTrueFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ private void checkTrueResult() {
+ checkResult();
+ }
+
+ private void checkFalseResult() {
+ checkResult();
+ }
+
+ private void checkResult() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+}
\ No newline at end of file
Added: xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_C_Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_C_Test.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_C_Test.java (added)
+++ xerces/java/trunk/tests/schema/config/IgnoreXSIType_A_C_Test.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IgnoreXSIType_A_C_Test extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IgnoreXSIType_A_C_Test.class);
+ }
+
+ protected String getXMLDocument() {
+ return "xsitype_A_C.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public IgnoreXSIType_A_C_Test(String name) {
+ super(name);
+ }
+
+ public void testDefaultDocument() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testDefaultFragment() {
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testSetFalseDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetFalseFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetTrueDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ public void testSetTrueFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ private void checkTrueResult() {
+ checkResult();
+ }
+
+ private void checkFalseResult() {
+ checkResult();
+ }
+
+ private void checkResult() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+}
\ No newline at end of file
Added: xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_AC_Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_AC_Test.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_AC_Test.java (added)
+++ xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_AC_Test.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IgnoreXSIType_C_AC_Test extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IgnoreXSIType_C_AC_Test.class);
+ }
+
+ protected String getXMLDocument() {
+ return "xsitype_C_AC.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public IgnoreXSIType_C_AC_Test(String name) {
+ super(name);
+ }
+
+ public void testDefaultDocument() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testDefaultFragment() {
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testSetFalseDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetFalseFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetTrueDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ public void testSetTrueFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ private void checkTrueResult() {
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_PARTIAL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertAnyType(fRootNode.getTypeDefinition());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_NONE, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertAnyType(child.getTypeDefinition());
+ }
+
+ private void checkFalseResult() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+}
\ No newline at end of file
Added: xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_A_Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_A_Test.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_A_Test.java (added)
+++ xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_A_Test.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IgnoreXSIType_C_A_Test extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IgnoreXSIType_C_A_Test.class);
+ }
+
+ protected String getXMLDocument() {
+ return "xsitype_C_A.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public IgnoreXSIType_C_A_Test(String name) {
+ super(name);
+ }
+
+ public void testDefaultDocument() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testDefaultFragment() {
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testSetFalseDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetFalseFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetTrueDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ public void testSetTrueFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ private void checkTrueResult() {
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_PARTIAL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertAnyType(fRootNode.getTypeDefinition());
+
+ checkChild();
+ }
+
+ private void checkFalseResult() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+
+ checkChild();
+ }
+
+ private void checkChild() {
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+}
\ No newline at end of file
Added: xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_CA_Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_CA_Test.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_CA_Test.java (added)
+++ xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_CA_Test.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IgnoreXSIType_C_CA_Test extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IgnoreXSIType_C_CA_Test.class);
+ }
+
+ protected String getXMLDocument() {
+ return "xsitype_C_CA.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public IgnoreXSIType_C_CA_Test(String name) {
+ super(name);
+ }
+
+ public void testDefaultDocument() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testDefaultFragment() {
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testSetFalseDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetFalseFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetTrueDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ public void testSetTrueFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ private void checkTrueResult() {
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_PARTIAL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertAnyType(fRootNode.getTypeDefinition());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_NONE, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertAnyType(child.getTypeDefinition());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+
+ private void checkFalseResult() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+
+ child = super.getChild(2);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementName("A", child.getElementDeclaration().getName());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+}
\ No newline at end of file
Added: xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_C_Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_C_Test.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_C_Test.java (added)
+++ xerces/java/trunk/tests/schema/config/IgnoreXSIType_C_C_Test.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class IgnoreXSIType_C_C_Test extends BaseTest {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IgnoreXSIType_C_C_Test.class);
+ }
+
+ protected String getXMLDocument() {
+ return "xsitype_C_C.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ public IgnoreXSIType_C_C_Test(String name) {
+ super(name);
+ }
+
+ public void testDefaultDocument() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testDefaultFragment() {
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ // default value of the feature is false
+ checkFalseResult();
+ }
+
+ public void testSetFalseDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetFalseFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, false);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkFalseResult();
+ }
+
+ public void testSetTrueDocument() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ public void testSetTrueFragment() {
+ try {
+ fValidator.setFeature(IGNORE_XSI_TYPE, true);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting feature: " + e1.getMessage());
+ }
+
+ try {
+ validateFragment();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkTrueResult();
+ }
+
+ private void checkTrueResult() {
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_NONE, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertAnyType(fRootNode.getTypeDefinition());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_NONE, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertAnyType(child.getTypeDefinition());
+ }
+
+ private void checkFalseResult() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
+
+ PSVIElementNSImpl child = super.getChild(1);
+ assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
+ .getValidationAttempted());
+ assertElementNull(child.getElementDeclaration());
+ assertTypeName("Y", child.getTypeDefinition().getName());
+ assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
+ }
+}
\ No newline at end of file
Added: xerces/java/trunk/tests/schema/config/RootTypeDefinitionTest.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/RootTypeDefinitionTest.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/RootTypeDefinitionTest.java (added)
+++ xerces/java/trunk/tests/schema/config/RootTypeDefinitionTest.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.impl.xs.SchemaSymbols;
+import org.apache.xerces.xs.ItemPSVI;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class RootTypeDefinitionTest extends BaseTest {
+
+ private QName unknownType;
+ private QName typeX;
+ private QName typeY;
+ private QName typeZ;
+ private QName typeOtherNamespace;
+
+ private final static String UNKNOWN_TYPE_ERROR = "cvc-type.1";
+
+ private final static String INVALID_DERIVATION_ERROR = "cvc-elt.4.3";
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(RootTypeDefinitionTest.class);
+ }
+
+ protected String getXMLDocument() {
+ return "base.xml";
+ }
+
+ protected String getSchemaFile() {
+ return "base.xsd";
+ }
+
+ protected String[] getRelevantErrorIDs() {
+ return new String[] { UNKNOWN_TYPE_ERROR, INVALID_DERIVATION_ERROR };
+ }
+
+ public RootTypeDefinitionTest(String name) {
+ super(name);
+ unknownType = new QName("W");
+ typeX = new QName("X");
+ typeY = new QName("Y");
+ typeZ = new QName("Z");
+ typeOtherNamespace = new QName("xslt.unittests", "W", "unit");
+ }
+
+ public void testDefault() {
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkDefault();
+ }
+
+ public void testSettingNull() {
+ try {
+ fValidator.setProperty(ROOT_TYPE, null);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ checkDefault();
+ }
+
+ public void testSettingToUnknownType() {
+ try {
+ fValidator.setProperty(ROOT_TYPE, unknownType);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertError(UNKNOWN_TYPE_ERROR);
+ checkDefault();
+ }
+
+ public void testSettingToEqualType() {
+ try {
+ fValidator.setProperty(ROOT_TYPE, typeX);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("X", fRootNode.getTypeDefinition().getName());
+ }
+
+ public void testSettingToDerivedType() {
+ // this is required to make it a valid type Y node
+ ((PSVIElementNSImpl) fRootNode).setAttributeNS(null, "attr", "typeY");
+ try {
+ fValidator.setProperty(ROOT_TYPE, typeY);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ }
+
+ public void testSettingToNonDerivedType() {
+ try {
+ fValidator.setProperty(ROOT_TYPE, typeZ);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Z", fRootNode.getTypeDefinition().getName());
+ }
+
+ public void testSettingToOtherSchemaType() {
+ ((PSVIElementNSImpl) fRootNode).setAttributeNS(SchemaSymbols.URI_XSI,
+ SchemaSymbols.XSI_SCHEMALOCATION,
+ "xslt.unittests otherNamespace.xsd");
+ try {
+ fValidator.setProperty(ROOT_TYPE, typeOtherNamespace);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("W", fRootNode.getTypeDefinition().getName());
+ assertTypeNamespace("xslt.unittests", fRootNode.getTypeDefinition()
+ .getNamespace());
+ }
+
+ public void testSettingTypeAndXSIType() {
+ // this is required to make it a valid type Y node
+ ((PSVIElementNSImpl) fRootNode).setAttributeNS(null, "attr", "typeY");
+ ((PSVIElementNSImpl) fRootNode).setAttributeNS(SchemaSymbols.URI_XSI,
+ SchemaSymbols.XSI_TYPE, "Y");
+ try {
+ fValidator.setProperty(ROOT_TYPE, typeX);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Y", fRootNode.getTypeDefinition().getName());
+ }
+
+ public void testSettingTypeAndInvalidXSIType() {
+ ((PSVIElementNSImpl) fRootNode).setAttributeNS(SchemaSymbols.URI_XSI,
+ SchemaSymbols.XSI_TYPE, "Z");
+ try {
+ fValidator.setProperty(ROOT_TYPE, typeX);
+ } catch (SAXException e1) {
+ Assert.fail("Problem setting property: " + e1.getMessage());
+ }
+
+ try {
+ validateDocument();
+ } catch (Exception e) {
+ Assert.fail("Validation failed: " + e.getMessage());
+ }
+
+ assertError(INVALID_DERIVATION_ERROR);
+ assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementNull(fRootNode.getElementDeclaration());
+ assertTypeName("Z", fRootNode.getTypeDefinition().getName());
+ }
+
+ private void checkDefault() {
+ assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
+ assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
+ .getValidationAttempted());
+ assertElementName("A", fRootNode.getElementDeclaration().getName());
+ assertTypeName("X", fRootNode.getTypeDefinition().getName());
+ }
+}
Added: xerces/java/trunk/tests/schema/config/SpecialCaseErrorHandler.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/schema/config/SpecialCaseErrorHandler.java?rev=371982&view=auto
==============================================================================
--- xerces/java/trunk/tests/schema/config/SpecialCaseErrorHandler.java (added)
+++ xerces/java/trunk/tests/schema/config/SpecialCaseErrorHandler.java Tue Jan 24 11:07:20 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package schema.config;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @author Peter McCracken, IBM
+ * @version $Id: $
+ */
+public class SpecialCaseErrorHandler implements ErrorHandler {
+
+ public static final boolean DEBUG = false;
+
+ private HashMap errors;
+
+ public SpecialCaseErrorHandler(String[] specialCases) {
+ errors = new HashMap();
+ for (int i = 0; i < specialCases.length; ++i) {
+ errors.put(specialCases[i], Boolean.FALSE);
+ }
+ }
+
+ public void reset() {
+ for (Iterator iter = errors.keySet().iterator(); iter.hasNext();) {
+ String error = (String) iter.next();
+ errors.put(error, Boolean.FALSE);
+ }
+ }
+
+ public void warning(SAXParseException arg0) throws SAXException {
+ if (DEBUG) {
+ System.err.println(arg0.getMessage());
+ }
+ }
+
+ public void error(SAXParseException arg0) throws SAXException {
+ if (DEBUG) {
+ System.err.println(arg0.getMessage());
+ }
+ for (Iterator iter = errors.keySet().iterator(); iter.hasNext();) {
+ String error = (String) iter.next();
+ if (arg0.getMessage().startsWith(error)) {
+ errors.put(error, Boolean.TRUE);
+ }
+ }
+ }
+
+ public void fatalError(SAXParseException arg0) throws SAXException {
+ throw arg0;
+ }
+
+ public boolean specialCaseFound(String key) {
+ return ((Boolean) errors.get(key)).booleanValue();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org