0N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4796780
0N/A * @summary The class MLetContentTest becomes public
0N/A * @author Shanliang JIANG
0N/A * @run clean MLetContentTest
0N/A * @run build MLetContentTest
0N/A * @run main MLetContentTest
0N/A */
0N/A
0N/Aimport java.util.*;
0N/Aimport java.net.*;
0N/A
0N/Aimport javax.management.loading.*;
0N/A
0N/Apublic class MLetContentTest {
0N/A public static void main(String[] args) throws Exception {
0N/A System.out.println(">>> General test for the public class MLetContent.");
0N/A
0N/A Map<String,String> attributes = new HashMap();
0N/A attributes.put("archive", archive);
0N/A attributes.put("Archive", "hahaha");
0N/A
0N/A attributes.put("code", code);
0N/A attributes.put("codE", "hihi");
0N/A
0N/A attributes.put("object", object);
0N/A attributes.put("obJect", "toto");
0N/A
0N/A attributes.put("name", name);
0N/A attributes.put("NAME", "titi");
0N/A
0N/A attributes.put("version", version);
0N/A attributes.put("VeRsIoN", "tttt");
0N/A
0N/A List<String> types = new ArrayList();
0N/A types.add("my type");
0N/A
0N/A List<String> values = new ArrayList();
0N/A values.add("my values");
0N/A
0N/A URL url = new URL(baseUrl+myfile);
0N/A MLetContent content = new MLetContent(url, attributes, types, values);
0N/A
0N/A if (!attributes.equals(content.getAttributes())) {
0N/A throw new RuntimeException("The user specific attributes are changed.");
0N/A }
0N/A
0N/A if (!url.equals(content.getDocumentBase())) {
0N/A throw new RuntimeException("The user specific document bas is changed.");
0N/A }
0N/A
0N/A if (!archive.equals(content.getJarFiles())) {
0N/A throw new RuntimeException("The user specific archive files are changed.");
0N/A }
0N/A
0N/A if (!code.equals(content.getCode())) {
0N/A throw new RuntimeException("The user specific code is changed.");
0N/A }
0N/A
0N/A if (!object.equals(content.getSerializedObject())) {
0N/A throw new RuntimeException("The user specific object is changed.");
0N/A }
0N/A
0N/A if (!name.equals(content.getName())) {
0N/A throw new RuntimeException("The user specific name is changed.");
0N/A }
0N/A
0N/A if (!version.equals(content.getVersion())) {
0N/A throw new RuntimeException("The user specific version is changed.");
0N/A }
0N/A
0N/A if (!types.equals(content.getParameterTypes())) {
0N/A throw new RuntimeException("The user specific types are changed.");
0N/A }
0N/A
0N/A if (!values.equals(content.getParameterValues())) {
0N/A throw new RuntimeException("The user specific values are changed.");
0N/A }
0N/A
0N/A if (!baseUrl.equals(content.getCodeBase().toString())) {
0N/A throw new RuntimeException("The user specific base url are changed.");
0N/A }
0N/A
0N/A url = new URL(baseUrl);
0N/A attributes.put("codebase", codebase);
0N/A content = new MLetContent(url, attributes, types, values);
0N/A
0N/A if (!content.getCodeBase().toString().equals(baseUrl+codebase)) {
0N/A throw new RuntimeException("The user specific base url are changed.");
0N/A }
0N/A
0N/A final MyMLet myMlet = new MyMLet();
0N/A
0N/A if (myMlet.check(null, null, null, content) != content.getCodeBase()) {
0N/A throw new RuntimeException("Failed to overrid the protected methed check");
0N/A }
0N/A
0N/A System.out.println(">>> The test is well passed.");
0N/A }
0N/A
0N/A private static class MyMLet extends MLet {
0N/A public URL check(String version,
0N/A URL codebase,
0N/A String jarfile,
0N/A MLetContent content) {
0N/A return content.getCodeBase();
0N/A }
0N/A }
0N/A
0N/A private static final String archive = "my jarfile";
0N/A private static final String code = "my code";
0N/A private static final String object = "my object";
0N/A private static final String name = "my name";
0N/A private static final String version = "my version";
0N/A
0N/A private static final String myfile = "My file";
0N/A private static final String baseUrl = "file:/tmp/test/";
0N/A
0N/A private final static String codebase = "my code base/";
0N/A}