1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import static org.testng.Assert.assertTrue;
  25 
  26 import java.io.File;
  27 import java.nio.file.Path;
  28 import java.nio.file.Paths;
  29 
  30 import static jdk.testlibrary.ProcessTools.executeTestJava;
  31 import jdk.testlibrary.CompilerUtils;
  32 
  33 import org.testng.annotations.BeforeTest;
  34 import org.testng.annotations.Test;
  35 
  36 /*
  37  * @test
  38  * @library /javax/xml/jaxp/libs
  39  * @build jdk.testlibrary.*
  40  * @run testng BasicModularXMLParserTest
  41  * @bug 8078820 8156119
  42  * @summary Tests JAXP lib can instantiate the following interfaces
  43  *          with customized provider module on boot layer
  44  *
  45  *          javax.xml.datatype.DatatypeFactory
  46  *          javax.xml.parsers.DocumentBuilderFactory
  47  *          javax.xml.parsers.SAXParserFactory
  48  *          javax.xml.stream.XMLEventFactory
  49  *          javax.xml.stream.XMLInputFactory
  50  *          javax.xml.stream.XMLOutputFactory
  51  *          javax.xml.transform.TransformerFactory
  52  *          javax.xml.validation.SchemaFactory
  53  *          javax.xml.xpath.XPathFactory
  54  *          org.xml.sax.XMLReader
  55  */
  56 
  57 @Test
  58 public class BasicModularXMLParserTest {
  59 
  60     private static final String TEST_SRC = System.getProperty("test.src");
  61 
  62     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
  63     private static final Path MOD_DIR1 = Paths.get("mod1");
  64     private static final Path MOD_DIR2 = Paths.get("mod2");
  65     private static final Path CLASSES_DIR = Paths.get("classes");
  66 
  67     /*
  68      * Compiles all modules used by the test
  69      */
  70     @BeforeTest
  71     public void compileAll() throws Exception {
  72         assertTrue(CompilerUtils.compile(SRC_DIR.resolve("xmlprovider1"), MOD_DIR1.resolve("xmlprovider1")));
  73         assertTrue(CompilerUtils.compile(SRC_DIR.resolve("xmlprovider2"), MOD_DIR2.resolve("xmlprovider2")));
  74         assertTrue(CompilerUtils.compile(SRC_DIR.resolve("unnamed"), CLASSES_DIR));
  75     }
  76 
  77     /*
  78      * test the default JAXP implementation
  79      */
  80     public void testDefault() throws Exception {
  81         int exitValue
  82             = executeTestJava("-cp", CLASSES_DIR.toString(),
  83                               "Main")
  84                 .outputTo(System.out)
  85                 .errorTo(System.out)
  86                 .getExitValue();
  87 
  88         assertTrue(exitValue == 0);
  89     }
  90 
  91     /*
  92      * test loading one provider module
  93      */
  94     public void testWithOneProvider() throws Exception {
  95         int exitValue
  96             = executeTestJava("--module-path", MOD_DIR1.toString(),
  97                               "-cp", CLASSES_DIR.toString(),
  98                               "Main", "xmlprovider1")
  99                 .outputTo(System.out)
 100                 .errorTo(System.out)
 101                 .getExitValue();
 102 
 103         assertTrue(exitValue == 0);
 104     }
 105 
 106     /*
 107      * test loading both provider modules
 108      */
 109     public void testWithTwoProvider() throws Exception {
 110         int exitValue
 111             = executeTestJava("--module-path", MOD_DIR1.toString() + File.pathSeparator + MOD_DIR2.toString(),
 112                               "-cp", CLASSES_DIR.toString(),
 113                               "Main", "xmlprovider1", "xmlprovider2")
 114                 .outputTo(System.out)
 115                 .errorTo(System.out)
 116                 .getExitValue();
 117 
 118         assertTrue(exitValue == 0);
 119     }
 120 
 121 }