jaxp/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java
author joehw
Thu, 15 Jan 2015 19:10:56 -0800
changeset 28445 5a87f52ca380
parent 27538 bd7c7463b5fc
child 34984 48a409c654e9
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:
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     1
/*
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     4
 *
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     8
 *
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    13
 * accompanied this code).
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    14
 *
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    18
 *
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    21
 * questions.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    22
 */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    23
package jaxp.library;
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    24
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    25
import java.io.ByteArrayInputStream;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    26
import java.io.File;
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    27
import java.io.IOException;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    28
import java.io.InputStream;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    29
import java.io.StringWriter;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    30
import java.nio.ByteBuffer;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    31
import java.nio.ByteOrder;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    32
import java.nio.charset.Charset;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    33
import java.nio.charset.StandardCharsets;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    34
import java.nio.charset.UnsupportedCharsetException;
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    35
import java.nio.file.Files;
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    36
import java.nio.file.Paths;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    37
import java.util.HashMap;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    38
import java.util.List;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    39
import java.util.Map;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    40
import java.util.concurrent.ConcurrentHashMap;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    41
import java.util.regex.Pattern;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    42
import java.util.stream.Collectors;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    43
import javax.xml.parsers.DocumentBuilder;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    44
import javax.xml.parsers.DocumentBuilderFactory;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    45
import javax.xml.parsers.ParserConfigurationException;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    46
import javax.xml.transform.Transformer;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    47
import javax.xml.transform.TransformerException;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    48
import javax.xml.transform.TransformerFactory;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    49
import javax.xml.transform.dom.DOMSource;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    50
import javax.xml.transform.stream.StreamResult;
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    51
import static org.testng.Assert.fail;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    52
import org.w3c.dom.Document;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    53
import org.w3c.dom.Node;
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    54
import org.xml.sax.SAXException;
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    55
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    56
/**
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    57
 * This is an interface provide basic support for JAXP functional test.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    58
 */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    59
