author | chegar |
Tue, 09 Oct 2018 11:44:00 +0100 | |
changeset 52052 | e25291a90cba |
parent 51693 | 59de57e466ba |
permissions | -rw-r--r-- |
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
1 |
/* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
4 |
* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
8 |
* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
13 |
* accompanied this code). |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
14 |
* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
18 |
* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
21 |
* questions. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
22 |
*/ |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
23 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
24 |
import jdk.test.lib.JDKToolFinder; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
25 |
import jdk.test.lib.Utils; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
26 |
import jdk.test.lib.compiler.CompilerUtils; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
27 |
import jdk.test.lib.process.ProcessTools; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
28 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
29 |
import java.io.IOException; |
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
30 |
import java.net.InetAddress; |
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
31 |
import java.nio.file.Files; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
33 |
import java.time.Duration; |
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
34 |
import java.util.Collection; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
35 |
import java.util.Collections; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
36 |
import java.util.List; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
37 |
import java.util.stream.Collectors; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
38 |
import java.util.stream.Stream; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
39 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
40 |
import static jdk.test.lib.Utils.TEST_SRC; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
41 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
42 |
/* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
43 |
* @test |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
44 |
* @summary Test of JNDI factories using classes exported by third-party modules. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
45 |
* @library /test/lib |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
46 |
* @modules jdk.compiler |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
47 |
* @run main RunBasic |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
48 |
*/ |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
49 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
50 |
/* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
51 |
* Demonstrates Java object storage/retrieval, LDAP control and URL context |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
52 |
* usage using an LDAP directory. The objects and their associated object |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
53 |
* factories, state factories, control factories and URL context factories |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
54 |
* are exported from third-party modules. |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
55 |
* |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
56 |
* Seven types of object are used: |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
57 |
* - an AWT object (Serializable) from the 'java.desktop' JDK module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
58 |
* - a Person object (DirContext) from the 'person' third-party module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
59 |
* - a Fruit object (Referenceable) from the 'fruit' third-party module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
60 |
* - an RMI object (Remote) from the 'hello' third-party module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
61 |
* - an LDAP request control (Control) from the 'foo' third-party module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
62 |
* - an LDAP response control (Control) from the 'authz' third-party module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
63 |
* - an ldapv4 URL (DirContext) from the 'ldapv4' third-party module |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
64 |
*/ |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
65 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
66 |
public class RunBasic { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
67 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
68 |
private static final List<String> JAVA_CMDS; |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
69 |
|
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
70 |
static final String HOST_NAME = InetAddress.getLoopbackAddress().getHostName(); |
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
71 |
|
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
72 |
static { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
73 |
String javaPath = JDKToolFinder.getJDKTool("java"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
74 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
75 |
JAVA_CMDS = Stream |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
76 |
.concat(Stream.of(javaPath), Stream.of(Utils.getTestJavaOpts())) |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
77 |
.collect(Collectors.collectingAndThen(Collectors.toList(), |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
78 |
Collections::unmodifiableList)); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
79 |
} |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
80 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
81 |
public static void main(String[] args) throws Throwable { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
82 |
// prepare all test modules |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
83 |
prepareModule("person"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
84 |
prepareModule("fruit"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
85 |
prepareModule("hello"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
86 |
prepareModule("foo"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
87 |
prepareModule("authz"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
88 |
prepareModule("ldapv4"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
89 |
prepareModule("test", "--module-source-path", |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
90 |
Path.of(TEST_SRC, "src").toString()); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
91 |
|
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
92 |
System.out.println("Hostname: [" + HOST_NAME + "]"); |
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
93 |
|
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
94 |
// run tests |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
95 |
runTest("java.desktop", "test.StoreObject"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
96 |
runTest("person", "test.StorePerson"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
97 |
runTest("fruit", "test.StoreFruit"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
98 |
runTest("hello", "test.StoreRemote"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
99 |
runTest("foo", "test.ConnectWithFoo"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
100 |
runTest("authz", "test.ConnectWithAuthzId"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
101 |
runTest("ldapv4", "test.ReadByUrl"); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
102 |
} |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
103 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
104 |
private static void prepareModule(String mod, String... opts) |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
105 |
throws IOException { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
106 |
System.out.println("Preparing the '" + mod + "' module..."); |
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
107 |
long start = System.nanoTime(); |
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
108 |
makeDir("mods", mod); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
109 |
CompilerUtils.compile(Path.of(TEST_SRC, "src", mod), |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
110 |
Path.of("mods", (mod.equals("test") ? "" : mod)), opts); |
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
111 |
Duration duration = Duration.ofNanos(System.nanoTime() - start); |
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
112 |
System.out.println("completed: duration - " + duration ); |
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
113 |
} |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
114 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
115 |
private static void makeDir(String first, String... more) |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
116 |
throws IOException { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
117 |
Files.createDirectories(Path.of(first, more)); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
118 |
} |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
119 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
120 |
private static void runTest(String desc, String clsName) throws Throwable { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
121 |
System.out.println("Running with the '" + desc + "' module..."); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
122 |
runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName, |
52052
e25291a90cba
8211920: Close server socket and cleanups in test/jdk/javax/naming/module/RunBasic.java
chegar
parents:
51693
diff
changeset
|
123 |
"ldap://" + HOST_NAME + "/dc=ie,dc=oracle,dc=com"); |
51693
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
124 |
} |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
125 |
|
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
126 |
private static void runJava(String... opts) throws Throwable { |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
127 |
ProcessTools.executeCommand( |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
128 |
Stream.of(JAVA_CMDS, List.of(opts)).flatMap(Collection::stream) |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
129 |
.toArray(String[]::new)).shouldHaveExitValue(0); |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
130 |
} |
59de57e466ba
8209773: Refactor shell test javax/naming/module/basic.sh to java
xyin
parents:
diff
changeset
|
131 |
} |