KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > junit > JiraTest


1 package org.apache.ws.jaxme.xs.junit;
2
3 import java.io.IOException JavaDoc;
4 import java.io.StringReader JavaDoc;
5 import java.util.Calendar JavaDoc;
6 import java.util.TimeZone JavaDoc;
7
8 import javax.xml.parsers.ParserConfigurationException JavaDoc;
9
10 import org.apache.ws.jaxme.xs.XSAttributable;
11 import org.apache.ws.jaxme.xs.XSAttribute;
12 import org.apache.ws.jaxme.xs.XSComplexType;
13 import org.apache.ws.jaxme.xs.XSElement;
14 import org.apache.ws.jaxme.xs.XSEnumeration;
15 import org.apache.ws.jaxme.xs.XSParser;
16 import org.apache.ws.jaxme.xs.XSSchema;
17 import org.apache.ws.jaxme.xs.XSSimpleContentType;
18 import org.apache.ws.jaxme.xs.XSSimpleType;
19 import org.apache.ws.jaxme.xs.XSType;
20 import org.apache.ws.jaxme.xs.types.XSID;
21 import org.apache.ws.jaxme.xs.types.XSString;
22 import org.apache.ws.jaxme.xs.util.XsDateTimeFormat;
23 import org.apache.ws.jaxme.xs.xml.XsAnyURI;
24 import org.apache.ws.jaxme.xs.xml.XsQName;
25 import org.xml.sax.InputSource JavaDoc;
26 import org.xml.sax.SAXException JavaDoc;
27
28
29 /** Collection of schemas from Jira.
30  */

31 public class JiraTest extends ParserTestBase {
32     /** Creates a new instance with the given name.
33      */

34     public JiraTest(String JavaDoc pName) {
35         super(pName);
36     }
37
38     private XSSchema parse(String JavaDoc pSchema, String JavaDoc pName)
39             throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
40         InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(pSchema));
41         isource.setSystemId(pName);
42         XSParser parser = new XSParser();
43         parser.setValidating(false);
44         return parser.parse(isource);
45     }
46
47     /** Test for JAXME-34 in Jira.
48      */

49     public void testJira34() throws Exception JavaDoc {
50         final String JavaDoc schemaSpec =
51             "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
52           + " <xs:complexType name='mixedType' mixed='true'>\n"
53           + " <xs:attribute name='foo' type='xs:string'/>\n"
54           + " </xs:complexType>\n"
55           + "</xs:schema>";
56         XSSchema schema = parse(schemaSpec, "jira34.xsd");
57         XSType[] types = schema.getTypes();
58         assertEquals(1, types.length);
59         XSComplexType ct = assertComplexType(types[0]);
60         assertTrue(ct.isMixed());
61     }
62
63     /** Test for JAXME-42 in Jira.
64      */

65     public void testJira42() throws Exception JavaDoc {
66         XsDateTimeFormat f = new XsDateTimeFormat();
67         Calendar JavaDoc cal = (Calendar JavaDoc) f.parseObject("2004-10-15T13:00:00Z");
68         assertEquals(2004, cal.get(Calendar.YEAR));
69         assertEquals(9, cal.get(Calendar.MONTH));
70         assertEquals(15, cal.get(Calendar.DAY_OF_MONTH));
71         assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
72         assertEquals(0, cal.get(Calendar.MINUTE));
73         assertEquals(0, cal.get(Calendar.SECOND));
74         assertEquals(0, cal.get(Calendar.MILLISECOND));
75         assertEquals(TimeZone.getTimeZone("GMT"), cal.getTimeZone());
76
77         String JavaDoc s = f.format(cal);
78         assertEquals("2004-10-15T13:00:00Z", s);
79     }
80
81     /** Test for JAXME-44 in Jira.
82      */

