jdk/test/javax/management/loading/MletParserLocaleTest.java
changeset 35268 d5aa211825e1
child 44423 306c020eb154
equal deleted inserted replaced
35267:8f0a2a0b4d96 35268:d5aa211825e1
       
     1 /*
       
     2  * Copyright (c) 2015, 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 7065236
       
    27  * @summary Checking MletParser for Locale insensitive strings
       
    28  * @author Harsha Wardhana B
       
    29  * @modules java.management
       
    30  * @run clean MletParserLocaleTest
       
    31  * @run build MletParserLocaleTest
       
    32  * @run main/othervm/timeout=5 MletParserLocaleTest mlet4.html
       
    33  */
       
    34 
       
    35 import java.io.File;
       
    36 import java.util.Locale;
       
    37 import javax.management.MBeanServer;
       
    38 import javax.management.MBeanServerFactory;
       
    39 import javax.management.ObjectName;
       
    40 import javax.management.loading.MLet;
       
    41 
       
    42 public class MletParserLocaleTest {
       
    43 
       
    44     public static void main(String[] args) throws Exception {
       
    45 
       
    46         boolean error = false;
       
    47 
       
    48         // Instantiate the MBean server
       
    49         //
       
    50         System.out.println("Create the MBean server");
       
    51         MBeanServer mbs = MBeanServerFactory.createMBeanServer();
       
    52 
       
    53         // Get Default Locale
       
    54         Locale loc = Locale.getDefault();
       
    55 
       
    56         // Instantiate an MLet
       
    57         //
       
    58         System.out.println("Create the MLet");
       
    59         MLet mlet = new MLet();
       
    60 
       
    61         // Register the MLet MBean with the MBeanServer
       
    62         //
       
    63         System.out.println("Register the MLet MBean");
       
    64         ObjectName mletObjectName = new ObjectName("Test:type=MLet");
       
    65         mbs.registerMBean(mlet, mletObjectName);
       
    66 
       
    67         // Call getMBeansFromURL
       
    68         //
       
    69         System.out.println("Call mlet.getMBeansFromURL(<url>)");
       
    70         String testSrc = System.getProperty("test.src");
       
    71         System.out.println("test.src = " + testSrc);
       
    72         String urlCodebase;
       
    73         if (testSrc.startsWith("/")) {
       
    74             urlCodebase =
       
    75                 "file:" + testSrc.replace(File.separatorChar, '/') + "/";
       
    76         } else {
       
    77             urlCodebase =
       
    78                 "file:/" + testSrc.replace(File.separatorChar, '/') + "/";
       
    79         }
       
    80         String mletFile = urlCodebase + args[0];
       
    81         System.out.println("MLet File = " + mletFile);
       
    82         try {
       
    83             // Change default Locale to Turkish
       
    84             Locale.setDefault(new Locale("tr", "TR"));
       
    85             mlet.getMBeansFromURL(mletFile);
       
    86             System.out.println("Test Passes");
       
    87         } catch (Exception e) {
       
    88             error = true;
       
    89             e.printStackTrace(System.out);
       
    90         }finally {
       
    91             Locale.setDefault(loc);
       
    92         }
       
    93 
       
    94         // Unregister the MLet MBean
       
    95         //
       
    96         System.out.println("Unregister the MLet MBean");
       
    97         mbs.unregisterMBean(mletObjectName);
       
    98 
       
    99         // Release MBean server
       
   100         //
       
   101         System.out.println("Release the MBean server");
       
   102         MBeanServerFactory.releaseMBeanServer(mbs);
       
   103 
       
   104         // End Test
       
   105         //
       
   106         System.out.println("Bye! Bye!");
       
   107         if (error) System.exit(1);
       
   108     }
       
   109 }