You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/01/18 23:08:48 UTC
svn commit: r1851656 [24/28] - in /xmlbeans/trunk: ./ external/ lib/
resources/ resources/typeimpl/ resources/typeimpl/org/
resources/typeimpl/org/apache/ resources/typeimpl/org/apache/xmlbeans/
resources/typeimpl/org/apache/xmlbeans/impl/ resources/ty...
Modified: xmlbeans/trunk/test/src/xmlobject/checkin/InstanceValidationTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/checkin/InstanceValidationTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/xmlobject/checkin/InstanceValidationTests.java (original)
+++ xmlbeans/trunk/test/src/xmlobject/checkin/InstanceValidationTests.java Fri Jan 18 23:08:44 2019
@@ -15,13 +15,10 @@
package xmlobject.checkin;
-import junit.framework.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.xml.stream.XMLInputStream;
import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+import org.junit.Test;
+import tools.util.JarUtil;
import javax.xml.namespace.QName;
import java.io.File;
@@ -30,38 +27,27 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import tools.util.*;
-
-public class InstanceValidationTests extends TestCase
-{
- public InstanceValidationTests(String name)
- { super(name); }
-
- public static Test suite()
- { return new TestSuite(InstanceValidationTests.class); }
+import static org.junit.Assert.*;
+public class InstanceValidationTests {
static String[] _args;
static String _test;
-
- public SchemaTypeLoader makeSchemaTypeLoader(String[] schemas) throws XmlException
- {
+
+ private SchemaTypeLoader makeSchemaTypeLoader(String[] schemas) throws XmlException {
XmlObject[] schemaDocs = new XmlObject[schemas.length];
- for (int i = 0; i < schemas.length; i++)
- {
+ for (int i = 0; i < schemas.length; i++) {
schemaDocs[i] = XmlObject.Factory.parse(schemas[i]);
}
return XmlBeans.loadXsd(schemaDocs);
}
- public SchemaTypeLoader makeSchemaTypeLoader(File[] schemas) throws XmlException, IOException
- {
+ private SchemaTypeLoader makeSchemaTypeLoader(File[] schemas) throws XmlException, IOException {
XmlObject[] schemaDocs = new XmlObject[schemas.length];
- for (int i = 0; i < schemas.length; i++)
- {
+ for (int i = 0; i < schemas.length; i++) {
schemaDocs[i] = XmlObject.Factory.parse(schemas[i], new XmlOptions().setLoadLineNumbers().setLoadMessageDigest());
}
@@ -69,31 +55,12 @@ public class InstanceValidationTests ext
}
- public List performValidation(String[] schemas, QName docType, String instances,
- boolean startOnDocument) throws XmlException
- {
+ private List performValidation(String[] schemas, String instances) throws XmlException {
SchemaTypeLoader stl = makeSchemaTypeLoader(schemas);
XmlOptions options = new XmlOptions();
- if (docType != null)
- {
- SchemaType docSchema = stl.findDocumentType(docType);
-
- Assert.assertTrue(docSchema != null);
-
- options.setDocumentType(docSchema);
- }
-
- XmlObject x = stl.parse( instances, null, options);
-
- if (!startOnDocument)
- {
- XmlCursor c = x.newCursor();
- c.toFirstChild();
- x = c.getObject();
- c.dispose();
- }
+ XmlObject x = stl.parse(instances, null, options);
List xel = new ArrayList();
options.setErrorListener(xel);
@@ -103,9 +70,8 @@ public class InstanceValidationTests ext
return xel;
}
-
- public void testValidationElementError() throws XmlException
- {
+ @Test
+ public void testValidationElementError() throws XmlException {
String bobSchema = "<xs:schema\n" + " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + " xmlns:bob='http://openuri.org/bobschema'\n" + " targetNamespace='http://openuri.org/bobschema'\n" + " elementFormDefault='qualified'>\n" + "\n" + " <xs:complexType name='biff'>\n" + " <xs:complexContent>\n" + " <xs:extension base='bob:foo'>\n" + " <xs:sequence>\n" + " <xs:element name='a' minOccurs='0' maxOccurs='unbounded'/>\n" + " </xs:sequence>\n" + " </xs:extension>\n" + " </xs:complexContent>\n" + " </xs:complexType>\n" + "" + " <xs:complexType name='foo'>\n" + " </xs:complexType>\n" + "" + " <xs:element name='foo' type='bob:foo'>\n" + " </xs:element>\n" + "" + "</xs:schema>\n";
String invalid = "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " + "xsi:type='bob:biff'><bob:q/></bob:foo>";
@@ -114,299 +80,285 @@ public class InstanceValidationTests ext
List errors = null;
- errors = performValidation(schemas, null, invalid, true);
- Assert.assertTrue(errors != null);
- Assert.assertTrue(errors.size()>0);
-
- for (Iterator it = errors.iterator(); it.hasNext();)
- {
- XmlValidationError xmlValError = (XmlValidationError) it.next();
- Assert.assertEquals(xmlValError.getErrorType(), XmlValidationError.INCORRECT_ELEMENT);
- Assert.assertEquals(xmlValError.getBadSchemaType().getName().getLocalPart(), "biff");
- Assert.assertEquals(xmlValError.getOffendingQName().getLocalPart(), "q");
- Assert.assertEquals(xmlValError.getMessage(), "Expected element 'a@http://openuri.org/bobschema' instead of 'q@http://openuri.org/bobschema' here in element foo@http://openuri.org/bobschema");
+ errors = performValidation(schemas, invalid);
+ assertNotNull(errors);
+ assertTrue(errors.size() > 0);
+
+ for (Object error : errors) {
+ XmlValidationError xmlValError = (XmlValidationError) error;
+ assertEquals(xmlValError.getErrorType(), XmlValidationError.INCORRECT_ELEMENT);
+ assertEquals(xmlValError.getBadSchemaType().getName().getLocalPart(), "biff");
+ assertEquals(xmlValError.getOffendingQName().getLocalPart(), "q");
+ assertEquals(xmlValError.getMessage(), "Expected element 'a@http://openuri.org/bobschema' instead of 'q@http://openuri.org/bobschema' here in element foo@http://openuri.org/bobschema");
}
}
+ @Test
+ public void testValidationAttributeError() throws XmlException {
- public void testValidationAttributeError() throws XmlException
- {
- StringBuffer empSchema = new StringBuffer();
-
- empSchema.append("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n");
- empSchema.append("<xs:element name='age'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:integer'>\n");
- empSchema.append("<xs:minInclusive value='0'/>\n");
- empSchema.append("<xs:maxInclusive value='100'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='empRecords'>\n");
- empSchema.append("<xs:complexType>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='name' type='xs:string'/>\n");
- empSchema.append("<xs:complexType name='personType'>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element ref='name'/>\n");
- empSchema.append("<xs:element ref='age'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("<xs:attribute name='employee' use='required'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:NMTOKEN'>\n");
- empSchema.append("<xs:enumeration value='current'/>\n");
- empSchema.append("<xs:enumeration value='past'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:attribute>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:schema>\n");
-
- StringBuffer xmlInstance = new StringBuffer();
- xmlInstance.append("<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >");
- xmlInstance.append("<person employee='past'>");
- xmlInstance.append("<name>joe blow</name>");
- xmlInstance.append("<age>31</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("<person>");
- xmlInstance.append("<name>test user</name>");
- xmlInstance.append("<age>29</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("</empRecords>");
-
- String[] schemas = {empSchema.toString()};
+ String empSchema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
+ "<xs:element name='age'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:integer'>\n" +
+ "<xs:minInclusive value='0'/>\n" +
+ "<xs:maxInclusive value='100'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='empRecords'>\n" +
+ "<xs:complexType>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n" +
+ "</xs:sequence>\n" +
+ "</xs:complexType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='name' type='xs:string'/>\n" +
+ "<xs:complexType name='personType'>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element ref='name'/>\n" +
+ "<xs:element ref='age'/>\n" +
+ "</xs:sequence>\n" +
+ "<xs:attribute name='employee' use='required'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:NMTOKEN'>\n" +
+ "<xs:enumeration value='current'/>\n" +
+ "<xs:enumeration value='past'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:attribute>\n" +
+ "</xs:complexType>\n" +
+ "</xs:schema>\n";
+ String[] schemas = {empSchema};
List errors = null;
- errors = performValidation(schemas, null, xmlInstance.toString(), true);
- Assert.assertTrue(errors != null);
- Assert.assertTrue(errors.size()>0);
-
- for (Iterator it = errors.iterator(); it.hasNext();)
- {
- XmlValidationError xmlValError = (XmlValidationError) it.next();
- Assert.assertEquals(xmlValError.getErrorType(), XmlValidationError.INCORRECT_ATTRIBUTE);
- Assert.assertEquals(xmlValError.getBadSchemaType().getName().getLocalPart(), "personType");
- Assert.assertEquals(xmlValError.getOffendingQName().getLocalPart(), "employee");
- Assert.assertEquals(xmlValError.getMessage(), "Expected attribute: employee in element person");
+ String xmlInstance = "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
+ "<person employee='past'>" +
+ "<name>joe blow</name>" +
+ "<age>31</age>" +
+ "</person>" +
+ "<person>" +
+ "<name>test user</name>" +
+ "<age>29</age>" +
+ "</person>" +
+ "</empRecords>";
+ errors = performValidation(schemas, xmlInstance);
+ assertNotNull(errors);
+ assertTrue(errors.size() > 0);
+
+ for (Object error : errors) {
+ XmlValidationError xmlValError = (XmlValidationError) error;
+ assertEquals(xmlValError.getErrorType(), XmlValidationError.INCORRECT_ATTRIBUTE);
+ assertEquals(xmlValError.getBadSchemaType().getName().getLocalPart(), "personType");
+ assertEquals(xmlValError.getOffendingQName().getLocalPart(), "employee");
+ assertEquals(xmlValError.getMessage(), "Expected attribute: employee in element person");
}
}
- public void testValidationIncorrectElementError() throws XmlException
- {
- StringBuffer empSchema = new StringBuffer();
-
- empSchema.append("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n");
- empSchema.append("<xs:element name='age'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:integer'>\n");
- empSchema.append("<xs:minInclusive value='0'/>\n");
- empSchema.append("<xs:maxInclusive value='100'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='empRecords'>\n");
- empSchema.append("<xs:complexType>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='name' type='xs:string'/>\n");
- empSchema.append("<xs:complexType name='personType'>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element ref='name'/>\n");
- empSchema.append("<xs:element ref='age'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("<xs:attribute name='employee' use='required'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:NMTOKEN'>\n");
- empSchema.append("<xs:enumeration value='current'/>\n");
- empSchema.append("<xs:enumeration value='past'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:attribute>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:schema>\n");
-
- StringBuffer xmlInstance = new StringBuffer();
- xmlInstance.append("<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >");
- xmlInstance.append("<person employee='past'>");
- //xmlInstance.append("<name>joe blow</name>");
- xmlInstance.append("<age>31</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("<person employee='current'>");
- xmlInstance.append("<name>test user</name>");
- xmlInstance.append("<age>29</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("</empRecords>");
+ @Test
+ public void testValidationIncorrectElementError() throws XmlException {
- String[] schemas = {empSchema.toString()};
+ String empSchema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
+ "<xs:element name='age'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:integer'>\n" +
+ "<xs:minInclusive value='0'/>\n" +
+ "<xs:maxInclusive value='100'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='empRecords'>\n" +
+ "<xs:complexType>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n" +
+ "</xs:sequence>\n" +
+ "</xs:complexType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='name' type='xs:string'/>\n" +
+ "<xs:complexType name='personType'>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element ref='name'/>\n" +
+ "<xs:element ref='age'/>\n" +
+ "</xs:sequence>\n" +
+ "<xs:attribute name='employee' use='required'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:NMTOKEN'>\n" +
+ "<xs:enumeration value='current'/>\n" +
+ "<xs:enumeration value='past'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:attribute>\n" +
+ "</xs:complexType>\n" +
+ "</xs:schema>\n";
+ String[] schemas = {empSchema};
List errors = null;
- errors = performValidation(schemas, null, xmlInstance.toString(), true);
- Assert.assertTrue(errors != null);
- Assert.assertTrue(errors.size()>0);
+ String xmlInstance =
+ "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
+ "<person employee='past'>" +
+ "<age>31</age>" +
+ "</person>" +
+ "<person employee='current'>" +
+ "<name>test user</name>" +
+ "<age>29</age>" +
+ "</person>" +
+ "</empRecords>";
+
+ errors = performValidation(schemas, xmlInstance);
+ assertNotNull(errors);
+ assertTrue(errors.size() > 0);
Iterator it = errors.iterator();
- Assert.assertTrue(it.hasNext());
+ assertTrue(it.hasNext());
XmlValidationError xmlValError = (XmlValidationError) it.next();
- Assert.assertEquals(XmlValidationError.INCORRECT_ELEMENT, xmlValError.getErrorType());
- Assert.assertEquals("personType", xmlValError.getBadSchemaType().getName().getLocalPart());
+ assertEquals(XmlValidationError.INCORRECT_ELEMENT, xmlValError.getErrorType());
+ assertEquals("personType", xmlValError.getBadSchemaType().getName().getLocalPart());
// todo debug this Assert.assertEquals(xmlValError.getOffendingQName().getLocalPart(), "age");
- Assert.assertEquals("Expected element 'name' instead of 'age' here in element person", xmlValError.getMessage());
+ assertEquals("Expected element 'name' instead of 'age' here in element person", xmlValError.getMessage());
- Assert.assertTrue(it.hasNext());
+ assertTrue(it.hasNext());
xmlValError = (XmlValidationError) it.next();
- Assert.assertEquals(XmlValidationError.INCORRECT_ELEMENT, xmlValError.getErrorType());
- Assert.assertEquals("personType", xmlValError.getBadSchemaType().getName().getLocalPart());
+ assertEquals(XmlValidationError.INCORRECT_ELEMENT, xmlValError.getErrorType());
+ assertEquals("personType", xmlValError.getBadSchemaType().getName().getLocalPart());
// todo debug this Assert.assertEquals(xmlValError.getOffendingQName().getLocalPart(), "age");
- Assert.assertEquals("Expected element 'name' before the end of the content in element person", xmlValError.getMessage());
+ assertEquals("Expected element 'name' before the end of the content in element person", xmlValError.getMessage());
}
- public void testValidationElementNotAllowedError() throws XmlException
- {
- StringBuffer empSchema = new StringBuffer();
-
- empSchema.append("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n");
- empSchema.append("<xs:element name='age'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:integer'>\n");
- empSchema.append("<xs:minInclusive value='0'/>\n");
- empSchema.append("<xs:maxInclusive value='100'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='empRecords'>\n");
- empSchema.append("<xs:complexType>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='name' type='xs:string'/>\n");
- empSchema.append("<xs:complexType name='personType'>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element ref='name'/>\n");
- empSchema.append("<xs:element ref='age'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("<xs:attribute name='employee' use='required'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:NMTOKEN'>\n");
- empSchema.append("<xs:enumeration value='current'/>\n");
- empSchema.append("<xs:enumeration value='past'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:attribute>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:schema>\n");
-
- StringBuffer xmlInstance = new StringBuffer();
- xmlInstance.append("<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >");
- xmlInstance.append("<person employee='past'>");
- xmlInstance.append("<name>joe blow</name>");
- xmlInstance.append("<age>31</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("<person employee='current'>");
- xmlInstance.append("<name>test user</name>");
- xmlInstance.append("<age>29</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("</empRecords>");
+ @Test
+ public void testValidationElementNotAllowedError() throws XmlException {
- String[] schemas = {empSchema.toString()};
+ String empSchema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
+ "<xs:element name='age'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:integer'>\n" +
+ "<xs:minInclusive value='0'/>\n" +
+ "<xs:maxInclusive value='100'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='empRecords'>\n" +
+ "<xs:complexType>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n" +
+ "</xs:sequence>\n" +
+ "</xs:complexType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='name' type='xs:string'/>\n" +
+ "<xs:complexType name='personType'>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element ref='name'/>\n" +
+ "<xs:element ref='age'/>\n" +
+ "</xs:sequence>\n" +
+ "<xs:attribute name='employee' use='required'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:NMTOKEN'>\n" +
+ "<xs:enumeration value='current'/>\n" +
+ "<xs:enumeration value='past'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:attribute>\n" +
+ "</xs:complexType>\n" +
+ "</xs:schema>\n";
+ String[] schemas = {empSchema};
List errors = null;
- errors = performValidation(schemas, null, xmlInstance.toString(), true);
- Assert.assertTrue(errors != null);
+ String xmlInstance =
+ "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
+ "<person employee='past'>" +
+ "<name>joe blow</name>" +
+ "<age>31</age>" +
+ "</person>" +
+ "<person employee='current'>" +
+ "<name>test user</name>" +
+ "<age>29</age>" +
+ "</person>" +
+ "</empRecords>";
+ errors = performValidation(schemas, xmlInstance);
+ assertNotNull(errors);
// todo: enable this assert Assert.assertTrue(errors.size()>0);
- for (Iterator it = errors.iterator(); it.hasNext();)
- {
- XmlValidationError xmlValError = (XmlValidationError) it.next();
-
- Assert.assertEquals(xmlValError.getErrorType(), XmlValidationError.ELEMENT_NOT_ALLOWED);
- Assert.assertEquals(xmlValError.getBadSchemaType().getName().getLocalPart(), "personType");
- Assert.assertEquals(xmlValError.getMessage(), "Expected element(s)");
+ for (Object error : errors) {
+ XmlValidationError xmlValError = (XmlValidationError) error;
+
+ assertEquals(xmlValError.getErrorType(), XmlValidationError.ELEMENT_NOT_ALLOWED);
+ assertEquals(xmlValError.getBadSchemaType().getName().getLocalPart(), "personType");
+ assertEquals(xmlValError.getMessage(), "Expected element(s)");
}
}
+ @Test
+ public void testValidationAttributeTypeError() throws XmlException {
- public void testValidationAttributeTypeError() throws XmlException
- {
- StringBuffer empSchema = new StringBuffer();
-
- empSchema.append("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n");
- empSchema.append("<xs:element name='age'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:integer'>\n");
- empSchema.append("<xs:minInclusive value='0'/>\n");
- empSchema.append("<xs:maxInclusive value='100'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='empRecords'>\n");
- empSchema.append("<xs:complexType>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='name' type='xs:string'/>\n");
- empSchema.append("<xs:complexType name='personType'>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element ref='name'/>\n");
- empSchema.append("<xs:element ref='age'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("<xs:attribute name='employee' use='required'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:NMTOKEN'>\n");
- empSchema.append("<xs:enumeration value='current'/>\n");
- empSchema.append("<xs:enumeration value='past'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:attribute>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:schema>\n");
-
- StringBuffer xmlInstance = new StringBuffer();
- xmlInstance.append("<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >");
- xmlInstance.append("<person employee='past'>");
- xmlInstance.append("<name>joe blow</name>");
- xmlInstance.append("<age>31</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("<person employee='current'>");
- xmlInstance.append("<name>test user</name>");
- xmlInstance.append("<age>junk</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("</empRecords>");
-
- String[] schemas = {empSchema.toString()};
+ String empSchema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
+ "<xs:element name='age'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:integer'>\n" +
+ "<xs:minInclusive value='0'/>\n" +
+ "<xs:maxInclusive value='100'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='empRecords'>\n" +
+ "<xs:complexType>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n" +
+ "</xs:sequence>\n" +
+ "</xs:complexType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='name' type='xs:string'/>\n" +
+ "<xs:complexType name='personType'>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element ref='name'/>\n" +
+ "<xs:element ref='age'/>\n" +
+ "</xs:sequence>\n" +
+ "<xs:attribute name='employee' use='required'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:NMTOKEN'>\n" +
+ "<xs:enumeration value='current'/>\n" +
+ "<xs:enumeration value='past'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:attribute>\n" +
+ "</xs:complexType>\n" +
+ "</xs:schema>\n";
+ String[] schemas = {empSchema};
List errors = null;
- errors = performValidation(schemas, null, xmlInstance.toString(), true);
- Assert.assertTrue(errors != null);
- Assert.assertTrue(errors.size()>0);
-
- for (Iterator it = errors.iterator(); it.hasNext();)
- {
- XmlValidationError xmlValError = (XmlValidationError) it.next();
- Assert.assertEquals(xmlValError.getErrorType(), XmlValidationError.ATTRIBUTE_TYPE_INVALID);
- Assert.assertEquals(xmlValError.getMessage(), "Invalid decimal value: unexpected char '106'");
+ String xmlInstance = "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
+ "<person employee='past'>" +
+ "<name>joe blow</name>" +
+ "<age>31</age>" +
+ "</person>" +
+ "<person employee='current'>" +
+ "<name>test user</name>" +
+ "<age>junk</age>" +
+ "</person>" +
+ "</empRecords>";
+ errors = performValidation(schemas, xmlInstance);
+ assertNotNull(errors);
+ assertTrue(errors.size() > 0);
+
+ for (Object error : errors) {
+ XmlValidationError xmlValError = (XmlValidationError) error;
+ assertEquals(xmlValError.getErrorType(), XmlValidationError.ATTRIBUTE_TYPE_INVALID);
+ assertEquals(xmlValError.getMessage(), "Invalid decimal value: unexpected char '106'");
}
}
- public void testElementError() throws XmlException
- {
- String bobSchema = "<xs:schema\n" + " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
+ @Test
+ public void testElementError() throws XmlException {
+ String bobSchema =
+ "<xs:schema\n" +
+ " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
" xmlns:bob='http://openuri.org/bobschema'\n" +
" targetNamespace='http://openuri.org/bobschema'\n" +
" elementFormDefault='qualified'>\n" +
@@ -427,1465 +379,1419 @@ public class InstanceValidationTests ext
"</xs:schema>\n";
String invalid = "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
- "xmlns:bob='http://openuri.org/bobschema' " +
- "xsi:type='bob:biff'><bob:q/></bob:foo>";
+ "xmlns:bob='http://openuri.org/bobschema' " +
+ "xsi:type='bob:biff'><bob:q/></bob:foo>";
String[] schemas = {bobSchema};
- List errors = performValidation(schemas, null, invalid, true);
- Assert.assertTrue(errors != null);
- Assert.assertTrue(errors.size()>0);
-
- for (Iterator it = errors.iterator(); it.hasNext();)
- {
- XmlError xmlError = (XmlError) it.next();
- Assert.assertEquals(xmlError.getMessage(), "Expected element 'a@http://openuri.org/bobschema' instead of 'q@http://openuri.org/bobschema' here in element foo@http://openuri.org/bobschema");
+ List errors = performValidation(schemas, invalid);
+ assertNotNull(errors);
+ assertTrue(errors.size() > 0);
+
+ for (Object error : errors) {
+ XmlError xmlError = (XmlError) error;
+ assertEquals(xmlError.getMessage(), "Expected element 'a@http://openuri.org/bobschema' instead of 'q@http://openuri.org/bobschema' here in element foo@http://openuri.org/bobschema");
// todo check XmlValidationError
}
}
- public void testAttributeError() throws XmlException
- {
- StringBuffer empSchema = new StringBuffer();
-
- empSchema.append("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n");
- empSchema.append("<xs:element name='age'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:integer'>\n");
- empSchema.append("<xs:minInclusive value='0'/>\n");
- empSchema.append("<xs:maxInclusive value='100'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='empRecords'>\n");
- empSchema.append("<xs:complexType>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:element>\n");
- empSchema.append("<xs:element name='name' type='xs:string'/>\n");
- empSchema.append("<xs:complexType name='personType'>\n");
- empSchema.append("<xs:sequence>\n");
- empSchema.append("<xs:element ref='name'/>\n");
- empSchema.append("<xs:element ref='age'/>\n");
- empSchema.append("</xs:sequence>\n");
- empSchema.append("<xs:attribute name='employee' use='required'>\n");
- empSchema.append("<xs:simpleType>\n");
- empSchema.append("<xs:restriction base='xs:NMTOKEN'>\n");
- empSchema.append("<xs:enumeration value='current'/>\n");
- empSchema.append("<xs:enumeration value='past'/>\n");
- empSchema.append("</xs:restriction>\n");
- empSchema.append("</xs:simpleType>\n");
- empSchema.append("</xs:attribute>\n");
- empSchema.append("</xs:complexType>\n");
- empSchema.append("</xs:schema>\n");
-
- StringBuffer xmlInstance = new StringBuffer();
- xmlInstance.append("<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >");
- xmlInstance.append("<person employee='past'>");
- xmlInstance.append("<name>joe blow</name>");
- xmlInstance.append("<age>31</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("<person>");
- xmlInstance.append("<name>test user</name>");
- xmlInstance.append("<age>29</age>");
- xmlInstance.append("</person>");
- xmlInstance.append("</empRecords>");
+ @Test
+ public void testAttributeError() throws XmlException {
- String[] schemas = {empSchema.toString()};
+ String empSchema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
+ "<xs:element name='age'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:integer'>\n" +
+ "<xs:minInclusive value='0'/>\n" +
+ "<xs:maxInclusive value='100'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='empRecords'>\n" +
+ "<xs:complexType>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element name='person' type='personType' maxOccurs='unbounded'/>\n" +
+ "</xs:sequence>\n" +
+ "</xs:complexType>\n" +
+ "</xs:element>\n" +
+ "<xs:element name='name' type='xs:string'/>\n" +
+ "<xs:complexType name='personType'>\n" +
+ "<xs:sequence>\n" +
+ "<xs:element ref='name'/>\n" +
+ "<xs:element ref='age'/>\n" +
+ "</xs:sequence>\n" +
+ "<xs:attribute name='employee' use='required'>\n" +
+ "<xs:simpleType>\n" +
+ "<xs:restriction base='xs:NMTOKEN'>\n" +
+ "<xs:enumeration value='current'/>\n" +
+ "<xs:enumeration value='past'/>\n" +
+ "</xs:restriction>\n" +
+ "</xs:simpleType>\n" +
+ "</xs:attribute>\n" +
+ "</xs:complexType>\n" +
+ "</xs:schema>\n";
+ String[] schemas = {empSchema};
List errors = null;
- errors = performValidation(schemas, null, xmlInstance.toString(), true);
- Assert.assertTrue(errors != null);
- Assert.assertTrue(errors.size()>0);
-
- for (Iterator it = errors.iterator(); it.hasNext();)
- {
- XmlError xmlError = (XmlError) it.next();
- Assert.assertEquals(xmlError.getMessage(), "Expected attribute: employee in element person");
+ String xmlInstance =
+ "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
+ "<person employee='past'>" +
+ "<name>joe blow</name>" +
+ "<age>31</age>" +
+ "</person>" +
+ "<person>" +
+ "<name>test user</name>" +
+ "<age>29</age>" +
+ "</person>" +
+ "</empRecords>";
+ errors = performValidation(schemas, xmlInstance);
+ assertNotNull(errors);
+ assertTrue(errors.size() > 0);
+
+ for (Object error : errors) {
+ XmlError xmlError = (XmlError) error;
+ assertEquals(xmlError.getMessage(), "Expected attribute: employee in element person");
// todo check XmlValidationError
}
}
+ @Test
+ public void testValidate0() throws Exception {
+ //
+ // The most basic schema
+ //
+
+ String schema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ "</xs:schema>" +
+ "";
+ String[] schemas = {schema};
- public void testValidate0 ( )
- throws Exception
- {
- //
- // The most basic schema
- //
+ SchemaTypeLoader stl = makeSchemaTypeLoader(schemas);
- String schema =
- "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
- "</xs:schema>" +
- "";
+ //
+ // One which uses ##targetNamespace on a wildcard
+ //
- String[] schemas = { schema };
+ schema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ " <xs:complexType name='foo'>\n" +
+ " <xs:sequence>\n" +
+ " <xs:any namespace='##targetNamespace'/>\n" +
+ " </xs:sequence>\n" +
+ " </xs:complexType>\n" +
+ "</xs:schema>" +
+ "";
- SchemaTypeLoader stl = makeSchemaTypeLoader( schemas );
+ String[] schemas99 = {schema};
- //
- // One which uses ##targetNamespace on a wildcard
- //
+ stl = makeSchemaTypeLoader(schemas99);
- schema =
- "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
- " <xs:complexType name='foo'>\n" +
- " <xs:sequence>\n" +
- " <xs:any namespace='##targetNamespace'/>\n" +
- " </xs:sequence>\n" +
- " </xs:complexType>\n" +
- "</xs:schema>" +
- "";
+ //
+ // A big, nasty schema :-)
+ //
- String[] schemas99 = { schema };
+ File schemeFile =
+ JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XMLSchema.xsd");
+ File xmlFile = JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XML.xsd");
- stl = makeSchemaTypeLoader( schemas99 );
+ File[] schemasF = {schemeFile, xmlFile};
- //
- // A big, nasty schema :-)
- //
+ stl = makeSchemaTypeLoader(schemasF);
- File schemeFile =
- JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XMLSchema.xsd" );
- File xmlFile = JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XML.xsd" );
+ SchemaType type =
+ stl.findDocumentType(
+ new QName("http://www.w3.org/2001/XMLSchema", "schema"));
- File[] schemasF = { schemeFile, xmlFile };
+ assertNotNull(type);
- stl = makeSchemaTypeLoader( schemasF );
- SchemaType type =
- stl.findDocumentType(
- new QName( "http://www.w3.org/2001/XMLSchema", "schema" ) );
+ //
+ // A good piece from a J2EE schema
+ //
- Assert.assertTrue( type != null );
+ schema =
+ "<?xml version='1.0' encoding='UTF-8'?>\n" +
+ "<xsd:schema xmlns='http://www.w3.org/2001/XMLSchema'\n" +
+ " xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
+ " elementFormDefault='qualified'\n" +
+ " attributeFormDefault='unqualified'>\n" +
+ "<xsd:annotation>\n" +
+ "<xsd:documentation>\n" +
+ "@(#)application-client_1_4.xsds 1.7 07/08/02\n" +
+ "</xsd:documentation>\n" +
+ "</xsd:annotation>\n" +
+ "</xsd:schema>\n";
+ String[] schemas5 = {schema};
- //
- // A good piece from a J2EE schema
- //
+ stl = makeSchemaTypeLoader(schemas5);
- schema =
- "<?xml version='1.0' encoding='UTF-8'?>\n" +
- "<xsd:schema xmlns='http://www.w3.org/2001/XMLSchema'\n" +
- " xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
- " elementFormDefault='qualified'\n" +
- " attributeFormDefault='unqualified'>\n" +
- "<xsd:annotation>\n" +
- "<xsd:documentation>\n" +
- "@(#)application-client_1_4.xsds 1.7 07/08/02\n" +
- "</xsd:documentation>\n" +
- "</xsd:annotation>\n" +
- "</xsd:schema>\n";
+ //
+ // A bad schema
+ //
- String[] schemas5 = { schema };
+ schema = "<foo/>";
- stl = makeSchemaTypeLoader( schemas5 );
+ String[] schemas2 = {schema};
- //
- // A bad schema
- //
+ try {
+ stl = makeSchemaTypeLoader(schemas2);
+ fail();
+ } catch (Exception e) {
+ }
- schema = "<foo/>";
+ //
+ // A bad schema
+ //
+ schema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ " <foo/>\n" +
+ "</xs:schema>" +
+ "";
- String[] schemas2 = { schema };
+ String[] schemas3 = {schema};
- try
- {
- stl = makeSchemaTypeLoader( schemas2 );
- Assert.assertTrue( false );
- }
- catch ( Exception e )
- {
- }
-
- //
- // A bad schema
- //
- schema =
- "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
- " <foo/>\n" +
- "</xs:schema>" +
- "";
-
- String[] schemas3 = { schema };
-
- try
- {
- makeSchemaTypeLoader( schemas3 );
+ try {
+ makeSchemaTypeLoader(schemas3);
- Assert.assertTrue( false );
- }
- catch ( XmlException e )
- {
- }
+ fail();
+ } catch (XmlException e) {
}
+ }
- public void testValidate1 ( )
- throws Exception
- {
- String ericSchema =
- "<xs:schema\n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " xmlns:nw='http://openuri.org/ericschema'\n" +
- " targetNamespace='http://openuri.org/ericschema'\n" +
- " elementFormDefault='qualified'>\n" +
- "\n" +
- " <xs:complexType name='foo'>\n" +
- " </xs:complexType>\n" +
- "\n" +
- " <xs:element name='foo' type='nw:foo'>\n" +
- " </xs:element>\n" +
- "\n" +
- " <xs:element name='eric'>\n" +
- " <xs:complexType>\n" +
- " <xs:sequence>\n" +
- " <xs:element name='a' maxOccurs='unbounded'/>\n" +
- " <xs:element name='b' />\n" +
- " <xs:any namespace='yaya' minOccurs='0' maxOccurs='1' processContents='lax'/>\n" +
- " <xs:element name='c' />\n" +
- " <xs:any minOccurs='0' maxOccurs='unbounded' processContents='strict'/>\n" +
- " </xs:sequence>\n" +
- " <xs:attribute name='x' use='optional'/>\n" +
- " <xs:attribute name='y' use='required'/>\n" +
- " <xs:attribute name='z' use='prohibited'/>\n" +
- " </xs:complexType>\n" +
- " </xs:element>\n" +
- "" +
- "</xs:schema>\n";
-
- String eric2Schema =
- "<xs:schema\n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " xmlns:nw='http://openuri.org/ericschema2'\n" +
- " xmlns:eric='http://openuri.org/ericschema'\n" +
- " targetNamespace='http://openuri.org/ericschema2'\n" +
- " elementFormDefault='qualified'>\n" +
- "\n" +
- " <xs:complexType name='eric2'>\n" +
- " <xs:complexContent>\n" +
- " <xs:extension base='eric:foo'>\n" +
- " <xs:sequence>\n" +
- " <xs:element name='a' maxOccurs='unbounded'/>\n" +
- " </xs:sequence>\n" +
- " </xs:extension>\n" +
- " </xs:complexContent>\n" +
- " </xs:complexType>\n" +
- "</xs:schema>\n";
-
- String eric = "<eric y='Y' xmlns='http://openuri.org/ericschema'>";
- String eric2 = "<eric xmlns='http://openuri.org/ericschema2'>";
- String xsi = "xmlns:eric2='http://openuri.org/ericschema2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
-
- String[] valid = {
- eric + "<a/><b/><c/><foo xsi:type='eric2:eric2' " +
- xsi + "><a xmlns=\"http://openuri.org/ericschema2\"/></foo></eric>",
- eric + "<a/><b/><boo xmlns='yaya'/><c/></eric>",
- eric + "<a/><b/><c/></eric>",
- eric + "<a x='y'/><b/><c/></eric>",
- "<eric y='Y' x='X' xmlns='http://openuri.org/ericschema'>" +
- "<a/><b/><c/></eric>"
- };
-
- String ericSansY =
- "<eric xmlns='http://openuri.org/ericschema'>";
-
- String[] invalid = {
- "<foo/>",
- "<eric><a/><foo/><c/></eric>",
- eric + "text<a/><b/><c/></eric>",
- eric + "<a/>text<b/><c/></eric>",
- eric + "<a/><b/>text<c/></eric>",
- eric + "<a/><b/><c/>text</eric>",
- eric + "<a x='y'/><b/><c/>text</eric>",
- eric + "<a/><b/><boo xmlns='yaya'/><moo xmlns='yaya'/><c/></eric>",
- ericSansY + "<a/><b/><c/></eric>",
- "<eric y='' z='' xmlns='http://openuri.org/ericschema'>" +
- "<a/><b/><c/></eric>"
- };
-
- String[] schemas = { ericSchema, eric2Schema };
-
- doTest(
- schemas,
- new QName( "http://openuri.org/ericschema", "eric" ),
- valid, invalid );
- }
+ @Test
+ public void testValidate1() throws Exception {
+ String ericSchema =
+ "<xs:schema\n" +
+ " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
+ " xmlns:nw='http://openuri.org/ericschema'\n" +
+ " targetNamespace='http://openuri.org/ericschema'\n" +
+ " elementFormDefault='qualified'>\n" +
+ "\n" +
+ " <xs:complexType name='foo'>\n" +
+ " </xs:complexType>\n" +
+ "\n" +
+ " <xs:element name='foo' type='nw:foo'>\n" +
+ " </xs:element>\n" +
+ "\n" +
+ " <xs:element name='eric'>\n" +
+ " <xs:complexType>\n" +
+ " <xs:sequence>\n" +
+ " <xs:element name='a' maxOccurs='unbounded'/>\n" +
+ " <xs:element name='b' />\n" +
+ " <xs:any namespace='yaya' minOccurs='0' maxOccurs='1' processContents='lax'/>\n" +
+ " <xs:element name='c' />\n" +
+ " <xs:any minOccurs='0' maxOccurs='unbounded' processContents='strict'/>\n" +
+ " </xs:sequence>\n" +
+ " <xs:attribute name='x' use='optional'/>\n" +
+ " <xs:attribute name='y' use='required'/>\n" +
+ " <xs:attribute name='z' use='prohibited'/>\n" +
+ " </xs:complexType>\n" +
+ " </xs:element>\n" +
+ "" +
+ "</xs:schema>\n";
- public void testValidate2 ( )
- throws Exception
- {
- String bobSchema =
- "<xs:schema\n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " xmlns:bob='http://openuri.org/bobschema'\n" +
- " targetNamespace='http://openuri.org/bobschema'\n" +
- " elementFormDefault='qualified'>\n" +
- "\n" +
- " <xs:complexType name='biff'>\n" +
- " <xs:complexContent>\n" +
- " <xs:extension base='bob:foo'>\n" +
- " <xs:sequence>\n" +
- " <xs:element name='a' minOccurs='0' maxOccurs='unbounded'/>\n" +
- " </xs:sequence>\n" +
- " </xs:extension>\n" +
- " </xs:complexContent>\n" +
- " </xs:complexType>\n" +
- "" +
- " <xs:complexType name='foo'>\n" +
- " </xs:complexType>\n" +
- "" +
- " <xs:element name='foo' type='bob:foo'>\n" +
- " </xs:element>\n" +
- "" +
- "</xs:schema>\n";
-
- String xsiType = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
-
- String[] valid = {
- "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " +
- "xsi:type='bob:biff'><bob:a/><bob:a/><bob:a/></bob:foo>"
- };
-
- String[] invalid = {
- "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " +
- "xsi:type='bob:biff'><bob:q/></bob:foo>",
- "<bob:foo a='b' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " +
- "xsi:type='bob:biff'><bob:a/><bob:a/><bob:a/></bob:foo>"
- };
+ String eric2Schema =
+ "<xs:schema\n" +
+ " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
+ " xmlns:nw='http://openuri.org/ericschema2'\n" +
+ " xmlns:eric='http://openuri.org/ericschema'\n" +
+ " targetNamespace='http://openuri.org/ericschema2'\n" +
+ " elementFormDefault='qualified'>\n" +
+ "\n" +
+ " <xs:complexType name='eric2'>\n" +
+ " <xs:complexContent>\n" +
+ " <xs:extension base='eric:foo'>\n" +
+ " <xs:sequence>\n" +
+ " <xs:element name='a' maxOccurs='unbounded'/>\n" +
+ " </xs:sequence>\n" +
+ " </xs:extension>\n" +
+ " </xs:complexContent>\n" +
+ " </xs:complexType>\n" +
+ "</xs:schema>\n";
- String[] schemas = { bobSchema };
+ String eric = "<eric y='Y' xmlns='http://openuri.org/ericschema'>";
+ String eric2 = "<eric xmlns='http://openuri.org/ericschema2'>";
+ String xsi = "xmlns:eric2='http://openuri.org/ericschema2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
+
+ String[] valid = {
+ eric + "<a/><b/><c/><foo xsi:type='eric2:eric2' " +
+ xsi + "><a xmlns=\"http://openuri.org/ericschema2\"/></foo></eric>",
+ eric + "<a/><b/><boo xmlns='yaya'/><c/></eric>",
+ eric + "<a/><b/><c/></eric>",
+ eric + "<a x='y'/><b/><c/></eric>",
+ "<eric y='Y' x='X' xmlns='http://openuri.org/ericschema'>" +
+ "<a/><b/><c/></eric>"
+ };
+
+ String ericSansY =
+ "<eric xmlns='http://openuri.org/ericschema'>";
+
+ String[] invalid = {
+ "<foo/>",
+ "<eric><a/><foo/><c/></eric>",
+ eric + "text<a/><b/><c/></eric>",
+ eric + "<a/>text<b/><c/></eric>",
+ eric + "<a/><b/>text<c/></eric>",
+ eric + "<a/><b/><c/>text</eric>",
+ eric + "<a x='y'/><b/><c/>text</eric>",
+ eric + "<a/><b/><boo xmlns='yaya'/><moo xmlns='yaya'/><c/></eric>",
+ ericSansY + "<a/><b/><c/></eric>",
+ "<eric y='' z='' xmlns='http://openuri.org/ericschema'>" +
+ "<a/><b/><c/></eric>"
+ };
+
+ String[] schemas = {ericSchema, eric2Schema};
+
+ doTest(
+ schemas,
+ new QName("http://openuri.org/ericschema", "eric"),
+ valid, invalid);
+ }
- doTest( schemas, null, valid, invalid );
- }
+ @Test
+ public void testValidate2() throws Exception {
+ String bobSchema =
+ "<xs:schema\n" +
+ " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
+ " xmlns:bob='http://openuri.org/bobschema'\n" +
+ " targetNamespace='http://openuri.org/bobschema'\n" +
+ " elementFormDefault='qualified'>\n" +
+ "\n" +
+ " <xs:complexType name='biff'>\n" +
+ " <xs:complexContent>\n" +
+ " <xs:extension base='bob:foo'>\n" +
+ " <xs:sequence>\n" +
+ " <xs:element name='a' minOccurs='0' maxOccurs='unbounded'/>\n" +
+ " </xs:sequence>\n" +
+ " </xs:extension>\n" +
+ " </xs:complexContent>\n" +
+ " </xs:complexType>\n" +
+ "" +
+ " <xs:complexType name='foo'>\n" +
+ " </xs:complexType>\n" +
+ "" +
+ " <xs:element name='foo' type='bob:foo'>\n" +
+ " </xs:element>\n" +
+ "" +
+ "</xs:schema>\n";
- String ns =
- "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
- "xmlns:xs='http://www.w3.org/2001/XMLSchema'";
-
- public void testValidate3 ( )
- throws Exception
- {
- String schema =
- "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
- "" +
- " <xs:simpleType name='allNNI'>\n" +
- " <xs:annotation><xs:documentation>\n" +
- " for maxOccurs</xs:documentation></xs:annotation>\n" +
- " <xs:union memberTypes='xs:nonNegativeInteger'>\n" +
- " <xs:simpleType>\n" +
- " <xs:restriction base='xs:NMTOKEN'>\n" +
- " <xs:enumeration value='unbounded'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- " </xs:union>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='ericBase64Binary'>\n" +
- " <xs:restriction base='xs:base64Binary'>\n" +
- " <xs:enumeration value='Eric'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='abcdHexBinary'>\n" +
- " <xs:restriction base='xs:hexBinary'>\n" +
- " <xs:enumeration value='abcd'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='zeroNumber'>\n" +
- " <xs:restriction base='number'>\n" +
- " <xs:enumeration value='Zero'/>\n" +
- " <xs:enumeration value='0'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='number'>\n" +
- " <xs:union>\n" +
- " <xs:simpleType>\n" +
- " <xs:restriction base='xs:decimal'/>\n" +
- " </xs:simpleType>\n" +
- " <xs:simpleType>\n" +
- " <xs:restriction base='xs:string'>\n" +
- " <xs:whiteSpace value='collapse'/>\n" +
- " <xs:enumeration value='Zero'/>\n" +
- " <xs:enumeration value='One'/>\n" +
- " <xs:enumeration value='Two'/>\n" +
- " <xs:enumeration value='Three'/>\n" +
- " <xs:enumeration value='Many'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- " </xs:union>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='listOfInt'>\n" +
- " <xs:list itemType='xs:int'/>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='listOfPrime'>\n" +
- " <xs:list itemType='prime'/>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='ericBrother'>\n" +
- " <xs:restriction base='xs:string'>\n" +
- " <xs:whiteSpace value='collapse'/>\n" +
- " <xs:enumeration value='Brian'/>\n" +
- " <xs:enumeration value='Kevin'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='ericBrothers'>\n" +
- " <xs:list itemType='ericBrother'/>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='weekString'>\n" +
- " <xs:restriction base='xs:string'>\n" +
- " <xs:whiteSpace value='collapse'/>\n" +
- " <xs:enumeration value='Monday'/>\n" +
- " <xs:enumeration value='Tuesday'/>\n" +
- " <xs:enumeration value='Wednesday'/>\n" +
- " <xs:enumeration value='Thursday'/>\n" +
- " <xs:enumeration value='Friday'/>\n" +
- " <xs:enumeration value='Saturday'/>\n" +
- " <xs:enumeration value='Sunday'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='aYear'>\n" +
- " <xs:restriction base='xs:duration'>\n" +
- " <xs:enumeration value='P1Y'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='ericBDay'>\n" +
- " <xs:restriction base='xs:date'>\n" +
- " <xs:enumeration value='1965-06-10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='youngerThanEric'>\n" +
- " <xs:restriction base='xs:date'>\n" +
- " <xs:minExclusive value='1965-06-10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='fiveCharQname'>\n" +
- " <xs:restriction base='xs:QName'>\n" +
- " <xs:length value='5'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='wackyQname'>\n" +
- " <xs:restriction base='xs:QName'>\n" +
- " <xs:minLength value='3'/>\n" +
- " <xs:maxLength value='10'/>\n" +
- " <xs:pattern value='[xs:abcde]*'/>\n" +
- " <xs:enumeration value='xs:abc'/>\n" +
- " <xs:enumeration value='xs:bcd'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='fiveCharAnyURI'>\n" +
- " <xs:restriction base='xs:anyURI'>\n" +
- " <xs:length value='5'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='wackyAnyURI'>\n" +
- " <xs:restriction base='xs:anyURI'>\n" +
- " <xs:minLength value='3'/>\n" +
- " <xs:maxLength value='10'/>\n" +
- " <xs:enumeration value='foo'/>\n" +
- " <xs:enumeration value='bar'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='bit'>\n" +
- " <xs:restriction base='xs:boolean'>\n" +
- " <xs:pattern value='1|0'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='evenInteger'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:pattern value='[0-9]*[02468]'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='prime'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:pattern value='[0-9]*[13579]'/>\n" +
- " <xs:enumeration value='3'/>\n" +
- " <xs:enumeration value='5'/>\n" +
- " <xs:enumeration value='7'/>\n" +
- " <xs:enumeration value='11'/>\n" +
- " <xs:enumeration value='13'/>\n" +
- " <xs:enumeration value='17'/>\n" +
- " <xs:enumeration value='19'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='fourCharString'>\n" +
- " <xs:restriction base='xs:string'>\n" +
- " <xs:length value='4'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='threeOrMoreCharString'>\n" +
- " <xs:restriction base='xs:string'>\n" +
- " <xs:minLength value='3'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='fiveOrLessCharString'>\n" +
- " <xs:restriction base='xs:string'>\n" +
- " <xs:maxLength value='5'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='fiveTotalDigits'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:totalDigits value='5'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='threeFractionDigits'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:fractionDigits value='3'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMinExclusive'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:minExclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMaxExclusive'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:maxExclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMaxInclusive'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:maxInclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMinInclusive'>\n" +
- " <xs:restriction base='xs:decimal'>\n" +
- " <xs:minInclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMinExclusiveFloat'>\n" +
- " <xs:restriction base='xs:float'>\n" +
- " <xs:minExclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMaxExclusiveFloat'>\n" +
- " <xs:restriction base='xs:float'>\n" +
- " <xs:maxExclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMaxInclusiveFloat'>\n" +
- " <xs:restriction base='xs:float'>\n" +
- " <xs:maxInclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMinInclusiveFloat'>\n" +
- " <xs:restriction base='xs:float'>\n" +
- " <xs:minInclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "\n" +
- " <xs:simpleType name='tenMinExclusiveDouble'>\n" +
- " <xs:restriction base='xs:double'>\n" +
- " <xs:minExclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMaxExclusiveDouble'>\n" +
- " <xs:restriction base='xs:double'>\n" +
- " <xs:maxExclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMaxInclusiveDouble'>\n" +
- " <xs:restriction base='xs:double'>\n" +
- " <xs:maxInclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "" +
- " <xs:simpleType name='tenMinInclusiveDouble'>\n" +
- " <xs:restriction base='xs:double'>\n" +
- " <xs:minInclusive value='10'/>\n" +
- " </xs:restriction>\n" +
- " </xs:simpleType>\n" +
- "\n" +
- " <xs:element name='any'>\n" +
- " </xs:element>\n" +
- "" +
- " <xs:element name='default_12345' default='12345'>\n" +
- " </xs:element>\n" +
- "" +
- " <xs:element name='default_1234' default='1234'>\n" +
- " </xs:element>\n" +
- "" +
- " <xs:element name='default_eric' default='eric'>\n" +
- " </xs:element>\n" +
- "" +
- "</xs:schema>\n";
-
- String[] valid = {
- "<any " + ns + " xsi:type='threeFractionDigits'>.1</any>",
- "<any " + ns + " xsi:type='threeFractionDigits'>.12</any>",
- "<any " + ns + " xsi:type='threeFractionDigits'>.123</any>",
-
- "<any " + ns + " xsi:type='allNNI'>unbounded</any>",
- "<any " + ns + " xsi:type='allNNI'>0</any>",
- "<any " + ns + " xsi:type='allNNI'>1</any>",
-
- "<any " + ns + " xsi:type='xs:base64Binary'>CAFEBABE</any>",
- "<any " + ns + " xsi:type='abcdHexBinary'>abcd</any>",
-
- "<any " + ns + " xsi:type='xs:base64Binary'>abcdefgh</any>",
- "<any " + ns + " xsi:type='ericBase64Binary'>Eric</any>",
-
- "<any " + ns + " xsi:type='zeroNumber'> Zero</any>",
- "<any " + ns + " xsi:type='zeroNumber'>Zero</any>",
- "<any " + ns + " xsi:type='zeroNumber'>0</any>",
-
- "<any " + ns + " xsi:type='number'>1</any>",
- "<any " + ns + " xsi:type='number'> 1 </any>",
- "<any " + ns + " xsi:type='number'>Two</any>",
- "<any " + ns + " xsi:type='number'> Three </any>",
-
- "<any " + ns + " xsi:type='ericBrothers'></any>",
- "<any " + ns + " xsi:type='ericBrothers'>Brian</any>",
- "<any " + ns + " xsi:type='ericBrothers'>Kevin</any>",
- "<any " + ns + " xsi:type='ericBrothers'>Kevin Brian</any>",
- "<any " + ns + " xsi:type='ericBrothers'>Brian Kevin</any>",
-
- "<any " + ns + " xsi:type='listOfInt'> 1 22 333 4444 </any>",
- "<any " + ns + " xsi:type='listOfInt'></any>",
- "<any " + ns + " xsi:type='listOfInt'>5999</any>",
-
- "<any " + ns + " xsi:type='aYear'>P1Y</any>",
-
- "<any " + ns + " xsi:type='fiveCharAnyURI'>abcde</any>",
- "<any " + ns + " xsi:type='fiveCharQname'>xs:abc</any>",
- "<any " + ns + " xsi:type='xs:anyURI'>foo</any>",
- "<any " + ns + " xsi:type='wackyAnyURI'>foo</any>",
-
- "<any " + ns + " xsi:type='youngerThanEric'>1965-06-11</any>",
- "<any " + ns + " xsi:type='ericBDay'>1965-06-10</any>",
- "<any " + ns + " xsi:type='xs:dateTime'>1999-05-31T13:20:00-05:00</any>",
- "<any " + ns + " xsi:type='xs:time'>00:00:00</any>",
- "<any " + ns + " xsi:type='xs:time'>13:20:00-05:00</any>",
-
- "<any " + ns + " xsi:type='wackyQname'>xs:abc</any>",
- "<any " + ns + " xsi:type='fiveCharQname'>abcde</any>",
- "<any " + ns + " xsi:type='fiveCharQname'>xs:ab</any>",
- "<any " + ns + " xsi:type='prime'>3</any>",
- "<any " + ns + " xsi:type='prime'>11</any>",
- "<any " + ns + " xsi:type='xs:integer'>+45</any>",
- "<any " + ns + " xsi:type='xs:integer'>1</any>",
- "<any " + ns + " xsi:type='xs:integer'>0</any>",
- "<any " + ns + " xsi:type='xs:integer'>-1</any>",
- "<any " + ns + " xsi:type='xs:integer'>-1</any>",
- "<any " + ns + " xsi:type='xs:integer'>489743579837589743434</any>",
- "<any " + ns + " xsi:type='xs:boolean'>1</any>",
- "<default_1234 " + ns + " xsi:type='evenInteger'></default_1234>",
- "<any " + ns + " xsi:type='evenInteger'>12</any>",
- "<any " + ns + " xsi:type='bit'>1</any>",
- "<any " + ns + " xsi:type='bit'>0</any>",
- "<any " + ns + " xsi:type='xs:boolean'>false</any>",
- "<any " + ns + " xsi:type='evenInteger'>0</any>",
- "<any " + ns + " xsi:type='weekString'>Monday</any>",
- "<any " + ns + " xsi:type='weekString'>Sunday</any>",
- "<any " + ns + " xsi:type='weekString'> Thursday </any>",
-
- "<any " + ns + " xsi:type='tenMinExclusive'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxExclusive'>9.9</any>",
- "<any " + ns + " xsi:type='tenMinInclusive'>10</any>",
- "<any " + ns + " xsi:type='tenMinInclusive'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxInclusive'>10</any>",
- "<any " + ns + " xsi:type='tenMaxInclusive'>9.9</any>",
-
- "<any " + ns + " xsi:type='tenMinExclusiveFloat'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxExclusiveFloat'>9.9</any>",
- "<any " + ns + " xsi:type='tenMinInclusiveFloat'>10</any>",
- "<any " + ns + " xsi:type='tenMinInclusiveFloat'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxInclusiveFloat'>10</any>",
- "<any " + ns + " xsi:type='tenMaxInclusiveFloat'>9.9</any>",
-
- "<any " + ns + " xsi:type='tenMinExclusiveDouble'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxExclusiveDouble'>9.9</any>",
- "<any " + ns + " xsi:type='tenMinInclusiveDouble'>10</any>",
- "<any " + ns + " xsi:type='tenMinInclusiveDouble'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxInclusiveDouble'>10</any>",
- "<any " + ns + " xsi:type='tenMaxInclusiveDouble'>9.9</any>",
-
- "<any " + ns + " xsi:type='fourCharString'>eric</any>",
- "<any " + ns + " xsi:type='threeOrMoreCharString'>12345</any>",
- "<any " + ns + " xsi:type='fiveOrLessCharString'>1234</any>",
- "<any " + ns + " xsi:type='fiveTotalDigits'>12345</any>",
- "<any " + ns + " xsi:type='fiveTotalDigits'>1234</any>",
- "<default_1234 " + ns + " xsi:type='evenInteger'>\n\n</default_1234>"
- };
-
- String[] invalid = {
- "<any " + ns + " xsi:type='allNNI'>foo</any>",
- "<any " + ns + " xsi:type='xs:hexBinary'>P</any>",
- "<any " + ns + " xsi:type='xs:hexBinary'>CAFEBABP</any>",
- "<any " + ns + " xsi:type='abcdHexBinary'>abce</any>",
-
- "<any " + ns + " xsi:type='xs:base64Binary'>abcde</any>",
- "<any " + ns + " xsi:type='ericBase64Binary'>Erik</any>",
-
- "<any " + ns + " xsi:type='zeroNumber'>One</any>",
- "<any " + ns + " xsi:type='zeroNumber'>Twenty</any>",
-
- "<any " + ns + " xsi:type='number'>Seven</any>",
- "<any " + ns + " xsi:type='number'>Bob</any>",
- "<any " + ns + " xsi:type='number'></any>",
-
- "<any " + ns + " xsi:type='ericBrothers'>1</any>",
- "<any " + ns + " xsi:type='ericBrothers'>Bob</any>",
- "<any " + ns + " xsi:type='ericBrothers'>Ralph Frank</any>",
-
- "<any " + ns + " xsi:type='listOfInt'> 1 22 333 Eric </any>",
- "<any " + ns + " xsi:type='listOfInt'>Eric</any>",
- "<any " + ns + " xsi:type='listOfInt'>-</any>",
-
- "<any " + ns + " xsi:type='aYear'>P2Y</any>",
-
- "<any " + ns + " xsi:type='youngerThanEric'>1965-06-10</any>",
- "<any " + ns + " xsi:type='ericBDay'>1985-06-10</any>",
- "<any " + ns + " xsi:type='xs:dateTime'>xx1999-05-31T13:20:00-05:00</any>",
- "<any " + ns + " xsi:type='xs:dateTime'>eric</any>",
- "<any " + ns + " xsi:type='xs:time'>99:99:00</any>",
- "<any " + ns + " xsi:type='xs:time'>13:20:00-99:00</any>",
-
- "<any " + ns + " xsi:type='wackyAnyURI'>moo</any>",
- "<any " + ns + " xsi:type='fiveCharAnyURI'>ab</any>",
-
- "<any " + ns + " xsi:type='wackyQname'>xs:abcdefghijk</any>",
- "<any " + ns + " xsi:type='wackyQname'>xs:pqr</any>",
- "<any " + ns + " xsi:type='xs:QName'>foo:bar</any>",
- "<any " + ns + " xsi:type='prime'>12</any>",
- "<any " + ns + " xsi:type='prime'>6</any>",
- "<any " + ns + " xsi:type='xs:integer'>foo</any>",
- "<any " + ns + " xsi:type='xs:integer'>.1</any>",
- "<any " + ns + " xsi:type='evenInteger'>1</any>",
- "<any " + ns + " xsi:type='bit'>true</any>",
- "<any " + ns + " xsi:type='bit'>false</any>",
- "<any " + ns + " xsi:type='bit'>nibble</any>",
- "<any " + ns + " xsi:type='bit'>2</any>",
- "<any " + ns + " xsi:type='xs:boolean'>blurf</any>",
- "<any " + ns + " xsi:type='xs:boolean'></any>",
- "<any " + ns + " xsi:type='evenInteger'></any>",
- "<any " + ns + " xsi:type='weekString'>Monday Sucks</any>",
-
- "<any " + ns + " xsi:type='tenMaxExclusive'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxExclusive'>10</any>",
- "<any " + ns + " xsi:type='tenMinExclusive'>10</any>",
- "<any " + ns + " xsi:type='tenMinExclusive'>9.9</any>",
- "<any " + ns + " xsi:type='tenMinInclusive'>9.9</any>",
- "<any " + ns + " xsi:type='tenMaxInclusive'>10.1</any>",
-
- "<any " + ns + " xsi:type='tenMaxExclusiveFloat'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxExclusiveFloat'>10</any>",
- "<any " + ns + " xsi:type='tenMinExclusiveFloat'>10</any>",
- "<any " + ns + " xsi:type='tenMinExclusiveFloat'>9.9</any>",
- "<any " + ns + " xsi:type='tenMinInclusiveFloat'>9.9</any>",
- "<any " + ns + " xsi:type='tenMaxInclusiveFloat'>10.1</any>",
-
- "<any " + ns + " xsi:type='tenMaxExclusiveDouble'>10.1</any>",
- "<any " + ns + " xsi:type='tenMaxExclusiveDouble'>10</any>",
- "<any " + ns + " xsi:type='tenMinExclusiveDouble'>10</any>",
- "<any " + ns + " xsi:type='tenMinExclusiveDouble'>9.9</any>",
- "<any " + ns + " xsi:type='tenMinInclusiveDouble'>9.9</any>",
- "<any " + ns + " xsi:type='tenMaxInclusiveDouble'>10.1</any>",
-
- "<any " + ns + " xsi:type='fiveOrLessCharString'> 1234 </any>",
- "<any " + ns + " xsi:type='fiveTotalDigits'>123456</any>",
- "<any " + ns + " xsi:type='fourCharString'>vasilik</any>",
- "<any " + ns + " xsi:type='threeOrMoreCharString'>1</any>",
- "<any " + ns + " xsi:type='fiveOrLessCharString'>1234567</any>",
- "<any " + ns + " xsi:type='threeFractionDigits'>.1234</any>",
- "<any " + ns + " xsi:type='fourCharString'> eric </any>",
-
- "<default_12345 " + ns + " xsi:type='evenInteger'></default_12345>",
- "<default_12345 " + ns + " xsi:type='evenInteger'>\n\n</default_12345>"
- };
+ String[] valid = {
+ "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " +
+ "xsi:type='bob:biff'><bob:a/><bob:a/><bob:a/></bob:foo>"
+ };
+
+ String[] invalid = {
+ "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " +
+ "xsi:type='bob:biff'><bob:q/></bob:foo>",
+ "<bob:foo a='b' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " +
+ "xsi:type='bob:biff'><bob:a/><bob:a/><bob:a/></bob:foo>"
+ };
- String[] schemas = { schema };
+ String[] schemas = {bobSchema};
- doTest( schemas, null, valid, invalid );
- }
+ doTest(schemas, null, valid, invalid);
+ }
+ @Test
+ public void testValidate3() throws Exception {
+ String schema =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ "" +
+ " <xs:simpleType name='allNNI'>\n" +
+ " <xs:annotation><xs:documentation>\n" +
+ " for maxOccurs</xs:documentation></xs:annotation>\n" +
+ " <xs:union memberTypes='xs:nonNegativeInteger'>\n" +
+ " <xs:simpleType>\n" +
+ " <xs:restriction base='xs:NMTOKEN'>\n" +
+ " <xs:enumeration value='unbounded'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ " </xs:union>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='ericBase64Binary'>\n" +
+ " <xs:restriction base='xs:base64Binary'>\n" +
+ " <xs:enumeration value='Eric'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='abcdHexBinary'>\n" +
+ " <xs:restriction base='xs:hexBinary'>\n" +
+ " <xs:enumeration value='abcd'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='zeroNumber'>\n" +
+ " <xs:restriction base='number'>\n" +
+ " <xs:enumeration value='Zero'/>\n" +
+ " <xs:enumeration value='0'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='number'>\n" +
+ " <xs:union>\n" +
+ " <xs:simpleType>\n" +
+ " <xs:restriction base='xs:decimal'/>\n" +
+ " </xs:simpleType>\n" +
+ " <xs:simpleType>\n" +
+ " <xs:restriction base='xs:string'>\n" +
+ " <xs:whiteSpace value='collapse'/>\n" +
+ " <xs:enumeration value='Zero'/>\n" +
+ " <xs:enumeration value='One'/>\n" +
+ " <xs:enumeration value='Two'/>\n" +
+ " <xs:enumeration value='Three'/>\n" +
+ " <xs:enumeration value='Many'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ " </xs:union>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='listOfInt'>\n" +
+ " <xs:list itemType='xs:int'/>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='listOfPrime'>\n" +
+ " <xs:list itemType='prime'/>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='ericBrother'>\n" +
+ " <xs:restriction base='xs:string'>\n" +
+ " <xs:whiteSpace value='collapse'/>\n" +
+ " <xs:enumeration value='Brian'/>\n" +
+ " <xs:enumeration value='Kevin'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='ericBrothers'>\n" +
+ " <xs:list itemType='ericBrother'/>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='weekString'>\n" +
+ " <xs:restriction base='xs:string'>\n" +
+ " <xs:whiteSpace value='collapse'/>\n" +
+ " <xs:enumeration value='Monday'/>\n" +
+ " <xs:enumeration value='Tuesday'/>\n" +
+ " <xs:enumeration value='Wednesday'/>\n" +
+ " <xs:enumeration value='Thursday'/>\n" +
+ " <xs:enumeration value='Friday'/>\n" +
+ " <xs:enumeration value='Saturday'/>\n" +
+ " <xs:enumeration value='Sunday'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='aYear'>\n" +
+ " <xs:restriction base='xs:duration'>\n" +
+ " <xs:enumeration value='P1Y'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='ericBDay'>\n" +
+ " <xs:restriction base='xs:date'>\n" +
+ " <xs:enumeration value='1965-06-10'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='youngerThanEric'>\n" +
+ " <xs:restriction base='xs:date'>\n" +
+ " <xs:minExclusive value='1965-06-10'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='fiveCharQname'>\n" +
+ " <xs:restriction base='xs:QName'>\n" +
+ " <xs:length value='5'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='wackyQname'>\n" +
+ " <xs:restriction base='xs:QName'>\n" +
+ " <xs:minLength value='3'/>\n" +
+ " <xs:maxLength value='10'/>\n" +
+ " <xs:pattern value='[xs:abcde]*'/>\n" +
+ " <xs:enumeration value='xs:abc'/>\n" +
+ " <xs:enumeration value='xs:bcd'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='fiveCharAnyURI'>\n" +
+ " <xs:restriction base='xs:anyURI'>\n" +
+ " <xs:length value='5'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='wackyAnyURI'>\n" +
+ " <xs:restriction base='xs:anyURI'>\n" +
+ " <xs:minLength value='3'/>\n" +
+ " <xs:maxLength value='10'/>\n" +
+ " <xs:enumeration value='foo'/>\n" +
+ " <xs:enumeration value='bar'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='bit'>\n" +
+ " <xs:restriction base='xs:boolean'>\n" +
+ " <xs:pattern value='1|0'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='evenInteger'>\n" +
+ " <xs:restriction base='xs:decimal'>\n" +
+ " <xs:pattern value='[0-9]*[02468]'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='prime'>\n" +
+ " <xs:restriction base='xs:decimal'>\n" +
+ " <xs:pattern value='[0-9]*[13579]'/>\n" +
+ " <xs:enumeration value='3'/>\n" +
+ " <xs:enumeration value='5'/>\n" +
+ " <xs:enumeration value='7'/>\n" +
+ " <xs:enumeration value='11'/>\n" +
+ " <xs:enumeration value='13'/>\n" +
+ " <xs:enumeration value='17'/>\n" +
+ " <xs:enumeration value='19'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='fourCharString'>\n" +
+ " <xs:restriction base='xs:string'>\n" +
+ " <xs:length value='4'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='threeOrMoreCharString'>\n" +
+ " <xs:restriction base='xs:string'>\n" +
+ " <xs:minLength value='3'/>\n" +
+ " </xs:restriction>\n" +
+ " </xs:simpleType>\n" +
+ "" +
+ " <xs:simpleType name='fiveOrLessCharString'>\n" +
[... 1723 lines stripped ...]
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org