public class JAXPTestUtilities {
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    60
    /**
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    61
     * Prefix for error message.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    62
     */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    63
    public static final String ERROR_MSG_HEADER = "Unexcepted exception thrown:";
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    64
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    65
    /**
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    66
     * Prefix for error message on clean up block.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    67
     */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    68
    public static final String ERROR_MSG_CLEANUP = "Clean up failed on %s";
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    69
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    70
    /**
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    71
     * Force using slash as File separator as we always use cygwin to test in
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    72
     * Windows platform.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    73
     */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    74
    public static final String FILE_SEP = "/";
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    75
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    76
    /**
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    77
     * Current test directory.
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    78
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    79
    public static final String USER_DIR =
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    80
            System.getProperty("user.dir", ".") + FILE_SEP;;
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    81
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    82
    /**
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    83
     * A map storing every test's current test file pointer. File number should
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    84
     * be incremental and it's a thread-safe reading on this file number.
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    85
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    86
    private static final ConcurrentHashMap<Class, Integer> currentFileNumber
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
    87
                = new ConcurrentHashMap<>();
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    88
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
    89
    /**
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    90
     * BOM table for storing BOM header.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    91
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    92
    private final static Map<String, byte[]> bom = new HashMap();
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    93
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    94
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    95
     * Initialize all BOM headers.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    96
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    97
    static {
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    98
        bom.put("UTF-8", new byte[]{(byte)0xEF, (byte) 0xBB, (byte) 0xBF});
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
    99
        bom.put("UTF-16BE", new byte[]{(byte)0xFE, (byte)0xFF});
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   100
        bom.put("UTF-16LE", new byte[]{(byte)0xFF, (byte)0xFE});
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   101
        bom.put("UTF-32BE", new byte[]{(byte)0x00, (byte)0x00, (byte)0xFE, (byte)0xFF});
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   102
        bom.put("UTF-32LE", new byte[]{(byte)0xFF, (byte)0xFE, (byte)0x00, (byte)0x00});
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   103
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   104
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   105
    /**
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   106
     * Compare contents of golden file with test output file line by line.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   107
     * return true if they're identical.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   108
     * @param goldfile Golden output file name
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   109
     * @param outputfile Test output file name
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   110
     * @return true if two files are identical.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   111
     *         false if two files are not identical.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   112
     * @throws IOException if an I/O error occurs reading from the file or a
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   113
     *         malformed or unmappable byte sequence is read.
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   114
     */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   115
    public static boolean compareWithGold(String goldfile, String outputfile)
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   116
            throws IOException {
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   117
        return compareWithGold(goldfile, outputfile, StandardCharsets.UTF_8);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   118
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   119
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   120
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   121
     * Compare contents of golden file with test output file line by line.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   122
     * return true if they're identical.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   123
     * @param goldfile Golden output file name.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   124
     * @param outputfile Test output file name.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   125
     * @param cs the charset to use for decoding.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   126
     * @return true if two files are identical.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   127
     *         false if two files are not identical.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   128
     * @throws IOException if an I/O error occurs reading from the file or a
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   129
     *         malformed or unmappable byte sequence is read.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   130
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   131
    public static boolean compareWithGold(String goldfile, String outputfile,
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   132
             Charset cs) throws IOException {
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   133
        return Files.readAllLines(Paths.get(goldfile)).
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   134
                equals(Files.readAllLines(Paths.get(outputfile), cs));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   135
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   136
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   137
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   138
     * Compare contents of golden file with test output list line by line.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   139
     * return true if they're identical.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   140
     * @param goldfile Golden output file name.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   141
     * @param lines test output list.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   142
     * @return true if file's content is identical to given list.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   143
     *         false if file's content is not identical to given list.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   144
     * @throws IOException if an I/O error occurs reading from the file or a
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   145
     *         malformed or unmappable byte sequence is read
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   146
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   147
    public static boolean compareLinesWithGold(String goldfile, List<String> lines)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   148
            throws IOException {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   149
        return Files.readAllLines(Paths.get(goldfile)).equals(lines);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   150
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   151
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   152
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   153
     * Compare contents of golden file with a test output string.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   154
     * return true if they're identical.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   155
     * @param goldfile Golden output file name.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   156
     * @param string test string.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   157
     * @return true if file's content is identical to given string.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   158
     *         false if file's content is not identical to given string.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   159
     * @throws IOException if an I/O error occurs reading from the file or a
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   160
     *         malformed or unmappable byte sequence is read
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   161
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   162
    public static boolean compareStringWithGold(String goldfile, String string)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   163
            throws IOException {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   164
        return Files.readAllLines(Paths.get(goldfile)).stream().collect(
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   165
                Collectors.joining(System.getProperty("line.separator")))
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   166
                .equals(string);
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   167
    }
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   168
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   169
    /**
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   170
     * Compare contents of golden file with test output file by their document
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   171
     * representation.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   172
     * Here we ignore the white space and comments. return true if they're
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   173
     * lexical identical.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   174
     * @param goldfile Golden output file name.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   175
     * @param resultFile Test output file name.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   176
     * @return true if two file's document representation are identical.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   177
     *         false if two file's document representation are not identical.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   178
     * @throws javax.xml.parsers.ParserConfigurationException if the
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   179
     *         implementation is not available or cannot be instantiated.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   180
     * @throws SAXException If any parse errors occur.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   181
     * @throws IOException if an I/O error occurs reading from the file or a
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   182
     *         malformed or unmappable byte sequence is read .
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   183
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   184
    public static boolean compareDocumentWithGold(String goldfile, String resultFile)
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   185
            throws ParserConfigurationException, SAXException, IOException {
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   186
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   187
        factory.setNamespaceAware(true);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   188
        factory.setCoalescing(true);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   189
        factory.setIgnoringElementContentWhitespace(true);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   190
        factory.setIgnoringComments(true);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   191
        DocumentBuilder db = factory.newDocumentBuilder();
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   192
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   193
        Document goldD = db.parse(Paths.get(goldfile).toFile());
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   194
        goldD.normalizeDocument();
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   195
        Document resultD = db.parse(Paths.get(resultFile).toFile());
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   196
        resultD.normalizeDocument();
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   197
        return goldD.isEqualNode(resultD);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   198
    }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   199
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   200
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   201
     * Compare contents of golden file with the serialization represent by given
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   202
     * DOM node.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   203
     * Here we ignore the white space and comments. return true if they're
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   204
     * lexical identical.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   205
     * @param goldfile Golden output file name.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   206
     * @param node A DOM node instance.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   207
     * @return true if file's content is identical to given node's serialization
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   208
     *         represent.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   209
     *         false if file's content is not identical to given node's
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   210
     *         serialization represent.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   211
     * @throws TransformerException If an unrecoverable error occurs during the
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   212
     *         course of the transformation..
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   213
     * @throws IOException if an I/O error occurs reading from the file or a
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   214
     *         malformed or unmappable byte sequence is read .
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   215
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   216
    public static boolean compareSerializeDOMWithGold(String goldfile, Node node)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   217
            throws TransformerException, IOException {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   218
        TransformerFactory factory = TransformerFactory.newInstance();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   219
        // Use identity transformer to serialize
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   220
        Transformer identityTransformer = factory.newTransformer();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   221
        StringWriter sw = new StringWriter();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   222
        StreamResult streamResult = new StreamResult(sw);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   223
        DOMSource nodeSource = new DOMSource(node);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   224
        identityTransformer.transform(nodeSource, streamResult);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   225
        return compareStringWithGold(goldfile, sw.toString());
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   226
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   227
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   228
    /**
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   229
     * Convert stream to ByteArrayInputStream by given character set.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   230
     * @param charset target character set.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   231
     * @param file a file that contains no BOM head content.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   232
     * @return a ByteArrayInputStream contains BOM heads and bytes in original
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   233
     *         stream
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   234
     * @throws IOException I/O operation failed or unsupported character set.
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   235
     */
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   236
    public static InputStream bomStream(String charset, String file)
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   237
            throws IOException {
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   238
        String localCharset = charset;
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   239
        if (charset.equals("UTF-16") || charset.equals("UTF-32")) {
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   240
            localCharset
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   241
                += ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN ? "BE" : "LE";
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   242
        }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   243
        if (!bom.containsKey(localCharset))
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   244
            throw new UnsupportedCharsetException("Charset:" + localCharset);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   245
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   246
        byte[] content = Files.readAllLines(Paths.get(file)).stream().
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   247
                collect(Collectors.joining()).getBytes(localCharset);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   248
        byte[] head = bom.get(localCharset);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   249
        ByteBuffer bb = ByteBuffer.allocate(content.length + head.length);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   250
        bb.put(head);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   251
        bb.put(content);
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   252
        return new ByteArrayInputStream(bb.array());
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   253
    }
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   254
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   255
   /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   256
     * Worker method to detect common absolute URLs.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   257
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   258
     * @param s String path\filename or URL (or any, really)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   259
     * @return true if s starts with a common URI scheme (namely
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   260
     * the ones found in the examples of RFC2396); false otherwise
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   261
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   262
    protected static boolean isCommonURL(String s) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   263
        if (null == s)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   264
            return false;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   265
        return Pattern.compile("^(file:|http:|ftp:|gopher:|mailto:|news:|telnet:)")
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   266
                .matcher(s).matches();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   267
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   268
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   269
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   270
     * Utility method to translate a String filename to URL.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   271
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   272
     * If the name starts with a common URI scheme (namely the ones
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   273
     * found in the examples of RFC2396), then simply return the
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   274
     * name as-is (the assumption is that it's already a URL).
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   275
     * Otherwise we attempt (cheaply) to convert to a file:/ URL.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   276
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   277
     * @param filename local path/filename of a file.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   278
     * @return a file:/ URL if filename represent a file, the same string if
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   279
     *         it appears to already be a URL.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   280
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   281
    public static String filenameToURL(String filename) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   282
        return Paths.get(filename).toUri().toASCIIString();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   283
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   284
27538
bd7c7463b5fc 8047962: XML test colocation: AuctionPortal test
joehw
parents: 27216
diff changeset
   285
    /**
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   286
     * Prints error message if an exception is thrown
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   287
     * @param ex The exception is thrown by test.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   288
     */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   289
    public static void failUnexpected(Throwable ex) {
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   290
        fail(ERROR_MSG_HEADER, ex);
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   291
    }
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   292
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   293
    /**
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   294
     * Prints error message if an exception is thrown when clean up a file.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   295
     * @param ex The exception is thrown in cleaning up a file.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   296
     * @param name Cleaning up file name.
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   297
     */
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   298
    public static void failCleanup(IOException ex, String name) {
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   299
        fail(String.format(ERROR_MSG_CLEANUP, name), ex);
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   300
    }
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   301
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   302
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   303
     * Retrieve next test output file name. This method is a thread-safe method.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   304
     * @param clazz test class.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   305
     * @return next test output file name.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   306
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   307
    public static String getNextFile(Class clazz) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   308
        int nextNumber = currentFileNumber.contains(clazz)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   309
                ? currentFileNumber.get(clazz) + 1 : 1;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   310
        Integer i = currentFileNumber.putIfAbsent(clazz, nextNumber);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   311
        if (i != null && i != nextNumber) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   312
            do {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   313
                nextNumber = currentFileNumber.get(clazz) + 1;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   314
            } while (currentFileNumber.replace(clazz, nextNumber -1, nextNumber));
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   315
        }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   316
        return USER_DIR + clazz.getName() + nextNumber + ".out";
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   317
    }
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   318
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   319
    /**
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   320
     * Acquire a full path string by given class name and relative path string.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   321
     * @param clazz Class name for the test.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   322
     * @param relativeDir relative path between java source file and expected
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   323
     *        path.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   324
     * @return a string represents the full path of accessing path.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   325
     */
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   326
    public static String getPathByClassName(Class clazz, String relativeDir) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   327
        String packageName = FILE_SEP +
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   328
                clazz.getPackage().getName().replaceAll("[.]", FILE_SEP);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   329
        String javaSourcePath = System.getProperty("test.src").replaceAll("\\" + File.separator, FILE_SEP)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   330
                + packageName + FILE_SEP;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   331
        String normalizedPath = Paths.get(javaSourcePath, relativeDir).normalize().
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   332
                toAbsolutePath().toString();
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   333
        return normalizedPath.replace("\\", FILE_SEP) + FILE_SEP;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27538
diff changeset
   334
    }
27216
e63176413817 8051540: Convert JAXP functional tests to jtreg(TestNG): SAX and Transform
joehw
parents:
diff changeset
   335
}