1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package tests;
19
20 import junit.framework.TestCase;
21 import org.apache.ws.commons.schema.*;
22
23 import javax.xml.namespace.QName;
24 import javax.xml.transform.stream.StreamSource;
25 import java.io.FileInputStream;
26 import java.io.InputStream;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.Set;
30
31 public class FacetsTest extends TestCase {
32
33
34
35
36
37
38 public void testLengthFacet() throws Exception {
39
40
41
42
43
44
45
46
47
48
49
50 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
51 "myZipCode");
52 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
53 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
54 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
55
56 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
57 assertNotNull(elem);
58 assertEquals("myZipCode", elem.getName());
59 assertEquals(new QName("http://soapinterop.org/types", "myZipCode"),
60 elem.getQName());
61 assertEquals(new QName("http://soapinterop.org/types", "zipCode"),
62 elem.getSchemaTypeName());
63
64 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
65
66 XmlSchemaSimpleTypeRestriction r =
67 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
68 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
69 r.getBaseTypeName());
70
71 XmlSchemaSimpleType xsst = r.getBaseType();
72 assertNull(xsst);
73
74 XmlSchemaObjectCollection collection = r.getFacets();
75 assertEquals(2, collection.getCount());
76
77 Set s = new HashSet();
78 s.add(XmlSchemaLengthFacet.class.getName());
79 s.add(XmlSchemaPatternFacet.class.getName());
80 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
81 Object o = i.next();
82 assertTrue(s.remove(o.getClass().getName()));
83 if (o instanceof XmlSchemaLengthFacet) {
84 assertEquals("5", ((XmlSchemaLengthFacet)o).getValue());
85 assertEquals(false, ((XmlSchemaLengthFacet)o).isFixed());
86 String toStr = ((XmlSchemaLengthFacet)o).toString("xsd", 1);
87 assertTrue("The toString(String, int) method did not contain "
88 + "\"length\", but did contain: " + toStr,
89 toStr.indexOf("length value=\"5\"") != -1);
90 } else if (o instanceof XmlSchemaPatternFacet) {
91 assertEquals("\\d{5}", ((XmlSchemaPatternFacet)o).getValue());
92 assertEquals(false, ((XmlSchemaPatternFacet)o).isFixed());
93 String toStr = ((XmlSchemaPatternFacet)o).toString("xsd", 1);
94 assertTrue("The toString(String, int) method did not contain "
95 + "\"pattern\", but did contain: " + toStr,
96 toStr.indexOf("pattern value=\"\\d{5}\"") != -1);
97 } else {
98 fail("Unexpected object encountered: " + o.getClass().getName());
99 }
100 }
101
102 assertTrue("The set should have been empty, but instead contained: "
103 + s + ".",
104 s.isEmpty());
105
106 }
107
108
109
110
111
112
113 public void testPatternFacet() throws Exception {
114
115
116
117
118
119
120
121
122
123
124 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
125 "myCreditCardNumber");
126 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
127 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
128 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
129
130 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
131 assertNotNull(elem);
132 assertEquals("myCreditCardNumber", elem.getName());
133 assertEquals(new QName("http://soapinterop.org/types", "myCreditCardNumber"),
134 elem.getQName());
135 assertEquals(new QName("http://soapinterop.org/types", "creditCardNumber"),
136 elem.getSchemaTypeName());
137
138 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
139
140 XmlSchemaSimpleTypeRestriction r =
141 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
142 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
143 r.getBaseTypeName());
144
145 XmlSchemaSimpleType xsst = r.getBaseType();
146 assertNull(xsst);
147
148 XmlSchemaObjectCollection collection = r.getFacets();
149 assertEquals(1, collection.getCount());
150
151 Set s = new HashSet();
152 s.add(XmlSchemaPatternFacet.class.getName());
153 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
154 Object o = i.next();
155 assertTrue(s.remove(o.getClass().getName()));
156 if (o instanceof XmlSchemaPatternFacet) {
157 assertEquals("\\d{15}", ((XmlSchemaPatternFacet)o).getValue());
158 assertEquals(false, ((XmlSchemaPatternFacet)o).isFixed());
159 String toStr = ((XmlSchemaPatternFacet)o).toString("xsd", 1);
160 assertTrue("The toString(String, int) method did not contain "
161 + "\"pattern\", but did contain: " + toStr,
162 toStr.indexOf("pattern value=\"\\d{15}\"") != -1);
163 } else {
164 fail("Unexpected object encountered: " + o.getClass().getName());
165 }
166 }
167
168 assertTrue("The set should have been empty, but instead contained: "
169 + s + ".",
170 s.isEmpty());
171
172 }
173
174
175
176
177
178
179 public void testTotalDigitsFacet() throws Exception {
180
181
182
183
184
185
186
187
188
189
190 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
191 "myAge");
192 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
193 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
194 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
195
196 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
197 assertNotNull(elem);
198 assertEquals("myAge", elem.getName());
199 assertEquals(new QName("http://soapinterop.org/types", "myAge"),
200 elem.getQName());
201 assertEquals(new QName("http://soapinterop.org/types", "age"),
202 elem.getSchemaTypeName());
203
204 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
205
206 XmlSchemaSimpleTypeRestriction r =
207 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
208 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "decimal"),
209 r.getBaseTypeName());
210
211 XmlSchemaSimpleType xsst = r.getBaseType();
212 assertNull(xsst);
213
214 XmlSchemaObjectCollection collection = r.getFacets();
215 assertEquals(1, collection.getCount());
216
217 Set s = new HashSet();
218 s.add(XmlSchemaTotalDigitsFacet.class.getName());
219 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
220 Object o = i.next();
221 assertTrue(s.remove(o.getClass().getName()));
222 if (o instanceof XmlSchemaTotalDigitsFacet) {
223 assertEquals("3", ((XmlSchemaTotalDigitsFacet)o).getValue());
224 assertEquals(false, ((XmlSchemaTotalDigitsFacet)o).isFixed());
225 String toStr = ((XmlSchemaTotalDigitsFacet)o).toString("xsd", 1);
226 assertTrue("The toString(String, int) method did not contain "
227 + "\"totalDigits\", but did contain: " + toStr,
228 toStr.indexOf("totalDigits value=\"3\"") != -1);
229 } else {
230 fail("Unexpected object encountered: " + o.getClass().getName());
231 }
232 }
233
234 assertTrue("The set should have been empty, but instead contained: "
235 + s + ".",
236 s.isEmpty());
237
238 }
239
240
241
242
243
244
245 public void testMinMaxInclusiveFacets() throws Exception {
246
247
248
249
250
251
252
253
254
255
256
257 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
258 "myDistance");
259 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
260 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
261 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
262
263 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
264 assertNotNull(elem);
265 assertEquals("myDistance", elem.getName());
266 assertEquals(new QName("http://soapinterop.org/types", "myDistance"),
267 elem.getQName());
268 assertEquals(new QName("http://soapinterop.org/types", "distance"),
269 elem.getSchemaTypeName());
270
271 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
272
273 XmlSchemaSimpleTypeRestriction r =
274 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
275 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
276 r.getBaseTypeName());
277
278 XmlSchemaSimpleType xsst = r.getBaseType();
279 assertNull(xsst);
280
281 XmlSchemaObjectCollection collection = r.getFacets();
282 assertEquals(2, collection.getCount());
283
284 Set s = new HashSet();
285 s.add(XmlSchemaMaxInclusiveFacet.class.getName());
286 s.add(XmlSchemaMinInclusiveFacet.class.getName());
287 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
288 Object o = i.next();
289 assertTrue(s.remove(o.getClass().getName()));
290 if (o instanceof XmlSchemaMaxInclusiveFacet) {
291 assertEquals("100", ((XmlSchemaMaxInclusiveFacet)o).getValue());
292 assertEquals(true, ((XmlSchemaMaxInclusiveFacet)o).isFixed());
293 String toStr = ((XmlSchemaMaxInclusiveFacet)o).toString("xsd", 1);
294 assertTrue("The toString(String, int) method did not contain "
295 + "\"maxInclusive\", but did contain: " + toStr,
296 toStr.indexOf("maxInclusive value=\"100\"") != -1);
297 } else if (o instanceof XmlSchemaMinInclusiveFacet) {
298 assertEquals("0", ((XmlSchemaMinInclusiveFacet)o).getValue());
299 assertEquals(false, ((XmlSchemaMinInclusiveFacet)o).isFixed());
300 String toStr = ((XmlSchemaMinInclusiveFacet)o).toString("xsd", 1);
301 assertTrue("The toString(String, int) method did not contain "
302 + "\"minInclusive\", but did contain: " + toStr,
303 toStr.indexOf("minInclusive value=\"0\"") != -1);
304 } else {
305 fail("Unexpected object encountered: " + o.getClass().getName());
306 }
307 }
308
309 assertTrue("The set should have been empty, but instead contained: "
310 + s + ".",
311 s.isEmpty());
312
313 }
314
315
316
317
318
319
320 public void testMinMaxExlusiveFacets() throws Exception {
321
322
323
324
325
326
327
328
329
330
331
332 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
333 "myWeight");
334 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
335 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
336 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
337
338 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
339 assertNotNull(elem);
340 assertEquals("myWeight", elem.getName());
341 assertEquals(new QName("http://soapinterop.org/types", "myWeight"),
342 elem.getQName());
343 assertEquals(new QName("http://soapinterop.org/types", "weight"),
344 elem.getSchemaTypeName());
345
346 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
347
348 XmlSchemaSimpleTypeRestriction r =
349 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
350 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
351 r.getBaseTypeName());
352
353 XmlSchemaSimpleType xsst = r.getBaseType();
354 assertNull(xsst);
355
356 XmlSchemaObjectCollection collection = r.getFacets();
357 assertEquals(2, collection.getCount());
358
359 Set s = new HashSet();
360 s.add(XmlSchemaMaxExclusiveFacet.class.getName());
361 s.add(XmlSchemaMinExclusiveFacet.class.getName());
362 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
363 Object o = i.next();
364 assertTrue(s.remove(o.getClass().getName()));
365 if (o instanceof XmlSchemaMaxExclusiveFacet) {
366 assertEquals("200", ((XmlSchemaMaxExclusiveFacet)o).getValue());
367 assertEquals(false, ((XmlSchemaMaxExclusiveFacet)o).isFixed());
368 String toStr = ((XmlSchemaMaxExclusiveFacet)o).toString("xsd", 1);
369 assertTrue("The toString(String, int) method did not contain "
370 + "\"maxExclusive\", but did contain: " + toStr,
371 toStr.indexOf("maxExclusive value=\"200\"") != -1);
372 } else if (o instanceof XmlSchemaMinExclusiveFacet) {
373 assertEquals("1", ((XmlSchemaMinExclusiveFacet)o).getValue());
374 assertEquals(false, ((XmlSchemaMinExclusiveFacet)o).isFixed());
375 String toStr = ((XmlSchemaMinExclusiveFacet)o).toString("xsd", 1);
376 assertTrue("The toString(String, int) method did not contain "
377 + "\"minExclusive\", but did contain: " + toStr,
378 toStr.indexOf("minExclusive value=\"1\"") != -1);
379 } else {
380 fail("Unexpected object encountered: " + o.getClass().getName());
381 }
382 }
383
384 assertTrue("The set should have been empty, but instead contained: "
385 + s + ".",
386 s.isEmpty());
387
388 }
389
390
391
392
393
394
395 public void testWhiteSpaceFacet() throws Exception {
396
397
398
399
400
401
402
403
404
405
406 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
407 "myWhiteSpace");
408 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
409 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
410 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
411
412 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
413 assertNotNull(elem);
414 assertEquals("myWhiteSpace", elem.getName());
415 assertEquals(new QName("http://soapinterop.org/types", "myWhiteSpace"),
416 elem.getQName());
417 assertEquals(new QName("http://soapinterop.org/types", "noWhiteSpace"),
418 elem.getSchemaTypeName());
419
420 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
421
422 XmlSchemaSimpleTypeRestriction r =
423 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
424 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "normalizedString"),
425 r.getBaseTypeName());
426
427 XmlSchemaSimpleType xsst = r.getBaseType();
428 assertNull(xsst);
429
430 XmlSchemaObjectCollection collection = r.getFacets();
431 assertEquals(1, collection.getCount());
432
433 Set s = new HashSet();
434 s.add(XmlSchemaWhiteSpaceFacet.class.getName());
435 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
436 Object o = i.next();
437 assertTrue(s.remove(o.getClass().getName()));
438 if (o instanceof XmlSchemaWhiteSpaceFacet) {
439 assertEquals("collapse", ((XmlSchemaWhiteSpaceFacet)o).getValue());
440 assertEquals(false, ((XmlSchemaWhiteSpaceFacet)o).isFixed());
441 String toStr = ((XmlSchemaWhiteSpaceFacet)o).toString("xsd", 1);
442 assertTrue("The toString(String, int) method did not contain "
443 + "\"minExclusive\", but did contain: " + toStr,
444 toStr.indexOf("whiteSpace value=\"collapse\"") != -1);
445 } else {
446 fail("Unexpected object encountered: " + o.getClass().getName());
447 }
448 }
449
450 assertTrue("The set should have been empty, but instead contained: "
451 + s + ".",
452 s.isEmpty());
453
454 }
455
456
457
458
459
460
461 public void testFractionDigitsFacet() throws Exception {
462
463
464
465
466
467
468
469
470
471
472
473 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
474 "myHeight");
475 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
476 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
477 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
478
479 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
480 assertNotNull(elem);
481 assertEquals("myHeight", elem.getName());
482 assertEquals(new QName("http://soapinterop.org/types", "myHeight"),
483 elem.getQName());
484 assertEquals(new QName("http://soapinterop.org/types", "height"),
485 elem.getSchemaTypeName());
486
487 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
488
489 XmlSchemaSimpleTypeRestriction r =
490 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
491 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "decimal"),
492 r.getBaseTypeName());
493
494 XmlSchemaSimpleType xsst = r.getBaseType();
495 assertNull(xsst);
496
497 XmlSchemaObjectCollection collection = r.getFacets();
498 assertEquals(2, collection.getCount());
499
500 Set s = new HashSet();
501 s.add(XmlSchemaFractionDigitsFacet.class.getName());
502 s.add(XmlSchemaTotalDigitsFacet.class.getName());
503 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
504 Object o = i.next();
505 assertTrue(s.remove(o.getClass().getName()));
506 if (o instanceof XmlSchemaFractionDigitsFacet) {
507 assertEquals("2", ((XmlSchemaFractionDigitsFacet)o).getValue());
508 assertEquals(false, ((XmlSchemaFractionDigitsFacet)o).isFixed());
509 String toStr = ((XmlSchemaFractionDigitsFacet)o).toString("xsd", 1);
510 assertTrue("The toString(String, int) method did not contain "
511 + "\"fractionDigits\", but did contain: " + toStr,
512 toStr.indexOf("fractionDigits value=\"2\"") != -1);
513 } else if (o instanceof XmlSchemaTotalDigitsFacet) {
514 assertEquals("3", ((XmlSchemaTotalDigitsFacet)o).getValue());
515 assertEquals(false, ((XmlSchemaTotalDigitsFacet)o).isFixed());
516 String toStr = ((XmlSchemaTotalDigitsFacet)o).toString("xsd", 1);
517 assertTrue("The toString(String, int) method did not contain "
518 + "\"totalDigits\", but did contain: " + toStr,
519 toStr.indexOf("totalDigits value=\"3\"") != -1);
520 } else {
521 fail("Unexpected object encountered: " + o.getClass().getName());
522 }
523 }
524
525 assertTrue("The set should have been empty, but instead contained: "
526 + s + ".",
527 s.isEmpty());
528
529 }
530
531
532
533
534
535
536 public void testMinMaxLengthFacets() throws Exception {
537
538
539
540
541
542
543
544
545
546
547
548 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
549 "myYardLength");
550 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
551 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
552 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
553
554 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
555 assertNotNull(elem);
556 assertEquals("myYardLength", elem.getName());
557 assertEquals(new QName("http://soapinterop.org/types", "myYardLength"),
558 elem.getQName());
559 assertEquals(new QName("http://soapinterop.org/types", "yardLength"),
560 elem.getSchemaTypeName());
561
562 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
563
564 XmlSchemaSimpleTypeRestriction r =
565 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
566 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "nonNegativeInteger"),
567 r.getBaseTypeName());
568
569 XmlSchemaSimpleType xsst = r.getBaseType();
570 assertNull(xsst);
571
572 XmlSchemaObjectCollection collection = r.getFacets();
573 assertEquals(2, collection.getCount());
574
575 Set s = new HashSet();
576 s.add(XmlSchemaMinLengthFacet.class.getName());
577 s.add(XmlSchemaMaxLengthFacet.class.getName());
578 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
579 Object o = i.next();
580 assertTrue(s.remove(o.getClass().getName()));
581 if (o instanceof XmlSchemaMinLengthFacet) {
582 assertEquals("45", ((XmlSchemaMinLengthFacet)o).getValue());
583 assertEquals(false, ((XmlSchemaMinLengthFacet)o).isFixed());
584 String toStr = ((XmlSchemaMinLengthFacet)o).toString("xsd", 1);
585 assertTrue("The toString(String, int) method did not contain "
586 + "\"minExclusive\", but did contain: " + toStr,
587 toStr.indexOf("minLength value=\"45\"") != -1);
588 } else if (o instanceof XmlSchemaMaxLengthFacet) {
589 assertEquals("205", ((XmlSchemaMaxLengthFacet)o).getValue());
590 assertEquals(false, ((XmlSchemaMaxLengthFacet)o).isFixed());
591 String toStr = ((XmlSchemaMaxLengthFacet)o).toString("xsd", 1);
592 assertTrue("The toString(String, int) method did not contain "
593 + "\"maxLength\", but did contain: " + toStr,
594 toStr.indexOf("maxLength value=\"205\"") != -1);
595 } else {
596 fail("Unexpected object encountered: " + o.getClass().getName());
597 }
598 }
599
600 assertTrue("The set should have been empty, but instead contained: "
601 + s + ".",
602 s.isEmpty());
603
604 }
605
606
607
608
609
610
611 public void testEnumerationFacet() throws Exception {
612
613
614
615
616
617
618
619
620
621
622
623 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
624 "layoutComponent");
625 InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
626 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
627 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
628
629 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
630 assertNotNull(elem);
631 assertEquals("layoutComponent", elem.getName());
632 assertEquals(new QName("http://soapinterop.org/types", "layoutComponent"),
633 elem.getQName());
634 assertEquals(new QName("http://soapinterop.org/types", "layoutComponentType"),
635 elem.getSchemaTypeName());
636
637 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
638
639 XmlSchemaSimpleTypeRestriction r =
640 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
641 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
642 r.getBaseTypeName());
643
644 XmlSchemaSimpleType xsst = r.getBaseType();
645 assertNull(xsst);
646
647 XmlSchemaObjectCollection collection = r.getFacets();
648 assertEquals(2, collection.getCount());
649
650 Set s = new HashSet();
651 s.add("Field");
652 s.add("Separator");
653 for (Iterator i = collection.getIterator(); i.hasNext(); ) {
654 XmlSchemaEnumerationFacet xsef = (XmlSchemaEnumerationFacet)i.next();
655 String value = (String)xsef.getValue();
656 assertTrue("Atempted to remove an enumeration with the value of "
657 + "\"" + value + "\", but the value was not in the set.",
658 s.remove(value));
659 String toStr = xsef.toString("xsd", 1);
660 if (value.equals("Field")) {
661 assertTrue("The toString(String, int) method did not contain "
662 + "\"enumeration\", but did contain: " + toStr,
663 toStr.indexOf("enumeration value=\"Field\"") != -1);
664 } else if (value.equals("Separator")) {
665 assertTrue("The toString(String, int) method did not contain "
666 + "\"enumeration\", but did contain: " + toStr,
667 toStr.indexOf("enumeration value=\"Separator\"") != -1);
668 }
669 }
670
671 assertTrue("The set should have been empty, but instead contained: "
672 + s + ".",
673 s.isEmpty());
674
675 }
676
677 }