1 /* 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4796780 27 * @summary The class MLetContentTest becomes public 28 * @author Shanliang JIANG 29 * @run clean MLetContentTest 30 * @run build MLetContentTest 31 * @run main MLetContentTest 32 */ 33 34 import java.util.*; 35 import java.net.*; 36 37 import javax.management.loading.*; 38 39 public class MLetContentTest { 40 public static void main(String[] args) throws Exception { 41 System.out.println(">>> General test for the public class MLetContent."); 42 43 Map<String,String> attributes = new HashMap(); 44 attributes.put("archive", archive); 45 attributes.put("Archive", "hahaha"); 46 47 attributes.put("code", code); 48 attributes.put("codE", "hihi"); 49 50 attributes.put("object", object); 51 attributes.put("obJect", "toto"); 52 53 attributes.put("name", name); 54 attributes.put("NAME", "titi"); 55 56 attributes.put("version", version); 57 attributes.put("VeRsIoN", "tttt"); 58 59 List<String> types = new ArrayList(); 60 types.add("my type"); 61 62 List<String> values = new ArrayList(); 63 values.add("my values"); 64 65 URL url = new URL(baseUrl+myfile); 66 MLetContent content = new MLetContent(url, attributes, types, values); 67 68 if (!attributes.equals(content.getAttributes())) { 69 throw new RuntimeException("The user specific attributes are changed."); 70 } 71 72 if (!url.equals(content.getDocumentBase())) { 73 throw new RuntimeException("The user specific document bas is changed."); 74 } 75 76 if (!archive.equals(content.getJarFiles())) { 77 throw new RuntimeException("The user specific archive files are changed."); 78 } 79 80 if (!code.equals(content.getCode())) { 81 throw new RuntimeException("The user specific code is changed."); 82 } 83 84 if (!object.equals(content.getSerializedObject())) { 85 throw new RuntimeException("The user specific object is changed."); 86 } 87 88 if (!name.equals(content.getName())) { 89 throw new RuntimeException("The user specific name is changed."); 90 } 91 92 if (!version.equals(content.getVersion())) { 93 throw new RuntimeException("The user specific version is changed."); 94 } 95 96 if (!types.equals(content.getParameterTypes())) { 97 throw new RuntimeException("The user specific types are changed."); 98 } 99 100 if (!values.equals(content.getParameterValues())) { 101 throw new RuntimeException("The user specific values are changed."); 102 } 103 104 if (!baseUrl.equals(content.getCodeBase().toString())) { 105 throw new RuntimeException("The user specific base url are changed."); 106 } 107 108 url = new URL(baseUrl); 109 attributes.put("codebase", codebase); 110 content = new MLetContent(url, attributes, types, values); 111 112 if (!content.getCodeBase().toString().equals(baseUrl+codebase)) { 113 throw new RuntimeException("The user specific base url are changed."); 114 } 115 116 final MyMLet myMlet = new MyMLet(); 117 118 if (myMlet.check(null, null, null, content) != content.getCodeBase()) { 119 throw new RuntimeException("Failed to overrid the protected methed check"); 120 } 121 122 System.out.println(">>> The test is well passed."); 123 } 124 125 private static class MyMLet extends MLet { 126 public URL check(String version, 127 URL codebase, 128 String jarfile, 129 MLetContent content) { 130 return content.getCodeBase(); 131 } 132 } 133 134 private static final String archive = "my jarfile"; 135 private static final String code = "my code"; 136 private static final String object = "my object"; 137 private static final String name = "my name"; 138 private static final String version = "my version"; 139 140 private static final String myfile = "My file"; 141 private static final String baseUrl = "file:/tmp/test/"; 142 143 private final static String codebase = "my code base/"; 144 }