1 /* 2 * Copyright (c) 2015, 2018, 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 jdk.test.lib.JDKToolFinder; 25 import jdk.test.lib.Utils; 26 import jdk.test.lib.compiler.CompilerUtils; 27 import jdk.test.lib.process.ProcessTools; 28 29 import java.io.IOException; 30 import java.nio.file.Files; 31 import java.nio.file.Path; 32 import java.util.Collection; 33 import java.util.Collections; 34 import java.util.List; 35 import java.util.stream.Collectors; 36 import java.util.stream.Stream; 37 38 import static jdk.test.lib.Utils.TEST_SRC; 39 40 /* 41 * @test 42 * @summary Test of JNDI factories using classes exported by third-party modules. 43 * @library /test/lib 44 * @modules jdk.compiler 45 * @run main RunBasic 46 */ 47 48 /* 49 * Demonstrates Java object storage/retrieval, LDAP control and URL context 50 * usage using an LDAP directory. The objects and their associated object 51 * factories, state factories, control factories and URL context factories 52 * are exported from third-party modules. 53 * 54 * Seven types of object are used: 55 * - an AWT object (Serializable) from the 'java.desktop' JDK module 56 * - a Person object (DirContext) from the 'person' third-party module 57 * - a Fruit object (Referenceable) from the 'fruit' third-party module 58 * - an RMI object (Remote) from the 'hello' third-party module 59 * - an LDAP request control (Control) from the 'foo' third-party module 60 * - an LDAP response control (Control) from the 'authz' third-party module 61 * - an ldapv4 URL (DirContext) from the 'ldapv4' third-party module 62 */ 63 64 public class RunBasic { 65 66 private static final List<String> JAVA_CMDS; 67 68 static { 69 String javaPath = JDKToolFinder.getJDKTool("java"); 70 71 JAVA_CMDS = Stream 72 .concat(Stream.of(javaPath), Stream.of(Utils.getTestJavaOpts())) 73 .collect(Collectors.collectingAndThen(Collectors.toList(), 74 Collections::unmodifiableList)); 75 } 76 77 public static void main(String[] args) throws Throwable { 78 // prepare all test modules 79 prepareModule("person"); 80 prepareModule("fruit"); 81 prepareModule("hello"); 82 prepareModule("foo"); 83 prepareModule("authz"); 84 prepareModule("ldapv4"); 85 prepareModule("test", "--module-source-path", 86 Path.of(TEST_SRC, "src").toString()); 87 88 // run tests 89 runTest("java.desktop", "test.StoreObject"); 90 runTest("person", "test.StorePerson"); 91 runTest("fruit", "test.StoreFruit"); 92 runTest("hello", "test.StoreRemote"); 93 runTest("foo", "test.ConnectWithFoo"); 94 runTest("authz", "test.ConnectWithAuthzId"); 95 runTest("ldapv4", "test.ReadByUrl"); 96 } 97 98 private static void prepareModule(String mod, String... opts) 99 throws IOException { 100 System.out.println("Preparing the '" + mod + "' module..."); 101 makeDir("mods", mod); 102 CompilerUtils.compile(Path.of(TEST_SRC, "src", mod), 103 Path.of("mods", (mod.equals("test") ? "" : mod)), opts); 104 } 105 106 private static void makeDir(String first, String... more) 107 throws IOException { 108 Files.createDirectories(Path.of(first, more)); 109 } 110 111 private static void runTest(String desc, String clsName) throws Throwable { 112 System.out.println("Running with the '" + desc + "' module..."); 113 runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName, 114 "ldap://localhost/dc=ie,dc=oracle,dc=com"); 115 } 116 117 private static void runJava(String... opts) throws Throwable { 118 ProcessTools.executeCommand( 119 Stream.of(JAVA_CMDS, List.of(opts)).flatMap(Collection::stream) 120 .toArray(String[]::new)).shouldHaveExitValue(0); 121 } 122 }