Skip to content

Commit 2584bf8

Browse files
author
Justin Lu
committed
8210410: Refactor java.util.Currency:i18n shell tests to plain java tests
Reviewed-by: naoto, lancea
1 parent 454b116 commit 2584bf8

File tree

2 files changed

+157
-144
lines changed

2 files changed

+157
-144
lines changed

test/jdk/java/util/Currency/PropertiesTest.sh

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright (c) 2007, 2023, 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+
/*
25+
* @test
26+
* @bug 6332666 6863624 7180362 8003846 8074350 8074351 8130246 8149735 7102969
27+
* 8157138 8190904 8210410
28+
* @summary Tests the capability of replacing the currency data with a user
29+
* specified currency properties file in lib directory (old way) or
30+
* via the system property in the cmdline (new way).
31+
* @library /test/lib
32+
* @build PropertiesTest
33+
* @run junit PropertiesTestRun
34+
*/
35+
36+
import jdk.test.lib.Utils;
37+
import jdk.test.lib.process.ProcessTools;
38+
39+
import org.junit.jupiter.api.AfterAll;
40+
import org.junit.jupiter.api.BeforeAll;
41+
import org.junit.jupiter.api.Test;
42+
import org.junit.jupiter.params.ParameterizedTest;
43+
import org.junit.jupiter.params.provider.MethodSource;
44+
45+
import java.util.Arrays;
46+
import java.util.stream.Stream;
47+
48+
import static org.junit.jupiter.api.Assertions.fail;
49+
50+
public class PropertiesTestRun {
51+
52+
// String paths used for the cmdline processes
53+
private static final String TEST_JDK = Utils.TEST_JDK;
54+
private static final String TEST_PROPS =
55+
Utils.TEST_SRC+Utils.FILE_SEPARATOR+"currency.properties";
56+
private static final String WRITABLE_JDK =
57+
"."+Utils.FILE_SEPARATOR+"WRITABLE_JDK";
58+
private static final String WRITABLE_JDK_LIB =
59+
WRITABLE_JDK+Utils.FILE_SEPARATOR+"lib";
60+
private static final String WRITABLE_JDK_BIN =
61+
WRITABLE_JDK+Utils.FILE_SEPARATOR+"bin";
62+
private static final String WRITABLE_JDK_JAVA_PATH =
63+
WRITABLE_JDK_BIN + Utils.FILE_SEPARATOR + "java";
64+
65+
// Create a writable JDK and set up dumps 1-3
66+
@BeforeAll
67+
static void setUp() throws Throwable {
68+
// Create separate JDK to supersede currencies via lib directory
69+
createWritableJDK();
70+
// Create dump without user defined prop file
71+
executeTestJDKMethod("PropertiesTest", "-d", "dump1");
72+
// Create dump with user defined prop file (via system property)
73+
executeTestJDKMethod("-Djava.util.currency.data="+TEST_PROPS,
74+
"PropertiesTest", "-d", "dump2");
75+
// Create dump with user defined prop file (via lib)
76+
executeWritableJDKMethod("PropertiesTest", "-d", "dump3");
77+
}
78+
79+
// Need to create a separate JDK to insert the user defined properties file
80+
// into the lib folder. Create separate JDK to not disturb current TEST JDK.
81+
private static void createWritableJDK() throws Throwable {
82+
// Copy Test JDK into a separate JDK folder
83+
executeProcess(new String[]{"cp", "-H", "-R", TEST_JDK, WRITABLE_JDK});
84+
// Make the separate JDK writable
85+
executeProcess(new String[]{"chmod", "-R", "u+w", WRITABLE_JDK_LIB});
86+
// Copy the properties file into the writable JDK lib folder
87+
executeProcess(new String[]{"cp", TEST_PROPS, WRITABLE_JDK_LIB});
88+
}
89+
90+
// Compares the dumped output is expected between the default currencies
91+
// and the user-defined custom currencies
92+
@Test
93+
void compareDumps() throws Throwable {
94+
// Compare dump (from sys prop)
95+
executeTestJDKMethod("PropertiesTest", "-c", "dump1", "dump2",
96+
TEST_PROPS);
97+
// Compare dump (from lib)
98+
executeTestJDKMethod("PropertiesTest", "-c", "dump1", "dump3",
99+
TEST_PROPS);
100+
}
101+
102+
// Launch a test from PropertiesTest. See PropertiesTest.java for more
103+
// detail regarding a specific test that was launched.
104+
@ParameterizedTest
105+
@MethodSource("PropertiesTestMethods")
106+
void launchPropertiesTests(String methodName) throws Throwable {
107+
// Test via both the lib and system property
108+
executeWritableJDKMethod("PropertiesTest", methodName);
109+
executeTestJDKMethod("-Djava.util.currency.data="+TEST_PROPS,
110+
"PropertiesTest", methodName);
111+
}
112+
113+
private static Stream<String> PropertiesTestMethods() {
114+
return Stream.of("bug7102969", "bug8157138", "bug8190904");
115+
}
116+
117+
// Launch a PropertiesTest method using the TEST JDK
118+
private static void executeTestJDKMethod(String... params) throws Throwable {
119+
int exitStatus = ProcessTools.executeTestJvm(params).getExitValue();
120+
if (exitStatus != 0) {
121+
fail("Process started with: " + Arrays.toString(params) + " failed");
122+
}
123+
}
124+
125+
// Launch a PropertiesTest method using the WRITABLE JDK
126+
private static void executeWritableJDKMethod(String... params) throws Throwable {
127+
// Need to include WritableJDK javapath, TEST JDK classpath
128+
String[] allParams = new String[3+params.length+Utils.getTestJavaOpts().length];
129+
// We don't use executeTestJvm() because we want to point to separate JDK java path
130+
allParams[0] = WRITABLE_JDK_JAVA_PATH;
131+
allParams[1] = "-cp";
132+
allParams[2] = System.getProperty("java.class.path");
133+
// Add test.vm.opts and test.java.opts
134+
System.arraycopy(Utils.getTestJavaOpts(), 0, allParams, 3,
135+
Utils.getTestJavaOpts().length);
136+
// Add the rest of the actual arguments
137+
System.arraycopy(params, 0, allParams, Utils.getTestJavaOpts().length+3,
138+
params.length);
139+
// Launch the actual test method with all parameters set
140+
executeProcess(allParams);
141+
}
142+
143+
// Execute a process and fail if the command is not successful
144+
private static void executeProcess(String[] params) throws Throwable {
145+
System.out.println("Command line: " + Arrays.toString(params));
146+
int exitStatus = ProcessTools.executeProcess(params).getExitValue();
147+
if (exitStatus != 0) {
148+
fail("Process started with: " + Arrays.toString(params) + " failed");
149+
}
150+
}
151+
152+
@AfterAll
153+
static void tearDown() throws Throwable {
154+
// Remove the copied writable JDK image from scratch folder
155+
executeProcess(new String[]{"rm", "-rf", WRITABLE_JDK});
156+
}
157+
}

0 commit comments

Comments
 (0)