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