< prev index next >

test/jdk/javax/naming/module/RunBasic.java

Print this page

  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  */

 50 /*
 51  * Demonstrates Java object storage/retrieval, LDAP control and URL context
 52  * usage using an LDAP directory. The objects and their associated object
 53  * factories, state factories, control factories and URL context factories
 54  * are exported from third-party modules.
 55  *
 56  * Seven types of object are used:
 57  *   - an AWT object (Serializable) from the 'java.desktop' JDK module
 58  *   - a Person object (DirContext) from the 'person' third-party module
 59  *   - a Fruit object (Referenceable) from the 'fruit' third-party module
 60  *   - an RMI object (Remote) from the 'hello' third-party module
 61  *   - an LDAP request control (Control) from the 'foo' third-party module
 62  *   - an LDAP response control (Control) from the 'authz' third-party module
 63  *   - an ldapv4 URL (DirContext) from the 'ldapv4' third-party module
 64  */
 65 
 66 public class RunBasic {
 67 
 68     private static final List<String> JAVA_CMDS;
 69 








 70     static final String HOST_NAME = InetAddress.getLoopbackAddress().getHostName();


 71 
 72     static {
 73         String javaPath = JDKToolFinder.getJDKTool("java");
 74 
 75         JAVA_CMDS = Stream
 76                 .concat(Stream.of(javaPath), Stream.of(Utils.getTestJavaOpts()))
 77                 .collect(Collectors.collectingAndThen(Collectors.toList(),
 78                         Collections::unmodifiableList));
 79     }
 80 
 81     public static void main(String[] args) throws Throwable {
 82         // prepare all test modules
 83         prepareModule("person");
 84         prepareModule("fruit");
 85         prepareModule("hello");
 86         prepareModule("foo");
 87         prepareModule("authz");
 88         prepareModule("ldapv4");
 89         prepareModule("test", "--module-source-path",
 90                 Path.of(TEST_SRC, "src").toString());

102     }
103 
104     private static void prepareModule(String mod, String... opts)
105             throws IOException {
106         System.out.println("Preparing the '" + mod + "' module...");
107         long start = System.nanoTime();
108         makeDir("mods", mod);
109         CompilerUtils.compile(Path.of(TEST_SRC, "src", mod),
110                 Path.of("mods", (mod.equals("test") ? "" : mod)), opts);
111         Duration duration = Duration.ofNanos(System.nanoTime() - start);
112         System.out.println("completed: duration - " + duration );
113     }
114 
115     private static void makeDir(String first, String... more)
116             throws IOException {
117         Files.createDirectories(Path.of(first, more));
118     }
119 
120     private static void runTest(String desc, String clsName) throws Throwable {
121         System.out.println("Running with the '" + desc + "' module...");






122         runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName,
123                 "ldap://" + HOST_NAME + "/dc=ie,dc=oracle,dc=com");
124     }
125 
126     private static void runJava(String... opts) throws Throwable {
127         ProcessTools.executeCommand(
128                 Stream.of(JAVA_CMDS, List.of(opts)).flatMap(Collection::stream)
129                         .toArray(String[]::new)).shouldHaveExitValue(0);
130     }
131 }

  1 /*
  2  * Copyright (c) 2015, 2020, 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  */

 50 /*
 51  * Demonstrates Java object storage/retrieval, LDAP control and URL context
 52  * usage using an LDAP directory. The objects and their associated object
 53  * factories, state factories, control factories and URL context factories
 54  * are exported from third-party modules.
 55  *
 56  * Seven types of object are used:
 57  *   - an AWT object (Serializable) from the 'java.desktop' JDK module
 58  *   - a Person object (DirContext) from the 'person' third-party module
 59  *   - a Fruit object (Referenceable) from the 'fruit' third-party module
 60  *   - an RMI object (Remote) from the 'hello' third-party module
 61  *   - an LDAP request control (Control) from the 'foo' third-party module
 62  *   - an LDAP response control (Control) from the 'authz' third-party module
 63  *   - an ldapv4 URL (DirContext) from the 'ldapv4' third-party module
 64  */
 65 
 66 public class RunBasic {
 67 
 68     private static final List<String> JAVA_CMDS;
 69 
 70     // To update .ldap files under src/test/test, LDAP request and response
 71     // bytes can be logged while interacting with a real LDAP server
 72     // (e.g.: HOST_NAME = "localhost:8389").
 73     // For that point HOST_NAME to a real server in which the ROOT_DOMAIN
 74     // below is configured to allow modifications by anonymous users, and
 75     // pass an additional "-trace" argument to the created subprocesses.
 76     // The LDAP requests and response bytes will appear in the log, and you
 77     // can then update the corresponding .ldap files.
 78     static final String HOST_NAME = InetAddress.getLoopbackAddress().getHostName();
 79     static final String ROOT_DOMAIN = "dc=ie,dc=oracle,dc=com";
 80     static final String PATH = "/" + ROOT_DOMAIN;
 81 
 82     static {
 83         String javaPath = JDKToolFinder.getJDKTool("java");
 84 
 85         JAVA_CMDS = Stream
 86                 .concat(Stream.of(javaPath), Stream.of(Utils.getTestJavaOpts()))
 87                 .collect(Collectors.collectingAndThen(Collectors.toList(),
 88                         Collections::unmodifiableList));
 89     }
 90 
 91     public static void main(String[] args) throws Throwable {
 92         // prepare all test modules
 93         prepareModule("person");
 94         prepareModule("fruit");
 95         prepareModule("hello");
 96         prepareModule("foo");
 97         prepareModule("authz");
 98         prepareModule("ldapv4");
 99         prepareModule("test", "--module-source-path",
100                 Path.of(TEST_SRC, "src").toString());

112     }
113 
114     private static void prepareModule(String mod, String... opts)
115             throws IOException {
116         System.out.println("Preparing the '" + mod + "' module...");
117         long start = System.nanoTime();
118         makeDir("mods", mod);
119         CompilerUtils.compile(Path.of(TEST_SRC, "src", mod),
120                 Path.of("mods", (mod.equals("test") ? "" : mod)), opts);
121         Duration duration = Duration.ofNanos(System.nanoTime() - start);
122         System.out.println("completed: duration - " + duration );
123     }
124 
125     private static void makeDir(String first, String... more)
126             throws IOException {
127         Files.createDirectories(Path.of(first, more));
128     }
129 
130     private static void runTest(String desc, String clsName) throws Throwable {
131         System.out.println("Running with the '" + desc + "' module...");
132         // To record LDAP requests and responses in order to update the
133         // .ldap files under src/test/test, make sure that HOST_NAME
134         // points to an LDAP server accepting anonymous modifications without
135         // credentials, and that has "dc=ie,dc=oracle,dc=com" configured
136         // as root domain. Also add "-trace" as last argument to the runJava
137         // command below.
138         runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName,
139                 "ldap://" + HOST_NAME + PATH);
140     }
141 
142     private static void runJava(String... opts) throws Throwable {
143         ProcessTools.executeCommand(
144                 Stream.of(JAVA_CMDS, List.of(opts)).flatMap(Collection::stream)
145                         .toArray(String[]::new)).shouldHaveExitValue(0);
146     }
147 }
< prev index next >