Path: blob/master/test/jdk/javax/naming/module/RunBasic.java
41149 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import jdk.test.lib.JDKToolFinder;24import jdk.test.lib.Utils;25import jdk.test.lib.compiler.CompilerUtils;26import jdk.test.lib.process.ProcessTools;2728import java.io.IOException;29import java.net.InetAddress;30import java.nio.file.Files;31import java.nio.file.Path;32import java.time.Duration;33import java.util.Collection;34import java.util.Collections;35import java.util.List;36import java.util.stream.Collectors;37import java.util.stream.Stream;3839import static jdk.test.lib.Utils.TEST_SRC;4041/*42* @test43* @summary Test of JNDI factories using classes exported by third-party modules.44* @library /test/lib45* @modules jdk.compiler46* @run main RunBasic47*/4849/*50* Demonstrates Java object storage/retrieval, LDAP control and URL context51* usage using an LDAP directory. The objects and their associated object52* factories, state factories, control factories and URL context factories53* are exported from third-party modules.54*55* Seven types of object are used:56* - an AWT object (Serializable) from the 'java.desktop' JDK module57* - a Person object (DirContext) from the 'person' third-party module58* - a Fruit object (Referenceable) from the 'fruit' third-party module59* - an RMI object (Remote) from the 'hello' third-party module60* - an LDAP request control (Control) from the 'foo' third-party module61* - an LDAP response control (Control) from the 'authz' third-party module62* - an ldapv4 URL (DirContext) from the 'ldapv4' third-party module63*/6465public class RunBasic {6667private static final List<String> JAVA_CMDS;6869static final String HOST_NAME = InetAddress.getLoopbackAddress().getHostName();7071static {72String javaPath = JDKToolFinder.getJDKTool("java");7374JAVA_CMDS = Stream75.concat(Stream.of(javaPath), Stream.of(Utils.getTestJavaOpts()))76.collect(Collectors.collectingAndThen(Collectors.toList(),77Collections::unmodifiableList));78}7980public static void main(String[] args) throws Throwable {81// prepare all test modules82prepareModule("person");83prepareModule("fruit");84prepareModule("hello");85prepareModule("foo");86prepareModule("authz");87prepareModule("ldapv4");88prepareModule("test", "--module-source-path",89Path.of(TEST_SRC, "src").toString());9091System.out.println("Hostname: [" + HOST_NAME + "]");9293// run tests94runTest("java.desktop", "test.StoreObject");95runTest("person", "test.StorePerson");96runTest("fruit", "test.StoreFruit");97runTest("hello", "test.StoreRemote");98runTest("foo", "test.ConnectWithFoo");99runTest("authz", "test.ConnectWithAuthzId");100runTest("ldapv4", "test.ReadByUrl");101}102103private static void prepareModule(String mod, String... opts)104throws IOException {105System.out.println("Preparing the '" + mod + "' module...");106long start = System.nanoTime();107makeDir("mods", mod);108CompilerUtils.compile(Path.of(TEST_SRC, "src", mod),109Path.of("mods", (mod.equals("test") ? "" : mod)), opts);110Duration duration = Duration.ofNanos(System.nanoTime() - start);111System.out.println("completed: duration - " + duration );112}113114private static void makeDir(String first, String... more)115throws IOException {116Files.createDirectories(Path.of(first, more));117}118119private static void runTest(String desc, String clsName) throws Throwable {120System.out.println("Running with the '" + desc + "' module...");121runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName,122"ldap://" + HOST_NAME + "/dc=ie,dc=oracle,dc=com");123}124125private static void runJava(String... opts) throws Throwable {126ProcessTools.executeCommand(127Stream.of(JAVA_CMDS, List.of(opts)).flatMap(Collection::stream)128.toArray(String[]::new)).shouldHaveExitValue(0);129}130}131132133