Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/ws/ebcdic/WsImportTest.java
38853 views
/*1* Copyright (c) 2014, 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 803830726* @summary JAX-WS conformance tests fail when running JCK-devtools-8 suite against RI in EBCDIC emulation mode27* @run main/othervm WsImportTest28*/2930import java.io.InputStreamReader;31import java.io.IOException;32import java.io.BufferedReader;33import java.io.File;34import java.nio.file.Files;35import java.nio.file.FileVisitResult;36import java.nio.file.Path;37import java.nio.file.Paths;38import java.nio.file.SimpleFileVisitor;39import java.nio.file.attribute.BasicFileAttributes;40import static java.nio.file.FileVisitResult.*;4142public class WsImportTest {4344public static void main(String[] args) throws IOException {4546String wsimport = getWsImport();47String wsdl = getWSDLFilePath("test-service.wsdl");4849try {50log("Importing wsdl: " + wsdl);51String[] wsargs = {52wsimport,53"-p",54"generated",55"-J-Dfile.encoding=Cp037",56wsdl57};5859ProcessBuilder pb = new ProcessBuilder(wsargs);60pb.redirectErrorStream(true);61Process p = pb.start();62logOutput(p);63int result = p.waitFor();64p.destroy();6566if (result != 0) {67fail("WsImport failed. TEST FAILED.");68} else {69log("Test PASSED.");70}7172} catch (Exception e) {73e.printStackTrace();74fail(e.getMessage());75} finally {76deleteGeneratedFiles();77}78}7980private static void fail(String message) {81throw new RuntimeException(message);82}8384private static void log(String msg) {85System.out.println(msg);86}8788private static void logOutput(Process p) throws IOException {89BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));90String s = r.readLine();91while (s != null) {92log(s.trim());93s = r.readLine();94}95}9697private static void deleteGeneratedFiles() {98Path p = Paths.get("generated");99if (Files.exists(p)) {100try {101Files.walkFileTree(p, new SimpleFileVisitor<Path>() {102@Override103public FileVisitResult visitFile(Path file,104BasicFileAttributes attrs) throws IOException {105106Files.delete(file);107return CONTINUE;108}109@Override110public FileVisitResult postVisitDirectory(Path dir,111IOException exc) throws IOException {112113if (exc == null) {114Files.delete(dir);115return CONTINUE;116} else {117throw exc;118}119}120});121} catch (IOException ioe) {122ioe.printStackTrace();123}124}125}126127private static String getWSDLFilePath(String filename) {128String testSrc = System.getProperty("test.src");129if (testSrc == null) testSrc = ".";130return Paths.get(testSrc).resolve(filename).toString();131}132133private static String getWsImport() {134String javaHome = System.getProperty("java.home");135if (javaHome.endsWith("jre")) {136javaHome = new File(javaHome).getParent();137}138String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";139if (System.getProperty("os.name").startsWith("Windows")) {140wsimport = wsimport.concat(".exe");141}142return wsimport;143}144}145146147