test/jdk/javax/management/openmbean/IsValueTest.java
author jwilhelm
Thu, 24 Jan 2019 21:24:29 +0100
changeset 53479 31e5c82f59e9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8217580: Remove tests from problemList as bugs has been closed Reviewed-by: iignatyev, mseledtsov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2006, 2015, 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 5072004
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test new rules for isValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.openmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class IsValueTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private static String failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        CompositeType ctOld =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
            new CompositeType("same.type.name", "old",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                new String[] {"int", "string"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                new String[] {"an int", "a string"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                new OpenType[] {SimpleType.INTEGER, SimpleType.STRING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        CompositeType ctNew =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            new CompositeType("same.type.name", "new",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                new String[] {"int", "int2", "string"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                new String[] {"an int", "another int", "a string"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                new OpenType[] {SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.STRING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        CompositeData cdOld =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            new CompositeDataSupport(ctOld,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                new String[] {"string", "int"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                new Object[] {"bar", 17});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        CompositeData cdNew =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            new CompositeDataSupport(ctNew,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                new String[] {"int2", "int", "string"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                new Object[] {4, 3, "foo"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // Check that adding fields doesn't make isValue return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        check(ctOld.isValue(cdNew), "isValue: " + ctOld + "[" + cdNew + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        // Check that removing fields does make isValue return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        check(!ctNew.isValue(cdOld), "isValue: " + ctNew + "[" + cdOld + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // Check that we can add a contained CompositeData with extra fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        // inside another CompositeData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        CompositeType ctWrapOld =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            new CompositeType("wrapper", "wrapper",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                new OpenType[] {ctOld});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            new CompositeDataSupport(ctWrapOld,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                new Object[] {cdNew});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            check(true, "CompositeDataSupport containing CompositeDataSupport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            check(false, "CompositeDataSupport containing CompositeDataSupport: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // ...but not the contrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        CompositeType ctWrapNew =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            new CompositeType("wrapper", "wrapper",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                new OpenType[] {ctNew});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            new CompositeDataSupport(ctWrapNew,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                new Object[] {cdOld});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            check(false, "CompositeDataSupport containing old did not get exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            check(true, "CompositeDataSupport containing old got expected exception: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // Check that a TabularData can get an extended CompositeData row
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        TabularType ttOld =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            new TabularType("tabular", "tabular", ctOld, new String[] {"int"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        TabularData tdOld =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            new TabularDataSupport(ttOld);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            tdOld.put(cdNew);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            check(true, "TabularDataSupport adding extended CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            check(false, "TabularDataSupport adding extended CompositeData: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // Check that an extended TabularData can be put into a CompositeData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        TabularType ttNew =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            new TabularType("tabular", "tabular", ctNew, new String[] {"int"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        TabularData tdNew =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            new TabularDataSupport(ttNew);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        CompositeType cttWrap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            new CompositeType("wrapTT", "wrapTT",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                new OpenType[] {ttOld});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            new CompositeDataSupport(cttWrap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                new String[] {"wrapped"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                new Object[] {tdNew});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            check(true, "CompositeDataSupport adding extended TabularData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            check(false, "CompositeDataSupport adding extended TabularData: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (failed != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new Exception("TEST FAILED: " + failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private static void check(boolean value, String what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            System.out.println("OK: " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            failed = what;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            System.out.println("FAILED: " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}