summaryrefslogtreecommitdiffstats
path: root/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java
blob: ca822f6006c6c788623dcf6aa196abaa933ea5d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/**
 *
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 test.sdo21.tests.general;

import commonj.sdo.*;
import commonj.sdo.helper.*;
import org.junit.After;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import test.sdo21.framework.CTSTestCase;
import test.sdo21.tests.util.XMLEqualityChecker;

import java.io.*;
import java.math.BigDecimal;
import java.net.URL;

/**
 * Tests various concepts against the XMLHelper, including ...
 * <ul>
 * <li> Verification of change summary serialization before and after undoChanges()
 * <li> Round tripping of serialization
 * <li> Definition of types using dynamic API
 * <li> Handling of sequenced types
 * <li> Handling of open sequenced types
 * </ul>
 * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=45">2.1 spec section 3.11</a>
 */
public class XMLHelperTest extends CTSTestCase {
    private static final String CUSTOMER1_XML = "/customer1.xml";
    private static final String CUSTOMER2_XML = "/customer2.xml";
    private static final String MIXED_XML = "/mixed2.xml";
    private static final String MIXEDOPEN_XML = "/mixedopen.xml";

    /**
     * Verify how the XMLHelper handles serialization of a DataObject which includes a ChangeSummary.<br/>
     * Checks are made before and after an {@link ChangeSummary#undoChanges()} call
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=28">2.1 spec section 3.3.5</a>
     * @see XMLHelper#save(DataObject, String, String)
     */
    @Test
    public void testChangeSummary() throws Exception {

        final String TEST_MODEL = "/simpleWithChangeSummary.xsd";
        final String TEST_NAMESPACE = "http://www.example.com/simpleCS";

        final String TEST_DATA_BEFORE_UNDO = "/simpleWithChangeSummary.xml";
        final String TEST_DATA_AFTER_UNDO = "/simpleWithChangeSummaryUndone.xml";

        // Populate the meta data for the test (Stock Quote) model
        URL url = getClass().getResource(TEST_MODEL);
        InputStream inputStream = url.openStream();
        getScope().getXSDHelper().define(inputStream, url.toString());
        inputStream.close();

        Type quoteType = getScope().getTypeHelper().getType(TEST_NAMESPACE, "RootQuote");
        DataObject quote = getScope().getDataFactory().create(quoteType);

        ChangeSummary cs = quote.getChangeSummary();
        ChangeSummary csp = (ChangeSummary)quote.get("changes");

        assertSame("The ChangeSummary Property should be returned by getChangeSummary.", cs, csp);

        quote.setString("symbol", "fbnt");
        quote.setString("companyName", "FlyByNightTechnology");
        quote.setBigDecimal("price", new BigDecimal("1000.0"));
        DataObject child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("1500.0"));
        child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("2000.0"));
        child = child.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("2000.99"));
        child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("2500.0"));

        // Begin logging changes
        //
        cs.beginLogging();

        // Modify the data graph in various ways
        //
        quote.setString("symbol", "FBNT");
        quote.setBigDecimal("price", new BigDecimal("999.0"));
        quote.setDouble("volume", 1000);

        child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("3000.0"));
        child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("4000.0"));

        quote.getDataObject("quotes[2]").delete();

        // Stop logging changes and serialize the resulting data graph

        cs.endLogging();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        getScope().getXMLHelper().save(quote, TEST_NAMESPACE, "stockQuote", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(TEST_DATA_BEFORE_UNDO)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect the ChangeSummary: " + e.getMessage());
        }

        // Undo all changes and then serialize the resulting data graph again

        cs.undoChanges();

        baos = new ByteArrayOutputStream();
        getScope().getXMLHelper().save(quote, TEST_NAMESPACE, "stockQuote", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(TEST_DATA_AFTER_UNDO)
            );
        }
        catch (Exception e) {
            fail( "XMLHelper did not accurately reflect the ChangeSummary after undoChanges(): " + e.getMessage() );
        }
    }

    /**
     * Verify how the XMLHelper handles open content.<br/>
     * Ensures that the open content is serialized properly.
     * Uses global properties from the XSD, and open content properties
     * defined by the dynamic API.<br/>
     * TODO -- is this primarily a TypeHelper test? Consider moving.
     * 
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=38">2.1 spec section 3.6.6</a>
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=41">2.1 spec section 3.8.3</a>
     */
    @Test
    public void testDefineOpenContentProperty() throws IOException {
        final String TEST_MODEL = "/open.xsd";
        final String TEST_NAMESPACE = "http://www.example.com/open";
        final String TEST_DATA = "/openContentProperty.xml";

        TypeHelper typeHelper;
        XSDHelper xsdHelper;
        XMLHelper xmlHelper;
        DataFactory dataFactory;

        typeHelper = getScope().getTypeHelper();
        dataFactory = getScope().getDataFactory();
        xsdHelper = getScope().getXSDHelper();
        xmlHelper = getScope().getXMLHelper();

        // Populate the meta data for the test (Stock Quote) model
        URL url = getClass().getResource(TEST_MODEL);
        InputStream inputStream = url.openStream();
        xsdHelper.define(inputStream, url.toString());
        inputStream.close();

        Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote");
        DataObject quote = dataFactory.create(quoteType);

        assertNotNull( quote );

        quote.setString("symbol", "s1");

        Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company");
        DataObject company = quote.createDataObject(companyProperty);
        company.setString("name", "FlyByNightTechnology");

        Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price");
        quote.getList(priceProperty).add(new BigDecimal("1000.0"));

        // Define a new SDO open content property with simple type
        DataObject p = dataFactory.create("commonj.sdo", "Property");
        p.set("type", typeHelper.getType("commonj.sdo", "Decimal"));
        p.set("name", "highPrice");
        Property highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);

        quote.setBigDecimal(highPrice, new BigDecimal("1100.0"));

        // Define a new SDO open content property with complex type
        DataObject mutualFundQuotePropertyDef = dataFactory.create("commonj.sdo", "Property");
        mutualFundQuotePropertyDef.set("type", quoteType);
        mutualFundQuotePropertyDef.set("name", "mutualFundQuote");
        mutualFundQuotePropertyDef.setBoolean("containment", true);
        Property mutualFundQuoteProperty =
            typeHelper.defineOpenContentProperty(TEST_NAMESPACE, mutualFundQuotePropertyDef);

        DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty);
        mutualFundQuote.setString("symbol", "mutual-1");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(TEST_DATA)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect open content." + e.getMessage());
        }

        // validate existing property condition
        Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
        assertTrue("The expected Property equality was not true", highPrice.equals(duplicateProp));

        // validate error condition, where new property exists with different
        // type
        boolean errorCondition = false;
        try {
            p = dataFactory.create("commonj.sdo", "Property");
            p.set("type", typeHelper.getType("commonj.sdo", "String"));
            p.set("name", "highPrice");
            highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
        } catch (IllegalArgumentException ex) {
            errorCondition = true;
        }
        assertTrue("Should not be able to redefine a Property with a different Type.", errorCondition);
    }

    /**
     * Verify how the XMLHelper handles Types defined using the TypeHelper. Save
     * and load the Dataobject with the XMLHelper as an intermediate step.<br/>
     * TODO this is a hybrid test that needs some refactoring.  It implicitly tests
     * dynamic type creation, creation of dynamic types, xml round tripping and the
     * dataObject API without a great deal of structure.  Some assertions are 
     * irrelevant since the tests would throw NPEs before performing the
     * tests.  Other assertions could be stronger than checking for non-null. See also
     * testDefineTypes for similar issues.<br/>
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=41">SDO spec 2..1 section 3.8.4</a>
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=46">SDO spec 2..1 section 3.11.3</a>
     * @see TypeHelper#define(DataObject)
     * @see XMLHelper#save(DataObject, String, String, java.io.OutputStream)
     * @see XMLHelper#load(InputStream, String, Object)
     * 
     */
    @Test
    public void testDefineTypeRoundTrip() throws Exception {
        TypeHelper types = getScope().getTypeHelper();
        DataFactory factory = getScope().getDataFactory();
        XMLHelper xmlHelper = getScope().getXMLHelper();

        Type intType = types.getType("commonj.sdo", "Int");
        assertNotNull( intType );
        Type stringType = types.getType("commonj.sdo", "String");

        // create a new Type for Customers
        DataObject customerType = factory.create("commonj.sdo", "Type");
        customerType.set("uri", "http://example.com/customer");
        customerType.set("name", "Customer");

        Property xmlElementProp = getScope().getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);

        
        // create a customer number property
        DataObject custNumProperty = customerType.createDataObject("property");
        custNumProperty.set("name", "custNum");
        custNumProperty.set("type", intType);
        custNumProperty.setBoolean(xmlElementProp, false);

        // create a first name property
        DataObject firstNameProperty = customerType.createDataObject("property");
        firstNameProperty.set("name", "firstName");
        firstNameProperty.set("type", stringType);
        firstNameProperty.setBoolean(xmlElementProp, false);

        // create a last name property
        DataObject lastNameProperty = customerType.createDataObject("property");
        lastNameProperty.set("name", "lastName");
        lastNameProperty.set("type", stringType);
        lastNameProperty.setBoolean(xmlElementProp, false);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlHelper.save(customerType, "commonj.sdo", "type", baos);

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        XMLDocument xdoc = xmlHelper.load(bais);

        customerType = xdoc.getRootObject();

        // now define the Customer type so that customers can be made
        types.define(customerType);

        DataObject customer1 = factory.create("http://example.com/customer", "Customer");

        customer1.setInt("custNum", 1);
        customer1.set("firstName", "John");
        customer1.set("lastName", "Adams");
        DataObject customer2 = factory.create("http://example.com/customer", "Customer");
        customer2.setInt("custNum", 2);
        customer2.set("firstName", "Jeremy");
        customer2.set("lastName", "Pavick");

        assertNotNull("Customer1 should not be null", customer1);
        Type type = customer1.getType();
        assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
        assertNotNull("Customer1.firstName should not be null", type.getProperty("firstName"));
        assertNotNull("Customer1.lastName should not be null", type.getProperty("lastName"));
        assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
        assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
        assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);

        assertNotNull("Customer2 should not be null", customer2);
        type = customer2.getType();
        assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
        assertNotNull("Customer1.custNum should not be null", type.getProperty("firstName"));
        assertNotNull("Customer1.custNum should not be null", type.getProperty("lastName"));
        assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
        assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
        assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);

        baos = new ByteArrayOutputStream();
        xmlHelper.save(customer1, "http://example.com/customer", "Customer", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(CUSTOMER1_XML)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect customer1: " + e.getMessage());
        }

        baos = new ByteArrayOutputStream();
        xmlHelper.save(customer2, "http://example.com/customer", "Customer", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(CUSTOMER2_XML)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect customer2: " + e.getMessage());
        }

    }

    /**
     * Verify how the XMLHelper handles Types defined using the TypeHelper.
     * TODO this is the same as {@link XMLHelperTest#testDefineTypeRoundTrip()} without
     * the round tripping of the metametadata. See the issues described in the doc for that method.
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=41">SDO spec 2..1 section 3.8.4</a>
     * @see TypeHelper#define(DataObject)

     */
    @Test
    public void testDefineType() throws Exception {
        TypeHelper types = getScope().getTypeHelper();
        DataFactory factory = getScope().getDataFactory();
        XMLHelper xmlHelper = getScope().getXMLHelper();

        Type intType = types.getType("commonj.sdo", "Int");
        Type stringType = types.getType("commonj.sdo", "String");

        // create a new Type for Customers
        DataObject customerType = factory.create("commonj.sdo", "Type");
        customerType.set("uri", "http://example.com/customer");
        customerType.set("name", "Customer");

        Property xmlElementProp = getScope().getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);
        
        // create a customer number property
        DataObject custNumProperty = customerType.createDataObject("property");
        custNumProperty.set("name", "custNum");
        custNumProperty.set("type", intType);
        custNumProperty.setBoolean(xmlElementProp, false);

        // create a first name property
        DataObject firstNameProperty = customerType.createDataObject("property");
        firstNameProperty.set("name", "firstName");
        firstNameProperty.set("type", stringType);
        firstNameProperty.setBoolean(xmlElementProp, false);

        // create a last name property
        DataObject lastNameProperty = customerType.createDataObject("property");
        lastNameProperty.set("name", "lastName");
        lastNameProperty.set("type", stringType);
        lastNameProperty.setBoolean(xmlElementProp, false);

        // now define the Customer type so that customers can be made
        types.define(customerType);

        DataObject customer1 = factory.create("http://example.com/customer", "Customer");
        customer1.setInt("custNum", 1);
        customer1.set("firstName", "John");
        customer1.set("lastName", "Adams");
        DataObject customer2 = factory.create("http://example.com/customer", "Customer");
        customer2.setInt("custNum", 2);
        customer2.set("firstName", "Jeremy");
        customer2.set("lastName", "Pavick");

        assertNotNull("Customer1 should not be null", customer1);
        Type type = customer1.getType();
        assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
        assertNotNull("Customer1.firstName should not be null", type.getProperty("firstName"));
        assertNotNull("Customer1.lastName should not be null", type.getProperty("lastName"));
        assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
        assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
        assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);

        assertNotNull("Customer2 should not be null", customer2);
        type = customer2.getType();
        assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
        assertNotNull("Customer1.custNum should not be null", type.getProperty("firstName"));
        assertNotNull("Customer1.custNum should not be null", type.getProperty("lastName"));
        assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
        assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
        assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlHelper.save(customer1, "http://example.com/customer", "Customer", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(CUSTOMER1_XML)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect customer1: " + e.getMessage());
        }

        baos = new ByteArrayOutputStream();
        xmlHelper.save(customer2, "http://example.com/customer", "Customer", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(CUSTOMER2_XML)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect customer2: " + e.getMessage());
        }
    }

    /**
     * Verify how the XMLHelper handles defined Sequence types.
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=18">SDO spec 2..1 section 3.1.8</a>
     * @see DataObject#getSequence()
     * @see Sequence#addText(String)
     * @see Sequence#add(Property, Object)
     */
    @Test
    public void testDefineSequencedType() throws Exception {

        TypeHelper types = getScope().getTypeHelper();
        DataFactory factory = getScope().getDataFactory();
        XMLHelper xmlHelper = getScope().getXMLHelper();

        Type stringType = types.getType("commonj.sdo", "String");
        Type decimalType = types.getType("commonj.sdo", "Decimal");

        // Define a new mixed type - MixedQuote
        DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
        mixedQuoteType.set("uri", "http://www.example.com/mixed");
        mixedQuoteType.set("name", "MixedQuote");
        mixedQuoteType.set("sequenced", Boolean.TRUE);

        DataObject symbolProperty = mixedQuoteType.createDataObject("property");
        symbolProperty.set("name", "symbol");
        symbolProperty.set("type", stringType);

        DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
        companyNameProperty.set("name", "companyName");
        companyNameProperty.set("type", stringType);

        DataObject priceProperty = mixedQuoteType.createDataObject("property");
        priceProperty.set("name", "price");
        priceProperty.set("type", decimalType);

        DataObject quotesProperty = mixedQuoteType.createDataObject("property");
        quotesProperty.set("name", "quotes");
        quotesProperty.set("type", mixedQuoteType);
        quotesProperty.set("many", Boolean.TRUE);
        quotesProperty.set("containment", Boolean.TRUE);

        types.define(mixedQuoteType);

        DataObject quote = factory.create("http://www.example.com/mixed", "MixedQuote");

        assertTrue("Quote type should be Sequenced", quote.getType().isSequenced());

        Sequence sequence = quote.getSequence();

        sequence.addText("\n  ");

        quote.setString("symbol", "fbnt");

        sequence.addText("\n  ");

        quote.setString("companyName", "FlyByNightTechnology");

        sequence.addText("\n  some text\n  ");

        DataObject child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("2000.0"));

        sequence.addText("\n  more text\n  ");

        // quote.setBigDecimal("price", new BigDecimal("1000.0"));
        sequence.add("price", new BigDecimal("1000.0"));

        sequence.addText("\n");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlHelper.save(quote, "http://www.example.com/mixed", "mixedStockQuote", baos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(MIXED_XML)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect quote: " + e.getMessage());
        }
    }

    /**
     * Verify how the XMLHelper handles Types which are Sequenced and Open.
     * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=18">SDO spec 2..1 section 3.1.8</a>
     * @see DataObject#getSequence()
     * @see Sequence#addText(String)
     * @see Sequence#add(Property, Object)
     * @see TypeHelper#defineOpenContentProperty(String, DataObject)
     * @see TypeHelper#getOpenContentProperty(String, String)
     */
    @Test
    public void testDefineSequencedOpenType() throws Exception {
        TypeHelper types = getScope().getTypeHelper();
        DataFactory factory = getScope().getDataFactory();
        XMLHelper xmlHelper = getScope().getXMLHelper();

        Type stringType = types.getType("commonj.sdo", "String");
        Type decimalType = types.getType("commonj.sdo", "Decimal");

        // Define a new mixed type - MixedQuote
        DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
        mixedQuoteType.set("uri", "http://www.example.com/mixed");
        mixedQuoteType.set("name", "MixedOpenQuote");
        mixedQuoteType.set("sequenced", Boolean.TRUE);
        mixedQuoteType.set("open", Boolean.TRUE);

        // DataObject symbolProperty =
        // mixedQuoteType.createDataObject("property");
        // symbolProperty.set("name", "symbol");
        // symbolProperty.set("type", stringType);

        DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
        companyNameProperty.set("name", "companyName");
        companyNameProperty.set("type", stringType);

        DataObject priceProperty = mixedQuoteType.createDataObject("property");
        priceProperty.set("name", "price");
        priceProperty.set("type", decimalType);

        DataObject quotesProperty = mixedQuoteType.createDataObject("property");
        quotesProperty.set("name", "quotes");
        quotesProperty.set("type", mixedQuoteType);
        quotesProperty.set("many", Boolean.TRUE);
        quotesProperty.set("containment", Boolean.TRUE);

        types.define(mixedQuoteType);

        // Define a global property
        DataObject symbolProperty = factory.create("commonj.sdo", "Property");
        symbolProperty.set("name", "symbol");
        symbolProperty.set("type", stringType);
        symbolProperty.set("containment", Boolean.TRUE);

        types.defineOpenContentProperty("http://www.example.com/open", symbolProperty);

        DataObject quote = factory.create("http://www.example.com/mixed", "MixedOpenQuote");

        assertTrue("Quote type should be Sequenced.", quote.getType().isSequenced());

        Sequence sequence = quote.getSequence();

        sequence.addText("\n  ");

        Property definedSymbolProperty = types.getOpenContentProperty("http://www.example.com/open", "symbol");
        quote.setString(definedSymbolProperty, "fbnt");

        sequence.addText("\n  ");

        quote.setString("companyName", "FlyByNightTechnology");

        sequence.addText("\n  some text\n  ");

        DataObject child = quote.createDataObject("quotes");
        child.setBigDecimal("price", new BigDecimal("2000.0"));

        sequence.addText("\n  more text\n  ");

        // quote.setBigDecimal("price", new BigDecimal("1000.0"));
        sequence.add("price", new BigDecimal("1000.0"));

        sequence.addText("\n");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", baos);

        FileOutputStream fos = new FileOutputStream("XMLTCOutput");
        xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", fos);

        try {
            XMLEqualityChecker.compareXmlFiles(
                    new ByteArrayInputStream(baos.toByteArray()),
                    getClass().getResource(MIXEDOPEN_XML)
            );
        }
        catch (Exception e) {
            fail("XMLHelper did not accurately reflect quote: " + e.getMessage());
        }
    }
    
    @Before
    public void setUp() throws Exception {
      super.setUp();
    }
    
    @After
    public void tearDown() throws Exception {
      super.tearDown();
    }
    
    
}