xml-xmlbeans-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daver...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed AttrWCRestriction.java AttributeRestriction.java ElementRestriction.java ElementWCRestriction.java EmptyContentRestriction.java GroupRestrictionTest.java MixedContentRestriction.java SimpleContentRestrictionTest.java SimpleTypeRestriction.java SubstitutionTest.java
Date Mon, 16 Aug 2004 18:59:33 GMT
daveremy    2004/08/16 11:59:33

  Added:       v2/test/src/scomp/derivation/restriction/detailed
                        AttrWCRestriction.java AttributeRestriction.java
                        ElementRestriction.java ElementWCRestriction.java
                        EmptyContentRestriction.java
                        GroupRestrictionTest.java
                        MixedContentRestriction.java
                        SimpleContentRestrictionTest.java
                        SimpleTypeRestriction.java SubstitutionTest.java
  Log:
  Contributed by:Yana Kadiyska. More schema feature tests
  
  Revision  Changes    Path
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/AttrWCRestriction.java
  
  Index: AttrWCRestriction.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package scomp.derivation.restriction.detailed;
  
  import scomp.common.BaseCase;
  import xbean.scomp.derivation.attributeWCRestriction.*;
  
  /**
   * @owner: ykadiysk
   * Date: Aug 6, 2004
   * Time: 3:39:18 PM
   */
  public class AttrWCRestriction extends BaseCase {
      String input;
      /**
       * Replace a wildcard with a concrete attribute
       * No other attr should be valid here
      */
      public void testAny2Instance() throws Throwable{
           input="<foo:Any2Concrete " +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                   " xmlns:at=\"http://xbean/scomp/attribute/GlobalAttrDefault\"" +
                  " at:testattribute=\"XBean\"/>";
           Any2ConcreteDocument doc=
                   Any2ConcreteDocument.Factory.parse(input);
          assertTrue ( doc.validate(validateOptions));
  
            input="<foo:Any2Concrete " +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                   " xmlns:at=\"http://xbean/scomp/attribute/GlobalAttrDefault\"" +
                  " at:testattributeInt=\"3\"/>";
            doc=
                   Any2ConcreteDocument.Factory.parse(input);
          assertTrue ( !doc.validate(validateOptions));
          showErrors();
      }
  
      /**
       * should be able to replace the any w/ local...
       * attrs not in target ns are therefore illegal
       * Skip to strict
       * No namespace should be OK, any other namespace should be notOK
       * @throws Throwable
       */
      public void testAny2LocalStrict() throws Throwable{
            input="<foo:Any2Local " +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                  " testattribute=\"XBean\"/>";
           Any2LocalDocument doc=
                   Any2LocalDocument.Factory.parse(input);
          assertTrue ( doc.validate(validateOptions));
  
          //a diff ns is not OK
           input="<foo:Any2Local " +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                   " xmlns:at=\"http://xbean/scomp/attribute/GlobalAttrDefault\"" +
                  " at:testattribute=\"XBean\"/>";
            doc=
                   Any2LocalDocument.Factory.parse(input);
          assertTrue (! doc.validate(validateOptions));
          showErrors();
      }
  
      /**
       * should be able to replace list of ns w/ subset
       * lax to strict
       * @throws Throwable
       */
      public void testList2SubsetStrict()throws Throwable{
            input="<foo:List2Subset " +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                   " xmlns:at=\"http://apache.org\"" +
                  " at:testattribute=\"XBean\"/>";
           List2SubsetDocument doc=
                   List2SubsetDocument.Factory.parse(input);
          //this is a non-existing NS...strict should complain
          assertTrue ( !doc.validate(validateOptions));
  
          //invalid case: give the attr a bad value, make sure it's being validated
      }
      /**
       * should be able to ##other w/ spec. namespaces
       * skip to lax
       * @throws Throwable
       */
      public void testOther2ListLax()throws Throwable{
            input="<foo:Other2List" +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                   " xmlns:at=\"http://xbean/scomp/attribute/GlobalAttrDefault\"" +
                  " at:testattribute=\"XBean\"/>";
           Other2ListDocument doc=
                   Other2ListDocument.Factory.parse(input);
          assertTrue ( doc.validate(validateOptions));
  
          //invalid case: a ns not in the list
  
           input="<foo:Other2List" +
                  " xmlns:foo=\"http://xbean/scomp/derivation/AttributeWCRestriction\"" +
                   " xmlns:at=\"http://foobar\"" +
                  " at:testattribute=\"XBean\"/>";
            doc=
                   Other2ListDocument.Factory.parse(input);
          assertTrue (! doc.validate(validateOptions));
          showErrors();
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/AttributeRestriction.java
  
  Index: AttributeRestriction.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package scomp.derivation.restriction.detailed;
  
  import xbean.scomp.derivation.attributeRestriction.AttrEltDocument;
  import xbean.scomp.derivation.attributeRestriction.RestrictedAttrT;
  
  import java.math.BigInteger;
  
  import scomp.common.BaseCase;
  import org.apache.xmlbeans.XmlString;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 23, 2004
   * Time: 11:52:12 AM
   */
  public class AttributeRestriction extends BaseCase {
     /**
      * A should be positive
      * B should be there by default
      * @throws Throwable
      */
      public void testAttributeABC() throws Throwable {
          AttrEltDocument doc = AttrEltDocument.Factory.newInstance();
          RestrictedAttrT elt = doc.addNewAttrElt();
          elt.setA(new BigInteger("-3"));
          assertTrue(!doc.validate(validateOptions));
          showErrors();
          assertEquals("b", elt.getB());
         XmlString expected=XmlString.Factory.newInstance();
         expected.setStringValue("c2");
          assertEquals(expected, elt.xgetC());
      }
  
      public void testAttributeDEF() throws Throwable {
          AttrEltDocument doc = AttrEltDocument.Factory.newInstance();
          RestrictedAttrT elt = doc.addNewAttrElt();
          XmlString expected=XmlString.Factory.newInstance();
          expected.setStringValue("a");
          elt.xsetD(expected);
          assertEquals("a", elt.getD());
          assertTrue(!doc.validate(validateOptions));
          showErrors();
          elt.setD("d");
          elt.setE("e");
          elt.setF("foobar");
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
      }
    /**
     * G is prohibited, X can appear even though not explicit in type
     * @throws Throwable
     */
      public void testAttributeGX() throws Throwable {
          AttrEltDocument doc = AttrEltDocument.Factory.newInstance();
          RestrictedAttrT elt = doc.addNewAttrElt();
          elt.setG("foobar");
          assertTrue(!doc.validate(validateOptions));
          showErrors();
          elt.setX("myval");
          elt.unsetG();
          elt.setF("foobar");
           try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/ElementRestriction.java
  
  Index: ElementRestriction.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package scomp.derivation.restriction.detailed;
  
  import xbean.scomp.derivation.elementRestriction.ElementDocument;
  import xbean.scomp.derivation.elementRestriction.RestrictedEltT;
  import org.apache.xmlbeans.XmlObject;
  import org.apache.xmlbeans.XmlString;
  import scomp.common.BaseCase;
  
  
  /**
   * @owner: ykadiysk
   * Date: Jul 23, 2004
   * Time: 11:52:03 AM
   */
  public class ElementRestriction extends BaseCase {
      /**
       * <xsd:complexType name="SequenceT">
       * <xsd:sequence>
       * <xsd:element name="child1" type="xsd:integer" minOccurs="1" />
       * <xsd:element name="child2" type="xsd:string" minOccurs="0"/>
       * </xsd:sequence>
       * </xsd:complexType>
       * <p/>
       * <xsd:complexType name="restrictedSequenceT">
       * <xsd:complexContent>
       * <xsd:restriction base="SequenceT">
       * <xsd:sequence>
       * <xsd:element name="child1" type="xsd:integer" minOccurs="2"/>
       * <xsd:element name="newchild" type="xsd:string"/>
       * </xsd:sequence>
       * </xsd:restriction>
       * </xsd:complexContent>
       * </xsd:complexType>
       */
      public void testRestrictedElement() throws Throwable {
          ElementDocument doc = ElementDocument.Factory.newInstance();
          RestrictedEltT elt = doc.addNewElement();
          XmlString aValue = XmlString.Factory.newInstance();
          aValue.setStringValue("foobar");
          //a can only occur 2ce
          elt.setAArray(new XmlObject[]{aValue, aValue, aValue});
          //b has to be missing or "myval"
          XmlString bValue = XmlString.Factory.newInstance();
          bValue.setStringValue("foobar");
          elt.setB(bValue);
          //c is of type xsd:token
          elt.setC("foobar:123");
          assertTrue(!doc.validate(validateOptions));
          showErrors();
  
          elt.removeA(2);               
          bValue.setStringValue("myval");
          elt.setB(bValue);
          assertEquals("myval",
                  ((XmlString)elt.getB()).getStringValue());
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/ElementWCRestriction.java
  
  Index: ElementWCRestriction.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package scomp.derivation.restriction.detailed;
  
  import scomp.common.BaseCase;
  import xbean.scomp.derivation.elementWCRestriction.*;
  
  /**
   * @owner: ykadiysk
   * Date: Aug 6, 2004
   * Time: 12:18:07 PM
   */
  
  //TODO compile time tests w/ occurence contstraints
  public class ElementWCRestriction extends BaseCase {
      // max occurs is now 2, not 3
      //NS restricted from any to other
      public void testMaxOccurs() throws Throwable {
          String input =
                  "<OtherLax " +
                  " xmlns=\"http://xbean/scomp/derivation/ElementWCRestriction\"" +
                  " xmlns:elt=\"http://xbean/scomp/element/GlobalEltDefault\">" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "</OtherLax>";
          OtherLaxDocument doc =
                  OtherLaxDocument.Factory.parse(input);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          //more than 2 elts not OK anymore
          //TODO: how do you add more than one elt here? only a
          //  setXXX method...no array
          input =
                  "<OtherLax " +
                  " xmlns=\"http://xbean/scomp/derivation/ElementWCRestriction\"" +
                  " xmlns:elt=\"http://xbean/scomp/element/GlobalEltDefault\">" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "<elt:GlobalEltDefaultInt>3</elt:GlobalEltDefaultInt>" +
                  "</OtherLax>";
          doc =
                  OtherLaxDocument.Factory.parse(input);
  
          assertTrue(!doc.validate(validateOptions));
          showErrors();
  
          //Only valid NS should be Other
          input =
                  "<OtherLax " +
                  " xmlns=\"http://xbean/scomp/derivation/ElementWCRestriction\">" +
                  "<testElt>foo</testElt></OtherLax>";
          doc =
                  OtherLaxDocument.Factory.parse(input);
  
          assertTrue(!doc.validate(validateOptions));
          showErrors();
  
      }
  
      //elt needs to occur exactly 2x
      //only URI allowed is GlobalElt
      public void testMinOccurs() throws Throwable {
          String input =
                  "<UriSkip " +
                  " xmlns=\"http://xbean/scomp/derivation/ElementWCRestriction\"" +
                  " xmlns:elt=\"http://xbean/scomp/element/GlobalEltDefault\">" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "</UriSkip>";
          UriSkipDocument doc =
                  UriSkipDocument.Factory.parse(input);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          //MinOccurs is 2
          input =
                  "<UriSkip " +
                  " xmlns=\"http://xbean/scomp/derivation/ElementWCRestriction\"" +
                  " xmlns:elt=\"http://xbean/scomp/element/GlobalEltDefault\">" +
                  "<elt:GlobalEltDefaultStr>foo</elt:GlobalEltDefaultStr>" +
                  "</UriSkip>";
          doc =
                  UriSkipDocument.Factory.parse(input);
          assertTrue(!doc.validate(validateOptions));
          showErrors();
      }
  
      //WC replaced by elt
      //maxOccurs is 1
      public void testConcrete() throws Throwable {
          String input =
                  "<foo:ConcreteElt " +
                  "xmlns:foo=\"http://xbean/scomp/derivation/ElementWCRestriction\">" +
                  "<concreteChild>foo</concreteChild>" +
                  "</foo:ConcreteElt>";
          ConcreteEltDocument doc =
                  ConcreteEltDocument.Factory.parse(input);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          //Max Occurs is 1
          input =
                  "<foo:ConcreteElt " +
                  "xmlns:foo=\"http://xbean/scomp/derivation/ElementWCRestriction\">" +
                  "<concreteChild>foo</concreteChild>" +
                  "<concreteChild>2</concreteChild>" +
                  "</foo:ConcreteElt>";
          doc =
                          ConcreteEltDocument.Factory.parse(input);
  
          assertTrue(!doc.validate(validateOptions));
          showErrors();
  
          //child other than that elt
          input =
                  "<ConcreteElt " +
                  "xmlns=\"http://xbean/scomp/derivation/ElementWCRestriction\"" +
                  "<testElt>foo</testElt></ConcreteElt>";
          assertTrue(!doc.validate(validateOptions));
          showErrors();
      }
  
  }
  
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/EmptyContentRestriction.java
  
  Index: EmptyContentRestriction.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package scomp.derivation.restriction.detailed;
  
  import xbean.scomp.derivation.emtpy.RestrictedEmptyEltDocument;
  import xbean.scomp.derivation.emtpy.RestrictedEmptyT;
  import scomp.common.BaseCase;
  import org.apache.xmlbeans.XmlCursor;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 22, 2004
   * Time: 5:22:07 PM
   */
  public class EmptyContentRestriction extends BaseCase {
      public void testRestriction() throws Throwable {
          RestrictedEmptyEltDocument doc = RestrictedEmptyEltDocument.Factory.newInstance();
  
          RestrictedEmptyT elt = doc.addNewRestrictedEmptyElt();
          elt.setEmptyAttr("foobar");
          assertTrue(!doc.validate());
          showErrors();
          elt.setEmptyAttr("myval");
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          XmlCursor cur = elt.newCursor();
          cur.toFirstContentToken();
          cur.toNextToken();
          cur.beginElement("foobar");
          assertEquals("<xml-fragment>" +
                  "<emt:RestrictedEmptyElt emptyAttr=\"myval\" " +
                  "xmlns:emt=\"http://xbean/scomp/derivation/Emtpy\"/>" +
                  "<foobar/></xml-fragment>", doc.xmlText());
          assertTrue(!doc.validate());
          showErrors();
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/GroupRestrictionTest.java
  
  Index: GroupRestrictionTest.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package scomp.derivation.restriction.detailed;
  
  import scomp.common.BaseCase;
  import xbean.scomp.derivation.groupRestriction.*;
  
  import java.math.BigInteger;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 22, 2004
   * Time: 11:53:10 AM
   */
  public class GroupRestrictionTest extends BaseCase {
  
      public void testRestrictSequence() throws Throwable {
          RestrictedSequenceEltDocument doc = RestrictedSequenceEltDocument.Factory
                  .newInstance();
          RestrictedSequenceT elt = doc.addNewRestrictedSequenceElt();
          elt.setChild1(BigInteger.ONE);
          elt.addChild2("foobar");
          elt.addChild3(BigInteger.TEN);
          elt.addChild3(BigInteger.TEN);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          elt.addChild3(BigInteger.ONE);
          assertTrue(!doc.validate());
          showErrors();
  
      }
  
      public void testRestrictChoice() throws Throwable {
          RestrictedChoiceEltDocument doc = RestrictedChoiceEltDocument.Factory
                  .newInstance();
          RestrictedChoiceT elt = doc.addNewRestrictedChoiceElt();
          elt.addChild2("foobar");
          elt.addChild3(BigInteger.ZERO);
          assertTrue(!doc.validate());
          showErrors();
          elt.removeChild2(0);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
  
      }
  
      public void testRestrictAll() throws Throwable {
          RestrictedAllEltDocument doc = RestrictedAllEltDocument.Factory
                  .newInstance();
          RestrictedAllT elt = doc.addNewRestrictedAllElt();
          elt.setChild2("foobar");
          //child3 can't be missing
          assertTrue(!doc.validate());
          showErrors();
          elt.setChild3(BigInteger.TEN);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
      }
  
      public void testAllToSequence() throws Throwable {
          All2SeqEltDocument doc = All2SeqEltDocument.Factory.newInstance();
          All2SequenceT elt = doc.addNewAll2SeqElt();
          elt.setA("foo");
          elt.setC(3);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          //b not part of restricted type
          elt.setB("bar");
          assertTrue(!doc.validate());
          showErrors();
      }
  
      public void testChoiceToSequence() throws Throwable {
          Choice2SeqEltDocument doc = Choice2SeqEltDocument.Factory.newInstance();
          Choice2SequenceT elt = doc.addNewChoice2SeqElt();
          elt.addA("foo");
          elt.addC(3);
          try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          //b not part of restricted type
          elt.addB("bar");
          assertTrue(!doc.validate());
          showErrors();
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/MixedContentRestriction.java
  
  Index: MixedContentRestriction.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package scomp.derivation.restriction.detailed;
  
  import xbean.scomp.derivation.mixedContentRestriction.*;
  import scomp.common.BaseCase;
  
  import java.math.BigInteger;
  
  import org.apache.xmlbeans.XmlCursor;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 22, 2004
   * Time: 5:21:53 PM
   */
  public class MixedContentRestriction extends BaseCase{
  
      public void testRestrictedMixed() throws Throwable{
          MixedEltDocument doc=MixedEltDocument.Factory.newInstance();
          RestrictedMixedT elt=doc.addNewMixedElt();
          assertTrue( !elt.isSetChild1());
          elt.setChild1(BigInteger.TEN);
          elt.setChild2(BigInteger.ZERO);
          //insert text b/n the 2 elements
          XmlCursor cur=elt.newCursor();
          cur.toFirstContentToken();
          assertTrue(cur.toNextSibling());
          cur.insertChars("My chars");
            try {
              assertTrue( doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          assertEquals("<xml-fragment>" +
                  "<child1>10</child1>My chars<child2>0</child2>"
+
                  "</xml-fragment>", elt.xmlText());
  
      }
      public void testRestrictedEltOnly() throws Throwable{
         ElementOnlyEltDocument doc=ElementOnlyEltDocument.Factory.newInstance();
          RestrictedEltT elt=doc.addNewElementOnlyElt();
          assertTrue( !elt.isSetChild1());
          elt.setChild1(BigInteger.TEN);
          elt.setChild2(BigInteger.ZERO);
          //insert text b/n the 2 elements
          XmlCursor cur=elt.newCursor();
         cur.toFirstContentToken();
          assertTrue(cur.toNextSibling());
          cur.insertChars("My chars");
          assertTrue( !doc.validate(validateOptions));
          showErrors();
          //should be valid w/o the Text there
          cur.toPrevToken();
           assertEquals("<xml-fragment>" +
                  "<child1>10</child1>My chars<child2>0</child2>"
+
                  "</xml-fragment>", elt.xmlText());
         assertTrue(cur.removeXml());
          try {
              assertTrue( doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
          assertEquals("<xml-fragment>" +
                  "<child1>10</child1><child2>0</child2>" +
                  "</xml-fragment>", elt.xmlText());
  
  
      }
      //seems that this is not a valid example p.329 top
      //public void testRestrictedMixedToSimple() throws Throwable{}
      public void testRestrictedMixedToEmpty() throws Throwable{
           Mixed2EmptyEltDocument doc=Mixed2EmptyEltDocument.Factory.newInstance();
           Mixed2EmptyT elt=doc.addNewMixed2EmptyElt();
          assertEquals(null,elt.xgetChild1());
          elt.setChild1(BigInteger.TEN);
           assertTrue( !doc.validate(validateOptions));
          showErrors();
          elt.unsetChild1();
           try {
              assertTrue( doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/SimpleContentRestrictionTest.java
  
  Index: SimpleContentRestrictionTest.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package scomp.derivation.detailed;
  
  import xbean.scomp.derivation.simpleExtension.SimpleRestrictionEltDocument;
  import xbean.scomp.derivation.simpleExtension.SimpleRestrictionT;
  import scomp.common.BaseCase;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 21, 2004
   * Time: 10:17:02 AM
   */
  public class SimpleContentRestrictionTest extends BaseCase{
      public void testLegalValues() throws Throwable{
          SimpleRestrictionEltDocument doc=SimpleRestrictionEltDocument.Factory.newInstance();
          SimpleRestrictionT elt=doc.addNewSimpleRestrictionElt();
          elt.setIntValue(3);
            try {
              assertTrue( doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
             throw t;
          }
  
      }
       public void testIllegalValues() throws Throwable{
          SimpleRestrictionEltDocument doc=SimpleRestrictionEltDocument.Factory.newInstance();
          SimpleRestrictionT elt=doc.addNewSimpleRestrictionElt();
          elt.setIntValue(5);
  
              assertTrue( !doc.validate());
  
              doc.validate(validateOptions);
              showErrors();
  
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/SimpleTypeRestriction.java
  
  Index: SimpleTypeRestriction.java
  ===================================================================
  
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package scomp.derivation.restriction.detailed;
  
  import scomp.common.BaseCase;
  import xbean.scomp.derivation.simpleTypeRestriction.SmallPantSizeEltDocument;
  import xbean.scomp.derivation.facets.dateTimePattern.DateTimesDocument;
  import xbean.scomp.derivation.facets.dateTimePattern.DateTimes;
  import xbean.scomp.contentType.simpleType.PantSizeEltDocument;
  import xbean.scomp.contentType.simpleType.PantSize;
  
  import java.util.Calendar;
  import java.util.GregorianCalendar;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 29, 2004
   * Time: 2:15:27 PM
   */
  public class SimpleTypeRestriction extends BaseCase{
  
      public void testPatternRestriction()throws Throwable{
          SmallPantSizeEltDocument doc=SmallPantSizeEltDocument.Factory.newInstance();
            doc.setSmallPantSizeElt(8);
            //doc.setSmallPantSizeElt(6);
             try {
              assertTrue(doc.validate(validateOptions));
          }
          catch (Throwable t) {
              showErrors();
              throw t;
          }
      }
  
      //user-list inspired
      public void testDateTimeRestriction() throws Throwable{
         DateTimesDocument doc=
                 DateTimesDocument.Factory.newInstance();
          Calendar c=new GregorianCalendar(2004,8,10);
          DateTimes date=DateTimes.Factory.newInstance();
          date.setExtendedDate1(c);
          date.setExtendedDate2("2004-08-10");
          c.set(2004,8,10,12,10);
          date.setExtendedDateTime1(c);
          date.setExtendedDateTime2(c);
          date.setExtendedDateTimeAny3(c);
  
          System.out.println(
                  date.getExtendedDate1()+"\n"+
                   date.getExtendedDate2()+"\n"+
                   date.getExtendedDateTime1()+"\n"+
                   date.getExtendedDateTime2()+"\n"+
                   date.getExtendedDateTimeAny3()+"\n"
          );
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/detailed/SubstitutionTest.java
  
  Index: SubstitutionTest.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package scomp.derivation.restriction.detailed;
  
  import xbean.scomp.contentType.modelGroup.ChoiceEltDocument;
  import xbean.scomp.contentType.simpleType.PantSizeEltDocument;
  import scomp.common.BaseCase;
  
  /**
   * @owner: ykadiysk
   * Date: Jul 25, 2004
   * Time: 7:53:07 PM
   */
  public class SubstitutionTest extends BaseCase
   {
      public void testSubstitution() throws Throwable{
           ChoiceEltDocument doc=
                  ChoiceEltDocument.Factory.parse(
                          "<foo:ChoiceElt " +
                   "xmlns:foo=\"http://xbean/scomp/contentType/ModelGroup\"" +
                   " xmlns:sub=\"http://xbean/scomp/derivation/GroupRestriction\""+
                   " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                   " xsi:type=\"sub:restrictedChoiceT\">" +
                   "<child3>50</child3>" +
                   "</foo:ChoiceElt>"
                  );
                  try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
      }
  
       public void testSimpleTypeSubstitution() throws Throwable{
                  PantSizeEltDocument doc=
                  PantSizeEltDocument.Factory.parse(
                          "<foo:PantSizeElt " +
                   "xmlns:foo=\"http://xbean/scomp/contentType/SimpleType\"" +
                   " xmlns:sub=\"http://xbean/scomp/derivation/SimpleTypeRestriction\""+
                   " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                   " xsi:type=\"sub:SmallPantSize\">"+
                    "8" +
                   "</foo:PantSizeElt>"
                  );
                  try {
              assertTrue(doc.validate());
          }
          catch (Throwable t) {
              doc.validate(validateOptions);
              showErrors();
              throw t;
          }
       }
  }
  
  
  

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


Mime
View raw message