xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ce...@apache.org
Subject svn commit: r160344 - in xmlbeans/trunk/test: cases/xbean/scomp/element/NillTest.xsd src/compile/scomp/checkin/XmlBeansCompCheckinTests.java src/scomp/elements/detailed/GlobalEltNillable.java src/scomp/elements/detailed/NillTest.java src/scomp/idConstraint/detailed/KeyKeyref.java
Date Wed, 06 Apr 2005 23:52:40 GMT
Author: cezar
Date: Wed Apr  6 16:52:38 2005
New Revision: 160344

URL: http://svn.apache.org/viewcvs?view=rev&rev=160344
Log:
Contributed By Rajiv Balachandran -  Changed/Added tests for Nillable functionality and modified
checkintest to reflect revision 160341

Modified:
    xmlbeans/trunk/test/cases/xbean/scomp/element/NillTest.xsd
    xmlbeans/trunk/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java
    xmlbeans/trunk/test/src/scomp/elements/detailed/GlobalEltNillable.java
    xmlbeans/trunk/test/src/scomp/elements/detailed/NillTest.java
    xmlbeans/trunk/test/src/scomp/idConstraint/detailed/KeyKeyref.java

Modified: xmlbeans/trunk/test/cases/xbean/scomp/element/NillTest.xsd
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/cases/xbean/scomp/element/NillTest.xsd?view=diff&r1=160343&r2=160344
==============================================================================
--- xmlbeans/trunk/test/cases/xbean/scomp/element/NillTest.xsd (original)
+++ xmlbeans/trunk/test/cases/xbean/scomp/element/NillTest.xsd Wed Apr  6 16:52:38 2005
@@ -9,6 +9,7 @@
         <xs:sequence>
             <xs:element name="firstName" type="xs:string" minOccurs="0"/>
             <xs:element name="lastName" type="xs:string" minOccurs="0"/>
+            <xs:element name="LocalNillableElem" type="xs:string" nillable="true"/>
             <xs:element name="address" type="AddressInfo" minOccurs="0"/>
         </xs:sequence>
     </xs:complexType>
@@ -28,6 +29,9 @@
     </xs:element>
 
     <xs:element name="GlobalEltNotNillable" type="xs:string"/>
+    <xs:element name="GlobalEltNillable" type="xs:string" nillable="true"/>
+    <xs:element name="GlobalEltDefault" type="xs:integer" default="10"/>
+    <xs:element name="GlobalEltFixed" type="xs:integer" fixed="7"  />
 
 
 </xs:schema>

Modified: xmlbeans/trunk/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java?view=diff&r1=160343&r2=160344
==============================================================================
--- xmlbeans/trunk/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java (original)
+++ xmlbeans/trunk/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java Wed Apr  6
16:52:38 2005
@@ -292,9 +292,8 @@
             System.err.println(iaEx.getMessage());
         }
 
-        if (!iArgExThrown)
-            throw new Exception("All null values did not throw Illegal " +
-                    "Argument Exception");
+        // svn revision 160341. SchemaTypeLoader is not expected to non null any more. All
params can be null
+        assertFalse(iArgExThrown);
 
         iArgExThrown = false;
         try {
@@ -306,9 +305,8 @@
             System.err.println(iaEx.getMessage());
         }
 
-        if (!iArgExThrown)
-            throw new Exception("XSD[] and null values did not throw Illegal " +
-                    "Argument Exception");
+        // svn revision 160341. SchemaTypeLoader is not expected to non null any more
+        assertFalse(iArgExThrown);
 
     }
 

Modified: xmlbeans/trunk/test/src/scomp/elements/detailed/GlobalEltNillable.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/scomp/elements/detailed/GlobalEltNillable.java?view=diff&r1=160343&r2=160344
==============================================================================
--- xmlbeans/trunk/test/src/scomp/elements/detailed/GlobalEltNillable.java (original)
+++ xmlbeans/trunk/test/src/scomp/elements/detailed/GlobalEltNillable.java Wed Apr  6 16:52:38
2005
@@ -19,6 +19,7 @@
 import xbean.scomp.element.globalEltNillable.*;
 import org.apache.xmlbeans.impl.values.XmlValueNotNillableException;
 import org.apache.xmlbeans.XmlErrorCodes;
