jaxp/test/javax/xml/jaxp/functional/test/auctionportal/AuctionItemRepository.java
author joehw
Thu, 15 Jan 2015 19:10:56 -0800
changeset 28445 5a87f52ca380
parent 27538 bd7c7463b5fc
child 30707 47b636cd6456
permissions -rw-r--r--
8051563: Update JAXP functional tests Reviewed-by: lancea, joehw Contributed-by: tristan.yan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     1
/*
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     4
 *
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     8
 *
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    13
 * accompanied this code).
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    14
 *
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    18
 *
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    21
 * questions.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    22
 */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    23
package test.auctionportal;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    24
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    25
import static com.sun.org.apache.xerces.internal.impl.Constants.SP_ENTITY_EXPANSION_LIMIT;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    26
import static com.sun.org.apache.xerces.internal.impl.Constants.SP_MAX_OCCUR_LIMIT;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    27
import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_LANGUAGE;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    28
import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_SOURCE;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    29
import static org.testng.Assert.assertTrue;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    30
import java.io.File;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    31
import java.io.FileInputStream;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    32
import java.io.FileOutputStream;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    33
import java.io.FilePermission;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    34
import java.io.InputStream;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    35
import static javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    36
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    37
import javax.xml.parsers.DocumentBuilder;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    38
import javax.xml.parsers.DocumentBuilderFactory;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    39
import javax.xml.parsers.SAXParser;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    40
import javax.xml.parsers.SAXParserFactory;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    41
import javax.xml.transform.TransformerFactory;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    42
import javax.xml.transform.dom.DOMSource;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    43
import javax.xml.transform.stream.StreamResult;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    44
import jaxp.library.JAXPFileBaseTest;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    45
import static jaxp.library.JAXPTestUtilities.USER_DIR;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    46
import static jaxp.library.JAXPTestUtilities.compareDocumentWithGold;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    47
import static org.testng.Assert.assertFalse;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    48
import org.testng.annotations.Test;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    49
import org.w3c.dom.Document;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    50
import org.xml.sax.SAXParseException;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    51
import static test.auctionportal.HiBidConstants.GOLDEN_DIR;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    52
import static test.auctionportal.HiBidConstants.XML_DIR;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    53
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    54
/**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    55
 * This is a test class for the Auction portal HiBid.com.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    56
 */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    57
