Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/loading/MLetContentTest.java
38838 views
/*1* Copyright (c) 2004, 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* @run clean MLetContentTest29* @run build MLetContentTest30* @run main MLetContentTest31*/3233import java.util.*;34import java.net.*;3536import javax.management.loading.*;3738public class MLetContentTest {39public static void main(String[] args) throws Exception {40System.out.println(">>> General test for the public class MLetContent.");4142Map<String,String> attributes = new HashMap();43attributes.put("archive", archive);44attributes.put("Archive", "hahaha");4546attributes.put("code", code);47attributes.put("codE", "hihi");4849attributes.put("object", object);50attributes.put("obJect", "toto");5152attributes.put("name", name);53attributes.put("NAME", "titi");5455attributes.put("version", version);56attributes.put("VeRsIoN", "tttt");5758List<String> types = new ArrayList();59types.add("my type");6061List<String> values = new ArrayList();62values.add("my values");6364URL url = new URL(baseUrl+myfile);65MLetContent content = new MLetContent(url, attributes, types, values);6667if (!attributes.equals(content.getAttributes())) {68throw new RuntimeException("The user specific attributes are changed.");69}7071if (!url.equals(content.getDocumentBase())) {72throw new RuntimeException("The user specific document bas is changed.");73}7475if (!archive.equals(content.getJarFiles())) {76throw new RuntimeException("The user specific archive files are changed.");77}7879if (!code.equals(content.getCode())) {80throw new RuntimeException("The user specific code is changed.");81}8283if (!object.equals(content.getSerializedObject())) {84throw new RuntimeException("The user specific object is changed.");85}8687if (!name.equals(content.getName())) {88throw new RuntimeException("The user specific name is changed.");89}9091if (!version.equals(content.getVersion())) {92throw new RuntimeException("The user specific version is changed.");93}9495if (!types.equals(content.getParameterTypes())) {96throw new RuntimeException("The user specific types are changed.");97}9899if (!values.equals(content.getParameterValues())) {100throw new RuntimeException("The user specific values are changed.");101}102103if (!baseUrl.equals(content.getCodeBase().toString())) {104throw new RuntimeException("The user specific base url are changed.");105}106107url = new URL(baseUrl);108attributes.put("codebase", codebase);109content = new MLetContent(url, attributes, types, values);110111if (!content.getCodeBase().toString().equals(baseUrl+codebase)) {112throw new RuntimeException("The user specific base url are changed.");113}114115final MyMLet myMlet = new MyMLet();116117if (myMlet.check(null, null, null, content) != content.getCodeBase()) {118throw new RuntimeException("Failed to overrid the protected methed check");119}120121System.out.println(">>> The test is well passed.");122}123124private static class MyMLet extends MLet {125public URL check(String version,126URL codebase,127String jarfile,128MLetContent content) {129return content.getCodeBase();130}131}132133private static final String archive = "my jarfile";134private static final String code = "my code";135private static final String object = "my object";136private static final String name = "my name";137private static final String version = "my version";138139private static final String myfile = "My file";140private static final String baseUrl = "file:/tmp/test/";141142private final static String codebase = "my code base/";143}144145146