+import org.apache.xmlbeans.XmlOptions;
 
 /**
  *
@@ -55,8 +56,13 @@
      * @throws Exception
      */
     public void testNotNillable() throws Exception {
+
+        // XmlValueNotNillableException should be thrown only when validateOnSet property
is set
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
         GlobalEltNotNillableDocument testElt = GlobalEltNotNillableDocument
-                .Factory.newInstance();
+                .Factory.newInstance(options);
         try {
             testElt.setNil();
             fail("Expected XmlValueNotNillableException");
@@ -93,12 +99,13 @@
         GlobalEltNillableFixedDocument testElt = GlobalEltNillableFixedDocument
                 .Factory.parse("<GlobalEltNillableFixed" +
                 "   xmlns=\"http://xbean/scomp/element/GlobalEltNillable\"" +
-                "  xsi:nillable=\"true\"" +
+                "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+                "   xsi:nil=\"true\"" +
                 "/>");
-        assertTrue(!testElt.validate(validateOptions));
+        assertFalse(testElt.validate(validateOptions));
         assertEquals(1, errorList.size());
         showErrors();
-               String[] errExpected = new String[]{"cvc-elt3.3.4"};
+               String[] errExpected = new String[]{XmlErrorCodes.ELEM_LOCALLY_VALID$NIL_WITH_FIXED};
                     assertTrue(compareErrorCodes(errExpected));
 
 

Modified: xmlbeans/trunk/test/src/scomp/elements/detailed/NillTest.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/scomp/elements/detailed/NillTest.java?view=diff&r1=160343&r2=160344
==============================================================================
--- xmlbeans/trunk/test/src/scomp/elements/detailed/NillTest.java (original)
+++ xmlbeans/trunk/test/src/scomp/elements/detailed/NillTest.java Wed Apr  6 16:52:38 2005
@@ -15,11 +15,11 @@
 package scomp.elements.detailed;
 
 import scomp.common.BaseCase;
-import xbean.scomp.element.nillTest.Contact;
-import xbean.scomp.element.nillTest.AddressInfo;
-import xbean.scomp.element.nillTest.CityNameDocument;
-import xbean.scomp.element.nillTest.GlobalEltNotNillableDocument;
+import xbean.scomp.element.nillTest.*;
 import org.apache.xmlbeans.impl.values.XmlValueNotNillableException;
+import org.apache.xmlbeans.XmlOptions;
+
+import java.math.BigInteger;
 
 
 /**
@@ -36,33 +36,183 @@
      * XXX attribute/element and if the container is an
      * element, will also add the "xsi:nil" attribute.
      */
-    public void testNillable() {
-        Contact contact = Contact.Factory.newInstance();
+    // for all nillable tests, the validation falls thro only if the ValidateOnSet option
is turned on
+    public void testNotNillableLocalElem() {
+
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
+        // local element, not nillable. If setXXX is set to null & validateOnSet is true,
it should throw XmlValueNotNillableException
+        Contact contact = Contact.Factory.newInstance(options);
+        try{
+            contact.setFirstName(null);
+            fail("XmlValueNotNillableException Expected here");
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+        }
+
+        // with validate turned off, this should to thro
+        Contact contactWithValidateOff = Contact.Factory.newInstance(options);
+        try{
+            contactWithValidateOff.setFirstName(null);
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+            fail("XmlValueNotNillableException NOT Expected here");
+        }
+        assertEquals("<firstName " +
+               "xsi:nil=\"true\" " +
+               "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
+               contact.xmlText());
+
+    }
+
+    public void testNotNillableGlobalElem() {
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
+        // global element, not nillable. If setXXX is set to null & validateOnSet is
true, it should throw XmlValueNotNillableException
+        CityNameDocument cityName = CityNameDocument.Factory.newInstance(options);
+        try{
+            cityName.setCityName(null);
+            fail("XmlValueNotNillableException Expected here");
+        }
+        catch (XmlValueNotNillableException e) {
+        }
+
+        // with validate turned off, this should to thro
+        CityNameDocument cityNameWithValidateOff = CityNameDocument.Factory.newInstance();
+        try{
+            cityNameWithValidateOff.setCityName(null);
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+            fail("XmlValueNotNillableException NOT Expected here");
+        }
+
+        assertEquals("<nil:cityName " +
+               "xsi:nil=\"true\" " +
+               "xmlns:nil=\"http://xbean/scomp/element/NillTest\" " +
+               "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
+               cityNameWithValidateOff.xmlText());
+    }
+
+    public void testNillableGlobalElement()
+    {
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
+        // global element, nillable. If setXXX is set to null & validateOnSet is true,
it should NOT throw XmlValueNotNillableException
+        GlobalEltNillableDocument testElt = GlobalEltNillableDocument
+                .Factory.newInstance(options);
+        try{
+            testElt.setGlobalEltNillable(null);
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+            fail("XmlValueNotNillableException Not Expected here");
+        }
+        assertEquals("<nil:GlobalEltNillable " +
+               "xsi:nil=\"true\" " +
+               "xmlns:nil=\"http://xbean/scomp/element/NillTest\" " +
+               "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
+               testElt.xmlText());
 
-       // if the first name is null, xmlbeans doest not thrown any exceptions...
-        contact.setFirstName(null);
-       assertEquals("<firstName " +
+        // without the validateOnSet - no exception in this case either
+        GlobalEltNillableDocument testEltWithValidateOff = GlobalEltNillableDocument
+                .Factory.newInstance();
+        try{
+            testEltWithValidateOff.setGlobalEltNillable(null);
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+            fail("XmlValueNotNillableException Not Expected here");
+        }
+        assertEquals("<nil:GlobalEltNillable " +
+               "xsi:nil=\"true\" " +
+               "xmlns:nil=\"http://xbean/scomp/element/NillTest\" " +
+               "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
+               testElt.xmlText());
+
+
+    }
+
+    public void testNillableLocalElement()
+    {
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
+        // global element, nillable. If setXXX is set to null & validateOnSet is true,
it should NOT throw XmlValueNotNillableException
+        Contact contact = Contact
+                .Factory.newInstance(options);
+        try{
+            contact.setLocalNillableElem(null);
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+            fail("XmlValueNotNillableException Not Expected here");
+        }
+        assertEquals("<LocalNillableElem " +
                "xsi:nil=\"true\" " +
                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
                contact.xmlText());
-        GlobalEltNotNillableDocument testElt = GlobalEltNotNillableDocument
+
+        // without the validateOnSet - no exception in this case either
+        Contact contactWithValidationOff = Contact
                 .Factory.newInstance();
-        testElt.setGlobalEltNotNillable(null);
+        try{
+            contactWithValidationOff.setLocalNillableElem(null);
+        }
+        catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
+            fail("XmlValueNotNillableException Not Expected here");
+        }
+        assertEquals("<LocalNillableElem " +
+               "xsi:nil=\"true\" " +
+               "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
+               contactWithValidationOff.xmlText());
+
+
+    }
 
-        CityNameDocument doc = CityNameDocument.Factory.newInstance();
-        try {
-            doc.setCityName(null);
-            fail("Expected XmlValueNotNillableException");
+    public void testDefaultValElement()
+    {
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
+        // default value element, not nillable. If setXXX is set to null & validateOnSet
is true, it should
+        // throw XmlValueNotNillableException and validation should fail
+        GlobalEltDefaultDocument elt = GlobalEltDefaultDocument
+                .Factory.newInstance(options);
+        try{
+            elt.setGlobalEltDefault(null);
+            System.out.println("Elt Text:" + elt.xmlText());
+            assertFalse(elt.validate());
+            fail("XmlValueNotNillableException Expected here");
+        }
+        catch (XmlValueNotNillableException e) {
+        }
+    }
+
+    public void testNotNillableFixedValueElement()
+    {
+        XmlOptions options = new XmlOptions();
+        options.setValidateOnSet();
+
+        // fixed value element, not nillable. If setXXX is set to null & validateOnSet
is true, it should
+        // throw XmlValueNotNillableException and validation should fail
+        GlobalEltFixedDocument elt = GlobalEltFixedDocument
+                .Factory.newInstance(options);
+        try{
+            elt.setGlobalEltFixed(null);
+            System.out.println("Elt Text:" + elt.xmlText());
+            assertFalse(elt.validate());
+            fail("XmlValueNotNillableException Expected here");
         }
         catch (XmlValueNotNillableException e) {
+            e.printStackTrace();
         }
-       testElt.setGlobalEltNotNillable(null);
-       AddressInfo address = AddressInfo.Factory.newInstance();
-        //this can be null
-        address.setGlobalEltNotNillable(null);
-        // ...whereas this optional field cannot be null
-        //???throws an exception:
-        //likely due to the fact that it is a facet.
-        address.setCityName(null);
     }
+
 }

Modified: xmlbeans/trunk/test/src/scomp/idConstraint/detailed/KeyKeyref.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/scomp/idConstraint/detailed/KeyKeyref.java?view=diff&r1=160343&r2=160344
==============================================================================
--- xmlbeans/trunk/test/src/scomp/idConstraint/detailed/KeyKeyref.java (original)
+++ xmlbeans/trunk/test/src/scomp/idConstraint/detailed/KeyKeyref.java Wed Apr  6 16:52:38
2005
@@ -241,7 +241,8 @@
         assertTrue(!doc.validate(validateOptions));
         showErrors();
         String[] errExpected = new String[]{
-            XmlErrorCodes.IDENTITY_CONSTRAINT_VALID$DUPLICATE_KEY
+            XmlErrorCodes.IDENTITY_CONSTRAINT_VALID$DUPLICATE_KEY,
+            XmlErrorCodes.IDENTITY_CONSTRAINT_VALID$KEYREF_KEY_NOT_FOUND
         };
         assertTrue(compareErrorCodes(errExpected));
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message