public class AuctionItemRepository extends JAXPFileBaseTest {
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    58
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    59
     * XML file for parsing.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    60
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    61
    private final static String ENTITY_XML = XML_DIR + "entity.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    62
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    63
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    64
     * Feature name.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    65
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    66
    private final static String FEATURE_NAME = "http://xml.org/sax/features/namespace-prefixes";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    67
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    68
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    69
     * Setting the EntityExpansion Limit to 128000 and checks if the XML
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    70
     * document that has more than two levels of entity expansion is parsed or
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    71
     * not. Previous system property was changed to jdk.xml.entityExpansionLimit
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    72
     * see http://docs.oracle.com/javase/tutorial/jaxp/limits/limits.html.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    73
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    74
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    75
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    76
    @Test
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    77
    public void testEntityExpansionSAXPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    78
        SAXParserFactory factory = SAXParserFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    79
        // Secure processing will limit XML processing to conform to
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    80
        // implementation limits.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    81
        factory.setFeature(FEATURE_SECURE_PROCESSING, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    82
        // Set entityExpansionLimit as 2 should expect fatalError
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    83
        setSystemProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(128000));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    84
        SAXParser parser = factory.newSAXParser();
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    85
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    86
        MyErrorHandler fatalHandler = new MyErrorHandler();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    87
        setPermissions(new FilePermission(ENTITY_XML, "read"));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    88
        parser.parse(new File(ENTITY_XML), fatalHandler);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    89
        assertFalse(fatalHandler.isAnyError());
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    90
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    91
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    92
     * Setting the EntityExpansion Limit to 2 and checks if the XML
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    93
     * document that has more than two levels of entity expansion is parsed or
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    94
     * not. Previous system property was changed to jdk.xml.entityExpansionLimit
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    95
     * see http://docs.oracle.com/javase/tutorial/jaxp/limits/limits.html.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    96
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    97
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    98
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
    99
    @Test(expectedExceptions = SAXParseException.class)
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   100
    public void testEntityExpansionSAXNeg() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   101
        SAXParserFactory factory = SAXParserFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   102
        // Secure processing will limit XML processing to conform to
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   103
        // implementation limits.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   104
        factory.setFeature(FEATURE_SECURE_PROCESSING, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   105
        // Set entityExpansionLimit as 2 should expect SAXParseException.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   106
        setSystemProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(2));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   107
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   108
        SAXParser parser = factory.newSAXParser();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   109
        MyErrorHandler fatalHandler = new MyErrorHandler();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   110
        setPermissions(new FilePermission(ENTITY_XML, "read"));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   111
        parser.parse(new File(ENTITY_XML), fatalHandler);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   112
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   113
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   114
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   115
     * Testing set MaxOccursLimit to 10000 in the secure processing enabled for
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   116
     * SAXParserFactory.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   117
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   118
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   119
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   120
    @Test
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   121
    public void testMaxOccurLimitPos() throws Exception {
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   122
        String schema_file = XML_DIR + "toys.xsd";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   123
        String xml_file = XML_DIR + "toys.xml";
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   124
        SAXParserFactory factory = SAXParserFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   125
        factory.setValidating(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   126
        factory.setFeature(FEATURE_SECURE_PROCESSING, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   127
        setSystemProperty(SP_MAX_OCCUR_LIMIT, String.valueOf(10000));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   128
        SAXParser parser = factory.newSAXParser();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   129
        parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   130
        setPermissions(new FilePermission(XML_DIR + "-", "read"));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   131
        parser.setProperty(JAXP_SCHEMA_SOURCE, new File(schema_file));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   132
        try (InputStream is = new FileInputStream(xml_file)) {
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   133
            MyErrorHandler eh = new MyErrorHandler();
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   134
            parser.parse(is, eh);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   135
            assertFalse(eh.isAnyError());
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   136
        }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   137
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   138
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   139
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   140
     * Use a DocumentBuilder to create a DOM object and see if Secure Processing
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   141
     * feature affects the entity expansion.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   142
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   143
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   144
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   145
    @Test
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   146
    public void testEntityExpansionDOMPos() throws Exception  {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   147
        DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   148
        dfactory.setFeature(FEATURE_SECURE_PROCESSING, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   149
        setSystemProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(10000));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   150
        DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   151
        MyErrorHandler eh = new MyErrorHandler();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   152
        dBuilder.setErrorHandler(eh);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   153
        try {
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   154
            setPermissions(new FilePermission(ENTITY_XML, "read"));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   155
            dBuilder.parse(ENTITY_XML);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   156
            assertFalse(eh.isAnyError());
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   157
        } finally {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   158
            setPermissions();
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   159
        }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   160
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   161
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   162
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   163
     * Use a DocumentBuilder to create a DOM object and see how does the Secure
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   164
     * Processing feature and entityExpansionLimit value affects output.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   165
     * Negative test that when entityExpansionLimit is too small.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   166
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   167
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   168
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   169
    @Test(expectedExceptions = SAXParseException.class)
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   170
    public void testEntityExpansionDOMNeg() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   171
        DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   172
        dfactory.setFeature(FEATURE_SECURE_PROCESSING, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   173
        setSystemProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(2));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   174
        DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   175
        MyErrorHandler eh = new MyErrorHandler();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   176
        dBuilder.setErrorHandler(eh);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   177
        setPermissions(new FilePermission(ENTITY_XML, "read"));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   178
        dBuilder.parse(ENTITY_XML);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   179
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   180
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   181
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   182
     * Test xi:include with a SAXParserFactory.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   183
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   184
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   185
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   186
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   187
    public void testXIncludeSAXPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   188
        String resultFile = USER_DIR + "doc_xinclude.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   189
        String goldFile = GOLDEN_DIR + "doc_xincludeGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   190
        String xmlFile = XML_DIR + "doc_xinclude.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   191
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   192
        try(FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   193
            XInclHandler xh = new XInclHandler(fos, null);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   194
            SAXParserFactory spf = SAXParserFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   195
            spf.setNamespaceAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   196
            spf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   197
            spf.setFeature(FEATURE_NAME, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   198
            spf.newSAXParser().parse(new File(xmlFile), xh);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   199
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   200
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   201
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   202
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   203
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   204
     * Test the simple case of including a document using xi:include using a
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   205
     * DocumentBuilder.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   206
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   207
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   208
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   209
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   210
    public void testXIncludeDOMPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   211
        String resultFile = USER_DIR + "doc_xincludeDOM.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   212
        String goldFile = GOLDEN_DIR + "doc_xincludeGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   213
        String xmlFile = XML_DIR + "doc_xinclude.xml";
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   214
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   215
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   216
            dbf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   217
            dbf.setNamespaceAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   218
            Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   219
            doc.setXmlStandalone(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   220
            TransformerFactory.newInstance().newTransformer().
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   221
                    transform(new DOMSource(doc), new StreamResult(fos));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   222
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   223
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   224
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   225
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   226
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   227
     * Test the simple case of including a document using xi:include within a
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   228
     * xi:fallback using a DocumentBuilder.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   229
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   230
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   231
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   232
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   233
    public void testXIncludeFallbackDOMPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   234
        String resultFile = USER_DIR + "doc_fallbackDOM.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   235
        String goldFile = GOLDEN_DIR + "doc_fallbackGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   236
        String xmlFile = XML_DIR + "doc_fallback.xml";
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   237
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   238
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   239
            dbf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   240
            dbf.setNamespaceAware(true);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   241
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   242
            Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   243
            doc.setXmlStandalone(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   244
            TransformerFactory.newInstance().newTransformer()
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   245
                    .transform(new DOMSource(doc), new StreamResult(fos));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   246
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   247
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   248
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   249
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   250
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   251
     * Test for xi:fallback where the fall back text is parsed as text. This
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   252
     * test uses a nested xi:include for the fallback test.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   253
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   254
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   255
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   256
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   257
    public void testXIncludeFallbackTextPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   258
        String resultFile = USER_DIR + "doc_fallback_text.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   259
        String goldFile = GOLDEN_DIR + "doc_fallback_textGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   260
        String xmlFile = XML_DIR + "doc_fallback_text.xml";
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   261
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   262
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   263
            dbf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   264
            dbf.setNamespaceAware(true);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   265
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   266
            Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   267
            doc.setXmlStandalone(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   268
            TransformerFactory.newInstance().newTransformer()
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   269
                    .transform(new DOMSource(doc), new StreamResult(fos));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   270
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   271
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   272
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   273
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   274
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   275
     * Test the XPointer element() framework with XInclude.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   276
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   277
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   278
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   279
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   280
    public void testXpointerElementPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   281
        String resultFile = USER_DIR + "doc_xpointer_element.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   282
        String goldFile = GOLDEN_DIR + "doc_xpointerGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   283
        String xmlFile = XML_DIR + "doc_xpointer_element.xml";
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   284
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   285
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   286
            dbf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   287
            dbf.setNamespaceAware(true);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   288
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   289
            DocumentBuilder db = dbf.newDocumentBuilder();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   290
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   291
            TransformerFactory.newInstance().newTransformer()
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   292
                    .transform(new DOMSource(db.parse(new File(xmlFile))),
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   293
                            new StreamResult(fos));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   294
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   295
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   296
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   297
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   298
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   299
     * Test the XPointer framework with a SAX object.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   300
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   301
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   302
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   303
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   304
    public void testXPointerPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   305
        String resultFile = USER_DIR + "doc_xpointer.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   306
        String goldFile = GOLDEN_DIR + "doc_xpointerGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   307
        String xmlFile = XML_DIR + "doc_xpointer.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   308
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   309
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   310
            SAXParserFactory spf = SAXParserFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   311
            spf.setNamespaceAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   312
            spf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   313
            spf.setFeature(FEATURE_NAME, true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   314
            // parse the file
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   315
            spf.newSAXParser().parse(new File(xmlFile), new XInclHandler(fos, null));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   316
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   317
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   318
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   319
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   320
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   321
     * Test if xi:include may reference the doc containing the include if the
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   322
     * parse type is text.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   323
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   324
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   325
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   326
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   327
    public void testXIncludeLoopPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   328
        String resultFile = USER_DIR + "doc_xinc_loops.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   329
        String goldFile = GOLDEN_DIR + "doc_xinc_loopGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   330
        String xmlFile = XML_DIR + "doc_xinc_loops.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   331
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   332
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   333
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   334
            dbf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   335
            dbf.setNamespaceAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   336
            DocumentBuilder db = dbf.newDocumentBuilder();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   337
            Document doc = db.parse(new File(xmlFile));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   338
            doc.normalizeDocument();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   339
            doc.setXmlStandalone(true);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   340
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   341
            TransformerFactory.newInstance().newTransformer()
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   342
                    .transform(new DOMSource(doc), new StreamResult(fos));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   343
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   344
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   345
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   346
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   347
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   348
     * Test if two non nested xi:include elements can include the same document
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   349
     * with an xi:include statement.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   350
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   351
     * @throws Exception If any errors occur.
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   352
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   353
    @Test(groups = {"readWriteLocalFiles"})
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   354
    public void testXIncludeNestedPos() throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   355
        String resultFile = USER_DIR + "schedule.out";
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   356
        String goldFile = GOLDEN_DIR + "scheduleGold.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   357
        String xmlFile = XML_DIR + "schedule.xml";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   358
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   359
        try (FileOutputStream fos = new FileOutputStream(resultFile)) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   360
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   361
            dbf.setXIncludeAware(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   362
            dbf.setNamespaceAware(true);
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   363
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   364
            Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   365
            doc.setXmlStandalone(true);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   366
            TransformerFactory.newInstance().newTransformer()
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   367
                    .transform(new DOMSource(doc), new StreamResult(fos));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   368
        }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   369
        assertTrue(compareDocumentWithGold(goldFile, resultFile));
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   370
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents:
diff changeset
   371
}