Path: blob/master/test/langtools/tools/jdeps/jdkinternals/ShowReplacement.java
41152 views
/*1* Copyright (c) 2016, 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*/2223/*24* @test25* @bug 815952426* @summary Tests JDK internal APIs with and without replacements27* @library ../lib28* @modules jdk.jdeps/com.sun.tools.jdeps29* @build CompilerUtils JdepsUtil30* @run testng ShowReplacement31*/3233import java.nio.file.Path;34import java.nio.file.Paths;35import java.util.Map;3637import org.testng.annotations.BeforeTest;38import org.testng.annotations.Test;3940import static org.testng.Assert.assertEquals;41import static org.testng.Assert.assertTrue;4243public class ShowReplacement {44private static final String TEST_SRC = System.getProperty("test.src");4546private static final Path CLASSES_DIR = Paths.get("classes");4748private static final Map<String, String> REPLACEMENTS = Map.of(49"sun.security.util.HostnameChecker",50"Use javax.net.ssl.SSLParameters.setEndpointIdentificationAlgorithm(\"HTTPS\") @since 1.7",51"",52"or javax.net.ssl.HttpsURLConnection.setHostnameVerifier() @since 1.4");5354/**55* Compiles classes used by the test56*/57@BeforeTest58public void compileAll() throws Exception {59CompilerUtils.cleanDir(CLASSES_DIR);6061Path tmp = Paths.get("tmp");62assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "apple"), tmp));63assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "q"),64CLASSES_DIR,65"-cp", tmp.toString(),66"--add-exports=java.base/sun.security.util=ALL-UNNAMED"));67}6869@Test70public void withReplacement() {71Path file = Paths.get("q", "WithRepl.class");72JdepsRunner jdeps = JdepsRunner.run("-jdkinternals", CLASSES_DIR.resolve(file).toString());73String[] output = jdeps.output();74int i = 0;75while (!output[i].contains("Suggested Replacement")) {76i++;77}7879// must match the number of JDK internal APIs80int count = output.length-i-2;81assertEquals(count, REPLACEMENTS.size());8283for (int j=i+2; j < output.length; j++) {84String line = output[j];85int pos = line.indexOf("Use ");86if (pos < 0)87pos = line.indexOf("or");8889assertTrue(pos > 0);90String name = line.substring(0, pos).trim();91String repl = line.substring(pos, line.length()).trim();92assertEquals(REPLACEMENTS.get(name), repl);93}94}9596/*97* A JDK internal class has been removed while its package still exists.98*/99@Test100public void noReplacement() {101Path file = Paths.get("q", "NoRepl.class");102JdepsRunner jdeps = JdepsRunner.run("-jdkinternals", CLASSES_DIR.resolve(file).toString());103String[] output = jdeps.output();104int i = 0;105// expect no replacement106while (i < output.length && !output[i].contains("Suggested Replacement")) {107i++;108}109110// no replacement111assertEquals(output.length-i, 0);112}113114/*115* A JDK internal package has been removed.116*/117@Test118public void removedPackage() {119Path file = Paths.get("q", "RemovedPackage.class");120JdepsRunner jdeps = JdepsRunner.run("--jdk-internals", CLASSES_DIR.resolve(file).toString());121String[] output = jdeps.output();122int i = 0;123// expect no replacement124while (i < output.length && !output[i].contains("Suggested Replacement")) {125i++;126}127128// no replacement129assertEquals(output.length-i, 0);130}131}132133134