Path: blob/master/test/jdk/javax/management/loading/MLetContentTest.java
41152 views
/*1* Copyright (c) 2004, 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 479678026* @summary The class MLetContentTest becomes public27* @author Shanliang JIANG28*29* @run clean MLetContentTest30* @run build MLetContentTest31* @run main MLetContentTest32*/3334import java.util.*;35import java.net.*;3637import javax.management.loading.*;3839public class MLetContentTest {40public static void main(String[] args) throws Exception {41System.out.println(">>> General test for the public class MLetContent.");4243Map<String,String> attributes = new HashMap();44attributes.put("archive", archive);45attributes.put("Archive", "hahaha");4647attributes.put("code", code);48attributes.put("codE", "hihi");4950attributes.put("object", object);51attributes.put("obJect", "toto");5253attributes.put("name", name);54attributes.put("NAME", "titi");5556attributes.put("version", version);57attributes.put("VeRsIoN", "tttt");5859List<String> types = new ArrayList();60types.add("my type");6162List<String> values = new ArrayList();63values.add("my values");6465URL url = new URL(baseUrl+myfile);66MLetContent content = new MLetContent(url, attributes, types, values);6768if (!attributes.equals(content.getAttributes())) {69throw new RuntimeException("The user specific attributes are changed.");70}7172if (!url.equals(content.getDocumentBase())) {73throw new RuntimeException("The user specific document bas is changed.");74}7576if (!archive.equals(content.getJarFiles())) {77throw new RuntimeException("The user specific archive files are changed.");78}7980if (!code.equals(content.getCode())) {81throw new RuntimeException("The user specific code is changed.");82}8384if (!object.equals(content.getSerializedObject())) {85throw new RuntimeException("The user specific object is changed.");86}8788if (!name.equals(content.getName())) {89throw new RuntimeException("The user specific name is changed.");90}9192if (!version.equals(content.getVersion())) {93throw new RuntimeException("The user specific version is changed.");94}9596if (!types.equals(content.getParameterTypes())) {97throw new RuntimeException("The user specific types are changed.");98}99100if (!values.equals(content.getParameterValues())) {101throw new RuntimeException("The user specific values are changed.");102}103104if (!baseUrl.equals(content.getCodeBase().toString())) {105throw new RuntimeException("The user specific base url are changed.");106}107108url = new URL(baseUrl);109attributes.put("codebase", codebase);110content = new MLetContent(url, attributes, types, values);111112if (!content.getCodeBase().toString().equals(baseUrl+codebase)) {113throw new RuntimeException("The user specific base url are changed.");114}115116final MyMLet myMlet = new MyMLet();117118if (myMlet.check(null, null, null, content) != content.getCodeBase()) {119throw new RuntimeException("Failed to overrid the protected methed check");120}121122System.out.println(">>> The test is well passed.");123}124125private static class MyMLet extends MLet {126public URL check(String version,127URL codebase,128String jarfile,129MLetContent content) {130return content.getCodeBase();131}132}133134private static final String archive = "my jarfile";135private static final String code = "my code";136private static final String object = "my object";137private static final String name = "my name";138private static final String version = "my version";139140private static final String myfile = "My file";141private static final String baseUrl = "file:/tmp/test/";142143private final static String codebase = "my code base/";144}145146147