Path: blob/master/test/jdk/javax/management/loading/MletParserLocaleTest.java
41152 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 706523626* @summary Checking MletParser for Locale insensitive strings27* @author Harsha Wardhana B28*29* @run clean MletParserLocaleTest30* @run build MletParserLocaleTest31* @run main/othervm MletParserLocaleTest mlet4.html32*/3334import java.io.File;35import java.util.Locale;36import javax.management.MBeanServer;37import javax.management.MBeanServerFactory;38import javax.management.ObjectName;39import javax.management.loading.MLet;4041public class MletParserLocaleTest {4243public static void main(String[] args) throws Exception {4445boolean error = false;4647// Instantiate the MBean server48//49System.out.println("Create the MBean server");50MBeanServer mbs = MBeanServerFactory.createMBeanServer();5152// Get Default Locale53Locale loc = Locale.getDefault();5455// Instantiate an MLet56//57System.out.println("Create the MLet");58MLet mlet = new MLet();5960// Register the MLet MBean with the MBeanServer61//62System.out.println("Register the MLet MBean");63ObjectName mletObjectName = new ObjectName("Test:type=MLet");64mbs.registerMBean(mlet, mletObjectName);6566// Call getMBeansFromURL67//68System.out.println("Call mlet.getMBeansFromURL(<url>)");69String testSrc = System.getProperty("test.src");70System.out.println("test.src = " + testSrc);71String urlCodebase;72if (testSrc.startsWith("/")) {73urlCodebase =74"file:" + testSrc.replace(File.separatorChar, '/') + "/";75} else {76urlCodebase =77"file:/" + testSrc.replace(File.separatorChar, '/') + "/";78}79String mletFile = urlCodebase + args[0];80System.out.println("MLet File = " + mletFile);81try {82// Change default Locale to Turkish83Locale.setDefault(new Locale("tr", "TR"));84mlet.getMBeansFromURL(mletFile);85System.out.println("Test Passes");86} catch (Exception e) {87error = true;88e.printStackTrace(System.out);89}finally {90Locale.setDefault(loc);91}9293// Unregister the MLet MBean94//95System.out.println("Unregister the MLet MBean");96mbs.unregisterMBean(mletObjectName);9798// Release MBean server99//100System.out.println("Release the MBean server");101MBeanServerFactory.releaseMBeanServer(mbs);102103// End Test104//105System.out.println("Bye! Bye!");106if (error) System.exit(1);107}108}109110111