Path: blob/master/test/jdk/javax/management/loading/DocumentRootTest.java
41149 views
/*1* Copyright (c) 2006, 2015, 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*30* @run clean DocumentRootTest31* @run build DocumentRootTest32* @run main DocumentRootTest33*/3435import java.net.URL;36import java.util.ArrayList;37import java.util.HashMap;38import javax.management.loading.MLetContent;3940public class DocumentRootTest {41public static int test(URL documentBase, URL codeBase) {42int error = 0;43MLetContent mc = new MLetContent(44documentBase,45new HashMap<String,String>(),46new ArrayList<String>(),47new ArrayList<String>());48System.out.println("\nACTUAL DOCUMENT BASE = " + mc.getDocumentBase());49System.out.println("EXPECTED DOCUMENT BASE = " + documentBase);50if (!documentBase.equals(mc.getDocumentBase())) {51System.out.println("ERROR: Wrong document base");52error++;53};54System.out.println("ACTUAL CODEBASE = " + mc.getCodeBase());55System.out.println("EXPECTED CODEBASE = " + codeBase);56if (!codeBase.equals(mc.getCodeBase())) {57System.out.println("ERROR: Wrong code base");58error++;59};60return error;61}62public static void main(String[] args) throws Exception {63int error = 0;64error += test(new URL("file:/mlet.txt"), new URL("file:/"));65error += test(new URL("http://localhost/mlet.txt"), new URL("http://localhost/"));66if (error > 0) {67System.out.println("\nTest FAILED!\n");68throw new IllegalArgumentException("Test FAILED!");69} else {70System.out.println("\nTest PASSED!\n");71}72}73}747576