83     public void testJira44() throws Exception JavaDoc {
84         final String JavaDoc schemaSpec =
85             "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
86             + " <xs:simpleType name='threeOrFour'>\n"
87             + " <xs:restriction base='xs:string'>\n"
88             + " <xs:enumeration value='3'/>\n"
89             + " <xs:enumeration value='4'/>\n"
90             + " </xs:restriction>\n"
91             + " </xs:simpleType>\n"
92             + "\n"
93             + " <xs:complexType name='outerType1'>\n"
94             + " <xs:simpleContent>\n"
95             + " <xs:extension base='threeOrFour'>\n"
96             + " <xs:attribute name='isOctal' type='xs:boolean'/>\n"
97             + " </xs:extension>"
98             + " </xs:simpleContent>\n"
99             + " </xs:complexType>\n"
100             + "\n"
101             + " <xs:complexType name='outerType2'>\n"
102             + " <xs:simpleContent>\n"
103             + " <xs:restriction base='outerType1'>\n"
104             + " <xs:enumeration value='4'/>\n"
105             + " </xs:restriction>\n"
106             + " </xs:simpleContent>\n"
107             + " </xs:complexType>\n"
108             + "</xs:schema>";
109
110         XSSchema schema = parse(schemaSpec, "jira44.xsd");
111         XSType[] types = schema.getTypes();
112         assertEquals(3, types.length);
113         XSType threeOrFourType = types[0];
114         XSSimpleType threeOrFourSimpleType = assertSimpleType(threeOrFourType);
115         XSType restrictedType = assertRestriction(threeOrFourSimpleType);
116         XSEnumeration[] threeOrFourTypeEnums = threeOrFourSimpleType.getEnumerations();
117         assertEquals(2, threeOrFourTypeEnums.length);
118         assertEquals("3", threeOrFourTypeEnums[0].getValue());
119         assertEquals("4", threeOrFourTypeEnums[1].getValue());
120         assertEquals(XSString.getInstance(), restrictedType);
121         XSType outerType1 = types[1];
122         assertEquals(new XsQName((XsAnyURI) null, "outerType1"), outerType1.getName());
123         XSComplexType outerType1complexType = assertComplexType(outerType1);
124         XSSimpleContentType outerType1simpleContentType = assertSimpleContent(outerType1complexType);
125         XSType outerType1contentType = outerType1simpleContentType.getType();
126         assertEquals(threeOrFourType, outerType1contentType);
127         XSType outerType2 = types[2];
128         assertEquals(new XsQName((XsAnyURI) null, "outerType2"), outerType2.getName());
129         XSComplexType outerType2complexType = assertComplexType(outerType2);
130         XSSimpleContentType outerType2simpleContentType = assertSimpleContent(outerType2complexType);
131         XSType outerType2contentType = outerType2simpleContentType.getType();
132         assertEquals(threeOrFourType, assertRestriction(outerType2contentType.getSimpleType()));
133         XSEnumeration[] outerType2Enums = outerType2contentType.getSimpleType().getEnumerations();
134         assertEquals(1, outerType2Enums.length);
135         assertEquals("4", outerType2Enums[0].getValue());
136     }
137
138     /** Test for JAXME-46 in Jira.
139      */

140     public void testJira46() throws Exception JavaDoc {
141         final String JavaDoc uri = "http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/";
142         final String JavaDoc schemaSpec =
143             "<xs:schema targetNamespace='" + uri + "'\n" +
144             " xmlns:eGov_IT='" + uri + "'\n" +
145             " xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
146             " <xs:element name='Riferimento'>\n" +
147             " <xs:complexType>\n" +
148             " <xs:sequence/>\n" +
149             " <xs:attribute ref='eGov_IT:id' use='required'/>\n" +
150             " </xs:complexType>\n" +
151             " </xs:element>\n" +
152             " <xs:attribute name='id' type='xs:ID'/>\n" +
153             "</xs:schema>\n";
154         XSSchema schema = parse(schemaSpec, "jira46.xsd");
155         XSAttribute[] attrs = schema.getAttributes();
156         assertEquals(1, attrs.length);
157         XSAttribute idAttr = attrs[0];
158         assertEquals(new XsQName(uri, "id"), idAttr.getName());
159         assertEquals(XSID.getInstance(), idAttr.getType());
160         assertTrue(idAttr.isOptional());
161         XSElement[] elements = schema.getElements();
162         assertEquals(1, elements.length);
163         XSElement rifElem = elements[0];
164         XSComplexType ct = assertComplexType(rifElem.getType());
165         XSAttributable[] rifAttrs = ct.getAttributes();
166         assertEquals(1, rifAttrs.length);
167         XSAttribute idRef = (XSAttribute) rifAttrs[0];
168         assertFalse(idRef.equals(idAttr));
169         assertEquals(new XsQName(uri, "id"), idAttr.getName());
170         assertEquals(XSID.getInstance(), idAttr.getType());
171         assertFalse(idRef.isOptional());
172     }
173 }
174
Popular Tags