Update of /cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/junit
In directory sc8-pr-cvs1:/tmp/cvs-serv4606/src/net/sf/jaxme/junit
Modified Files:
ParserTest.java
Log Message:
Applied patch by Marty Kube adding an example from the
W3C Schema Primer, part 0.
Index: ParserTest.java
===================================================================
RCS file: /cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/junit/ParserTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ParserTest.java 12 Feb 2003 18:55:45 -0000 1.11
+++ ParserTest.java 16 Feb 2003 16:54:40 -0000 1.12
@@ -40,6 +40,7 @@
import org.apache.log4j.Logger;
import org.xml.sax.InputSource;
+
/** <p>Implements some basic tests for the Schema generator.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jochen Wiedmann</a>
@@ -51,7 +52,7 @@
public ParserTest(String arg) { super(arg); }
public void testSimpleTypes() throws Exception {
- final String mName = "testSimpleTypes";
+ final String mName = "testSimpleTypes";
log.debug(mName + ": ->");
final String schema =
"<?xml version='1.0'?>\n" +
@@ -122,7 +123,7 @@
}
public void testAttributes() throws Exception {
- final String mName = "testAttributes";
+ final String mName = "testAttributes";
log.debug(mName + ": ->");
final String schema =
"<?xml version='1.0'?>\n" +
@@ -177,7 +178,7 @@
}
public void testAttributeGroups() throws Exception {
- final String mName = "testAttributeGroups";
+ final String mName = "testAttributeGroups";
log.debug(mName + ": ->");
final String schema =
"<?xml version='1.0'?>\n" +
@@ -581,9 +582,276 @@
JavaQName qName = typeSG.getClassName(st, SchemaClass.CLASS_TYPE_XML_INTERFACE);
assertEquals(myPackageName, qName.getPackageName());
}
+
+ public void testPurchaseOrder() throws Exception {
+
+ final String mName = "testPurchaseOrder";
+ log.debug(mName + ": ->");
+
+ /*
+ A modified version of the first example from XML Schema Part 0:
+ http:www.w3.org/TR/xmlschema-0/#po.xml
+ Modifications:
+ 1) Removed forward references by re-ordering the document
+ 2) Changed some types to remove types not currently supported
+ xsd:NMTOKEN -> xsd:string
+ xsd:positiveInteger -> xsd:integer
+ */
- public void testABug() throws Exception {
- final String mName = "testABug";
+ final String schema =
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" +
+ " \n" +
+ " <xsd:annotation> \n" +
+ " <xsd:documentation xml:lang='en'> \n" +
+ " Purchase order schema for Example.com. \n" +
+ " Copyright 2000 Example.com. All rights reserved. \n" +
+ " </xsd:documentation> \n" +
+ " </xsd:annotation> \n" +
+ " \n" +
+ " <xsd:element name='comment' type='xsd:string'/> \n" +
+ " \n" +
+ " <xsd:simpleType name='SKU'> \n" +
+ " <xsd:restriction base='xsd:string'> \n" +
+ " <xsd:pattern value='\\d{3}-[A-Z]{2}'/> \n" +
+ " </xsd:restriction> \n" +
+ " </xsd:simpleType> \n" +
+ " \n" +
+ " <xsd:complexType name='USAddress'> \n" +
+ " <xsd:sequence> \n" +
+ " <xsd:element name='name' type='xsd:string'/> \n" +
+ " <xsd:element name='street' type='xsd:string'/> \n" +
+ " <xsd:element name='city' type='xsd:string'/> \n" +
+ " <xsd:element name='state' type='xsd:string'/> \n" +
+ " <xsd:element name='zip' type='xsd:integer'/> \n" +
+ " </xsd:sequence> \n" +
+ " <xsd:attribute name='country' type='xsd:string' fixed='US'/> \n" +
+ " </xsd:complexType> \n" +
+ " \n" +
+ " <xsd:complexType name='Items'> \n" +
+ " <xsd:sequence> \n" +
+ " <xsd:element name='item' minOccurs='0' maxOccurs='unbounded'> \n" +
+ " <xsd:complexType> \n" +
+ " <xsd:sequence> \n" +
+ " <xsd:element name='productName' type='xsd:string'/> \n" +
+ " <xsd:element name='quantity'> \n" +
+ " <xsd:simpleType> \n" +
+ " <xsd:restriction base='xsd:positiveInteger'> \n" +
+ " <xsd:maxExclusive value='100'/> \n" +
+ " </xsd:restriction> \n" +
+ " </xsd:simpleType> \n" +
+ " </xsd:element> \n" +
+ " <xsd:element name='USPrice' type='xsd:decimal'/> \n" +
+ " <xsd:element ref='comment' minOccurs='0'/> \n" +
+ " <xsd:element name='shipDate' type='xsd:date' minOccurs='0'/> \n" +
+ " </xsd:sequence> \n" +
+ " <xsd:attribute name='partNum' type='SKU' use='required'/> \n" +
+ " </xsd:complexType> \n" +
+ " </xsd:element> \n" +
+ " </xsd:sequence> \n" +
+ " </xsd:complexType> \n" +
+ " \n" +
+ " <xsd:complexType name='PurchaseOrderType'> \n" +
+ " <xsd:sequence> \n" +
+ " <xsd:element name='shipTo' type='USAddress'/> \n" +
+ " <xsd:element name='billTo' type='USAddress'/> \n" +
+ " <xsd:element ref='comment' minOccurs='0'/> \n" +
+ " <xsd:element name='items' type='Items'/> \n" +
+ " </xsd:sequence> \n" +
+ " <xsd:attribute name='orderDate' type='xsd:date'/> \n" +
+ " </xsd:complexType> \n" +
+ " \n" +
+ " <xsd:element name='purchaseOrder' type='PurchaseOrderType'/> \n" +
+ " \n" +
+ "</xsd:schema> \n";
+
+ JAXBSchemaReader r = new JAXBSchemaReader();
+ InputSource isource = new InputSource(new StringReader(schema));
+ isource.setSystemId("testPurchaseOrder.xsd");
+ JAXBSchema jschema = (JAXBSchema) r.parse(isource);
+ GlobalBindings globalBindings = jschema.getGlobalBindings();
+ assertNotNull(globalBindings);
+
+ SchemaType[] schemaTypes = jschema.getSchemaTypes();
+ assertNotNull(schemaTypes);
+ assertEquals(4, schemaTypes.length);
+ Arrays.sort(schemaTypes, QNameComparator.getInstance());
+
+ // Items
+ SchemaType items = schemaTypes[0];
+ assertEquals("Items", items.getLocalName());
+ assertTrue(items.isGlobal());
+ assertTrue(items.isComplex());
+ assertTrue(!((SchemaComplexType)items).hasSimpleContent());
+ assertTrue(((ComplexContentType)items).isSequence());
+ // Items.item
+ SchemaElement [] itemsChildren = ((ComplexContentType)items).getChildElements();
+ assertEquals(1, itemsChildren.length);
+ SchemaElement item = itemsChildren[0];
+ assertEquals("item", item.getQName().toString());
+ assertTrue(!item.isGlobal());
+ assertTrue(item.isComplex());
+ assertEquals(0, item.getSchemaProperty().getMinOccurs());
+ assertEquals(-1, item.getSchemaProperty().getMaxOccurs());
+ SchemaType itemST = (SchemaType) item.getSchemaType();
+ assertTrue(((ComplexContentType)itemST).isSequence());
+ // Items.item.partNum
+ // <xsd:attribute name='partNum' type='SKU' use='required'/>
+ SchemaAttribute [] itemAttributes = ((ComplexContentType)itemST).getAttributes();
+ assertEquals(1, itemAttributes.length);
+ SchemaAttribute partNum = itemAttributes[0];
+ assertEquals("partNum", partNum.getQName().toString());
+ assertEquals(1, partNum.getSchemaProperty().getMinOccurs()); // use='required'
+ assertEquals(1, partNum.getSchemaProperty().getMaxOccurs()); // use='required'
+ assertEquals("SKU", partNum.getSchemaType().getLocalName());
+ // Items.item.USPrice
+ // <xsd:element name='USPrice' type='xsd:decimal'/>
+ SchemaElement [] itemChildren = ((ComplexContentType)itemST).getChildElements();
+ assertEquals(5, itemChildren.length);
+ Arrays.sort(itemChildren, QNameComparator.getInstance());
+ SchemaElement usPrice = itemChildren[0];
+ assertEquals("USPrice", usPrice.getQName().toString());
+ assertTrue(!usPrice.isComplex());
+ SchemaSimpleType usPriceSST = (SchemaSimpleType) usPrice.getSchemaType();
+ assertTrue(usPriceSST.isAtomic());
+ assertEquals(java.math.BigDecimal.class.getName(),
+usPriceSST.getRuntimeType().toString());
+ // Items.item.comment
+ // <xsd:element ref='comment' minOccurs='0'/>
+ SchemaElement comment = itemChildren[1];
+ assertEquals("comment", comment.getQName().toString());
+ assertEquals(0, comment.getSchemaProperty().getMinOccurs());
+ assertTrue(!comment.isComplex());
+ SchemaSimpleType commentSST = (SchemaSimpleType) comment.getSchemaType();
+ assertTrue(commentSST.isAtomic());
+ assertEquals(String.class.getName(), commentSST.getRuntimeType().toString());
+ // Items.item.productName
+ // <xsd:element name='productName' type='xsd:string'/>
+ SchemaElement productName = itemChildren[2];
+ assertEquals("productName", productName.getQName().toString());
+ assertTrue(!productName.isComplex());
+ SchemaSimpleType productNameSST = (SchemaSimpleType) productName.getSchemaType();
+ assertTrue(productNameSST.isAtomic());
+ assertEquals(String.class.getName(), productNameSST.getRuntimeType().toString());
+
+ // Items.item.quantity
+ SchemaElement quantity = itemChildren[3];
+ assertEquals("quantity", quantity.getQName().toString());
+ assertTrue(!quantity.isComplex());
+ SchemaSimpleType quantitySST = (SchemaSimpleType) quantity.getSchemaType();
+ assertTrue(quantitySST.isAtomic());
+ assertEquals(java.math.BigDecimal.class.getName(),
+quantitySST.getRuntimeType().toString());
+ // Items.item.shipDate
+ // <xsd:element name='shipDate' type='xsd:date' minOccurs='0'/>
+ SchemaElement shipDate = itemChildren[4];
+ assertEquals("shipDate", shipDate.getQName().toString());
+ assertTrue(!shipDate.isComplex());
+ assertEquals(0, shipDate.getSchemaProperty().getMinOccurs());
+ SchemaSimpleType shipDateSST = (SchemaSimpleType) shipDate.getSchemaType();
+ assertTrue(shipDateSST.isAtomic());
+ assertEquals(Calendar.class.getName(), shipDateSST.getRuntimeType().toString());
+
+
+ // PurchaseOrderType
+ SchemaType purchaseOrderType = schemaTypes[1];
+ assertEquals("PurchaseOrderType", purchaseOrderType.getLocalName());
+ assertTrue(purchaseOrderType.isGlobal());
+ assertTrue(purchaseOrderType.isComplex());
+ assertTrue(((ComplexContentType)purchaseOrderType).isSequence());
+ // PurchaseOrderType.orderDate
+ // <xsd:attribute name='orderDate' type='xsd:date'/>
+ SchemaAttribute [] potAttributes =
+((ComplexContentType)purchaseOrderType).getAttributes();
+ assertEquals(1, potAttributes.length);
+ SchemaAttribute orderDate = potAttributes[0];
+ assertEquals("orderDate", orderDate.getQName().toString());
+ assertEquals(Calendar.class.getName(),
+ ((SchemaSimpleType)orderDate.getSchemaType()).getRuntimeType().toString());
+ SchemaElement [] potChildren =
+((ComplexContentType)purchaseOrderType).getChildElements();
+ assertEquals(4, potChildren.length);
+ // PurchaseOrderType.shipTo
+ // <xsd:element name='shipTo' type='USAddress'/>
+ SchemaElement shipTo = potChildren[0];
+ assertEquals("shipTo", shipTo.getQName().toString());
+ assertTrue(shipTo.isComplex());
+ SchemaType shipToST = shipTo.getSchemaType();
+ assertEquals("USAddress", shipToST.getQName().toString());
+ assertTrue(shipToST.isComplex());
+ // PurchaseOrderType.billTo
+ // <xsd:element name='billTo' type='USAddress'/>
+ SchemaElement billTo = potChildren[1];
+ assertEquals("billTo", billTo.getQName().toString());
+ assertTrue(billTo.isComplex());
+ SchemaType billToST = billTo.getSchemaType();
+ assertEquals("USAddress", billToST.getQName().toString());
+ assertTrue(billToST.isComplex());
+ // PurchaseOrderType.comment
+ // <xsd:element ref='comment' minOccurs='0'/>
+ SchemaElement potComment = potChildren[2];
+ assertEquals("comment", comment.getQName().toString());
+ assertEquals(0, comment.getSchemaProperty().getMinOccurs());
+ assertTrue(!comment.isComplex());
+ assertEquals(String.class.getName(),
+ ((SchemaSimpleType) comment.getSchemaType()).getRuntimeType().toString());
+
+ // PurchaseOrderType.items
+ // <xsd:element name='items' type='Items'/>
+ SchemaElement potItems = potChildren[3];
+ assertEquals("items", potItems.getQName().toString());
+ assertTrue(potItems.isComplex());
+
+ // SKU
+ SchemaType sku = schemaTypes[2];
+ assertEquals("SKU", sku.getLocalName());
+ assertTrue(sku.isGlobal());
+ assertTrue(!sku.isComplex());
+ assertTrue(sku.isRestriction());
+ // ToDo: test restriction pattern
+ // assertNotNull(sku.getRestriction());
+
+ // USAddress
+ // <xsd:complexType name='USAddress'>
+ // <xsd:sequence>
+ SchemaType usAddress = schemaTypes[3];
+ assertEquals("USAddress", usAddress.getLocalName());
+ assertTrue(usAddress.isGlobal());
+ assertTrue(usAddress.isComplex());
+ assertTrue(((ComplexContentType)usAddress).isSequence());
+ // USAddress.country
+ // <xsd:attribute name='country' type='xsd:string' fixed='US'/>
+ // ToDo: test attribute fixed='US'
+ SchemaAttribute [] usAddressAttributes =
+ ((ComplexContentType)usAddress).getAttributes();
+ assertEquals(1, usAddressAttributes.length);
+ SchemaAttribute country = usAddressAttributes[0];
+ assertEquals("country", country.getQName().toString());
+ assertEquals(String.class.getName(),
+ ((SchemaSimpleType)country.getSchemaType()).getRuntimeType().toString());
+ // USAddress children
+ String [] nameShouldBe = {"city", "name", "state", "street", "zip"};
+ SchemaElement [] usAddressChildren =
+((ComplexContentType)usAddress).getChildElements();
+ Arrays.sort(usAddressChildren, QNameComparator.getInstance());
+ assertEquals(5, usAddressChildren.length);
+ for (int i = 0; i < usAddressChildren.length; i++) {
+ SchemaElement child = usAddressChildren[i];
+ assertEquals(nameShouldBe[i], child.getQName().toString());
+ assertTrue(!child.isComplex());
+ String childRuntimeClass =
+ child.getQName().toString().equals("zip") ?
+ java.math.BigDecimal.class.getName() : String.class.getName();
+ assertEquals(childRuntimeClass,
+ ((SchemaSimpleType)
+child.getSchemaType()).getRuntimeType().toString());
+ }
+
+ // purchaseOrder
+ // <xsd:element name='purchaseOrder' type='PurchaseOrderType'/>
+ SchemaElement[] elements = jschema.getSchemaElements();
+ assertNotNull(schemaTypes);
+ assertEquals(2, elements.length);
+ Arrays.sort(elements, QNameComparator.getInstance());
+ SchemaElement purchaseOrder = elements[1];
+ assertEquals("purchaseOrder", purchaseOrder.getQName().toString());
+ assertTrue(purchaseOrder.isComplex());
+ assertTrue(!purchaseOrder.isGlobal());
+ assertEquals("PurchaseOrderType", purchaseOrder.getSchemaType().getLocalName());
+ }
+
+ public void testRestrictionMaxExclusive() throws Exception {
+ final String mName = "testRestrictionMaxExclusive";
log.debug(mName + ": ->");
final String schema =
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" +
@@ -598,7 +866,7 @@
JAXBSchemaReader r = new JAXBSchemaReader();
InputSource isource = new InputSource(new StringReader(schema));
- isource.setSystemId("testABug.xsd");
+ isource.setSystemId("testRestrictionMaxExclusive.xsd");
JAXBSchema jschema = (JAXBSchema) r.parse(isource);
log.debug(mName + ": <-");
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Jaxme-jaxb-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxme-jaxb-dev