jdk/test/javax/management/openmbean/CompositeDataStringTest.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 5506 202f599c92aa
child 44423 306c020eb154
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1020
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
1020
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     4
 *
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     8
 *
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    13
 * accompanied this code).
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    14
 *
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1570
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1570
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1570
diff changeset
    21
 * questions.
1020
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    22
 */
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    23
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    24
/*
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    25
 * @test
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    26
 * @bug 6610174
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    27
 * @summary Test that CompositeDataSupport.toString() represents arrays correctly
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    28
 * @author Eamonn McManus
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    29
 * @modules java.management
1020
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    30
 */
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1020
diff changeset
    31
1020
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    32
import javax.management.openmbean.ArrayType;
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    33
import javax.management.openmbean.CompositeData;
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    34
import javax.management.openmbean.CompositeDataSupport;
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1020
diff changeset
    35
import javax.management.openmbean.CompositeType;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1020
diff changeset
    36
import javax.management.openmbean.OpenType;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1020
diff changeset
    37
import javax.management.openmbean.SimpleType;
1020
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    38
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    39
public class CompositeDataStringTest {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    41
        CompositeType basicCT = new CompositeType(
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    42
                "basicCT", "basic CompositeType",
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    43
                new String[] {"name", "value"},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    44
                new String[] {"name", "value"},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    45
                new OpenType<?>[] {SimpleType.STRING, SimpleType.INTEGER});
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    46
        CompositeType ct = new CompositeType(
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    47
                "noddy", "descr",
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    48
                new String[] {"strings", "ints", "cds"},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    49
                new String[] {"string array", "int array", "composite data array"},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    50
                new OpenType<?>[] {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    51
                    ArrayType.getArrayType(SimpleType.STRING),
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    52
                    ArrayType.getPrimitiveArrayType(int[].class),
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    53
                    ArrayType.getArrayType(basicCT)
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    54
                });
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    55
        CompositeData basicCD1 = new CompositeDataSupport(
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    56
                basicCT, new String[] {"name", "value"}, new Object[] {"ceathar", 4});
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    57
        CompositeData basicCD2 = new CompositeDataSupport(
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    58
                basicCT, new String[] {"name", "value"}, new Object[] {"naoi", 9});
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    59
        CompositeData cd = new CompositeDataSupport(
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    60
                ct,
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    61
                new String[] {"strings", "ints", "cds"},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    62
                new Object[] {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    63
                    new String[] {"fred", "jim", "sheila"},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    64
                    new int[] {2, 3, 5, 7},
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    65
                    new CompositeData[] {basicCD1, basicCD2}
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    66
                });
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    67
        String s = cd.toString();
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    68
        System.out.println("CompositeDataSupport.toString(): " + s);
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    69
        String[] expected = {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    70
            "fred, jim, sheila",
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    71
            "2, 3, 5, 7",
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    72
            "ceathar",
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    73
            "naoi",
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    74
        };
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    75
        boolean ok = true;
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    76
        for (String expect : expected) {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    77
            if (s.contains(expect))
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    78
                System.out.println("OK: string contains <" + expect + ">");
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    79
            else {
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    80
                ok = false;
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    81
                System.out.println("NOT OK: string does not contain <" +
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    82
                        expect + ">");
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    83
            }
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    84
        }
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    85
        if (ok)
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    86
            System.out.println("TEST PASSED");
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    87
        else
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    88
            throw new Exception("TEST FAILED: string did not contain expected substrings");
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    89
    }
e7a021898dff 6610174: Improve CompositeDataSupport.toString when it includes arrays
emcmanus
parents:
diff changeset
    90
}