|
Java example source code file (RepositoryWildcardTest.java)
The RepositoryWildcardTest.java Java example source code/* * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4716807 * @summary Test if the repository supports correctly the use of * wildcards in the ObjectName key properties value part. * @author Luis-Miguel Alventosa * @run clean RepositoryWildcardTest * @run build RepositoryWildcardTest * @run main RepositoryWildcardTest */ import java.util.HashSet; import java.util.Set; import java.util.TreeSet; import javax.management.InstanceNotFoundException; import javax.management.MBeanServer; import javax.management.MBeanServerDelegate; import javax.management.MBeanServerFactory; import javax.management.ObjectName; import javax.management.RuntimeOperationsException; public class RepositoryWildcardTest { private static final String classname = "javax.management.monitor.StringMonitor"; private static int mbeanCreation(MBeanServer mbs, String name) throws Exception { int error = 0; try { System.out.println("Test: createMBean(" + name + ")"); mbs.createMBean(classname, ObjectName.getInstance(name)); error++; System.out.println("Didn't get expected exception!"); System.out.println("Test failed!"); } catch (RuntimeOperationsException e) { System.out.println("Got expected exception = " + e.getCause().toString()); System.out.println("Test passed!"); } return error; } private static int mbeanDeletion(MBeanServer mbs, String name) throws Exception { int error = 0; try { System.out.println("Test: unregisterMBean(" + name + ")"); mbs.unregisterMBean(ObjectName.getInstance(name)); error++; System.out.println("Didn't get expected exception!"); System.out.println("Test failed!"); } catch (InstanceNotFoundException e) { System.out.println("Got expected exception = " + e.toString()); System.out.println("Test passed!"); } return error; } private static int mbeanQuery(MBeanServer mbs, String name, Set<ObjectName> expectedSet) throws Exception { int error = 0; System.out.println("Test: queryNames(" + name + ")"); Set<ObjectName> returnedSet = mbs.queryNames(ObjectName.getInstance(name), null); System.out.println("ReturnedSet = " + new TreeSet(returnedSet)); System.out.println("ExpectedSet = " + new TreeSet(expectedSet)); if (returnedSet.equals(expectedSet)) { System.out.println("Test passed!"); } else { error++; System.out.println("Test failed!"); } return error; } public static void main(String[] args) throws Exception { int error = 0; MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName[] namesArray = { ObjectName.getInstance("d:k=abc"), ObjectName.getInstance("d:k=abcd"), ObjectName.getInstance("d:k=abcde"), ObjectName.getInstance("d:k=abc,k2=v2"), ObjectName.getInstance("d:k=abcd,k2=v2"), ObjectName.getInstance("d:k=abcde,k2=v2"), ObjectName.getInstance("d:k=\"abc\""), ObjectName.getInstance("d:k=\"abc\",k2=v2"), ObjectName.getInstance("d:p1=v1,p2=v2,p3=v3,p4=v4,p5=v5,p6=v6," + "p7=v7,p8=v8,p9=v9,p10=v10,p11=v11,p12=v12") }; for (ObjectName name : namesArray) mbs.createMBean(classname, name); System.out.println("----------------------------------------------"); System.out.println("TEST createMBean WITH PATTERNS"); System.out.println("----------------------------------------------"); error += mbeanCreation(mbs, "d:k=v,*"); error += mbeanCreation(mbs, "d:k=*"); error += mbeanCreation(mbs, "d:k=a?b"); error += mbeanCreation(mbs, "d:k=\"?\""); error += mbeanCreation(mbs, "d:k=\"a*b\""); System.out.println("----------------------------------------------"); System.out.println("TEST queryNames WITH PATTERNS"); System.out.println("----------------------------------------------"); Set<ObjectName> expectedSet = new HashSet Other Java examples (source code examples)Here is a short list of links related to this Java RepositoryWildcardTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.