protected void runTest()

in testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerialize.java [94:150]


    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMSourcedElement element =
                TestDocument.DOCUMENT1.createOMSourcedElement(factory, push, destructive);
        OMDataSource ds = element.getDataSource();
        OMContainer parent = elementContext.wrap(element);
        boolean parentComplete = parent != null && parent.isComplete();
        expansionStrategy.apply(element);
        boolean consuming =
                expansionStrategy.isConsumedAfterSerialization(
                        push, destructive, serializationStrategy);
        for (int iteration = 0; iteration < count; iteration++) {
            boolean expectException =
                    iteration != 0
                            && (consuming
                                    || serializeParent
                                            && !serializationStrategy.isCaching()
                                            && !parentComplete);
            XML result;
            try {
                result = serializationStrategy.serialize(serializeParent ? parent : element);
                if (expectException) {
                    fail("Expected exception");
                }
            } catch (Exception ex) {
                if (!expectException) {
                    throw ex;
                } else {
                    continue;
                }
            }
            InputSource expectedXML =
                    new InputSource(new StringReader(TestDocument.DOCUMENT1.getContent()));
            if (serializeParent) {
                expectedXML = elementContext.getControl(expectedXML);
            }
            assertAbout(xml()).that(result.getInputSource()).hasSameContentAs(expectedXML);
            // If the underlying OMDataSource is non destructive, the expansion status should not
            // have been changed during serialization. If it is destructive and caching is enabled,
            // then the sourced element should be expanded.
            if (expansionStrategy.isExpandedAfterSerialization(
                    push, destructive, serializationStrategy)) {
                assertTrue(element.isExpanded());
                assertEquals(
                        "OMSourcedElement completion status", !consuming, element.isComplete());
            } else {
                assertFalse(element.isExpanded());
            }
            if (parent != null && !serializeParent) {
                // Operations on the OMSourcedElement should have no impact on the parent
                assertEquals("Parent completion status", parentComplete, parent.isComplete());
            }
        }
        if (ds instanceof PullOMDataSource) {
            assertFalse(((PullOMDataSource) ds).hasUnclosedReaders());
        }
    }