Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/loading/DocumentRootTest.java
38838 views
/*1* Copyright (c) 2006, 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 650013926* @summary Test parsing error when the mlet file is27* located in the web server's document root.28* @author Luis-Miguel Alventosa29* @run clean DocumentRootTest30* @run build DocumentRootTest31* @run main DocumentRootTest32*/3334import java.net.URL;35import java.util.ArrayList;36import java.util.HashMap;37import javax.management.loading.MLetContent;3839public class DocumentRootTest {40public static int test(URL documentBase, URL codeBase) {41int error = 0;42MLetContent mc = new MLetContent(43documentBase,44new HashMap<String,String>(),45new ArrayList<String>(),46new ArrayList<String>());47System.out.println("\nACTUAL DOCUMENT BASE = " + mc.getDocumentBase());48System.out.println("EXPECTED DOCUMENT BASE = " + documentBase);49if (!documentBase.equals(mc.getDocumentBase())) {50System.out.println("ERROR: Wrong document base");51error++;52};53System.out.println("ACTUAL CODEBASE = " + mc.getCodeBase());54System.out.println("EXPECTED CODEBASE = " + codeBase);55if (!codeBase.equals(mc.getCodeBase())) {56System.out.println("ERROR: Wrong code base");57error++;58};59return error;60}61public static void main(String[] args) throws Exception {62int error = 0;63error += test(new URL("file:/mlet.txt"), new URL("file:/"));64error += test(new URL("http://localhost/mlet.txt"), new URL("http://localhost/"));65if (error > 0) {66System.out.println("\nTest FAILED!\n");67throw new IllegalArgumentException("Test FAILED!");68} else {69System.out.println("\nTest PASSED!\n");70}71}72}737475