[jboss-svn-commits] JBoss Common SVN: r3218 - in jbossxb/trunk/src: test/java/org/jboss/test/xb/validator and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jun 4 05:21:47 EDT 2009


Author: alex.loubyansky at jboss.com
Date: 2009-06-04 05:21:47 -0400 (Thu, 04 Jun 2009)
New Revision: 3218

Added:
   jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/
   jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ValidatorTestRoot.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xml
   jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xsd
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/util/SchemaBindingValidator.java
Log:
JBXB-203

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/util/SchemaBindingValidator.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/util/SchemaBindingValidator.java	2009-06-04 09:19:15 UTC (rev 3217)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/util/SchemaBindingValidator.java	2009-06-04 09:21:47 UTC (rev 3218)
@@ -325,6 +325,7 @@
             ElementBinding elementBinding = schemaBinding.getElement(elementQName);
             if (elementBinding == null)
                handleError("ElementBinding " + elementQName + " is not found in the SchemaBinding.");
+            validate(xsElement.getTypeDefinition(), elementBinding.getType());
          }
       }
       finally
@@ -351,7 +352,10 @@
    public void validate(XSTypeDefinition xsType, TypeBinding typeBinding)
    {
       if(xsType.getName() == null)
-         handleError("XSD type is anonymous but TypeBinding has QName " + typeBinding.getQName());
+      {
+         if(typeBinding.getQName() != null)
+            handleError("XSD type is anonymous but TypeBinding has QName " + typeBinding.getQName());
+      }
       else
       {
          if(excludedNs.contains(xsType.getNamespace()))

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ValidatorTestRoot.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ValidatorTestRoot.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/support/ValidatorTestRoot.java	2009-06-04 09:21:47 UTC (rev 3218)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.validator.support;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * A ValidatorTestRoot.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlSchema(namespace="urn:jboss:xb:test", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="root", namespace="urn:jboss:xb:test")
+ at XmlType(propOrder={"e1", "e2"}, name="")
+public class ValidatorTestRoot
+{
+   private String e1;
+   private String e2;
+   
+   @XmlElement(name="e")
+   public String getE1()
+   {
+      return e1;
+   }
+   
+   public void setE1(String e1)
+   {
+      this.e1 = e1;
+   }
+   
+   public String getE2()
+   {
+      return e2;
+   }
+   
+   public void setE2(String e2)
+   {
+      this.e2 = e2;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.java	2009-06-04 09:21:47 UTC (rev 3218)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.validator.test;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.validator.support.ValidatorTestRoot;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.resolver.MultiClassSchemaResolver;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+
+/**
+ * A ValidatingResolverUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class ValidatingResolverUnitTestCase extends AbstractBuilderTest
+{
+   public ValidatingResolverUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testInvalidBinding() throws Exception
+   {
+      MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
+      resolver.mapURIToClass("urn:jboss:xb:test", ValidatorTestRoot.class);
+      String xsd = findXML("ValidatingResolverUnitTestCase.xsd");
+      resolver.mapSchemaLocation("urn:jboss:xb:test", xsd);      
+      resolver.setValidateBinding(true);
+      
+      try
+      {
+         unmarshal("ValidatingResolverUnitTestCase.xml", ValidatorTestRoot.class, resolver);
+         fail("Validation expected to fail");
+      }
+      catch(JBossXBException e)
+      {
+         String msg;
+         if(JBossXBBuilder.isUseUnorderedSequence())
+            msg = "ElementBinding {urn:jboss:xb:test}e is missing: [{urn:jboss:xb:test}e2, {urn:jboss:xb:test}e1]";
+         else
+            msg = "Compared elements have different names: XSD QName is {urn:jboss:xb:test}e1, ElementBinding QName is {urn:jboss:xb:test}e";
+         assertEquals(msg, e.getCause().getMessage());
+      }
+   }
+}

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xml	2009-06-04 09:21:47 UTC (rev 3218)
@@ -0,0 +1,4 @@
+<root xmlns="urn:jboss:xb:test">
+   <e1>1</e1>
+   <e2>2</e2>
+</root>

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xsd
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xsd	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/validator/test/ValidatingResolverUnitTestCase.xsd	2009-06-04 09:21:47 UTC (rev 3218)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<xsd:schema
+   targetNamespace="urn:jboss:xb:test"
+   xmlns="urn:jboss:xb:test"
+   elementFormDefault="qualified"
+   attributeFormDefault="unqualified"
+   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+  <xsd:element name="root">
+    <xsd:complexType>
+      <xsd:sequence>
+
+        <xsd:element name="e1" type="xsd:string"/>
+        <xsd:element name="e2" type="xsd:string"/>
+
+      </xsd:sequence>
+    </xsd:complexType>
+  </xsd:element>
+
+</xsd:schema>




More information about the jboss-svn-commits mailing list