1 /*
2 * Copyright (c) 2003, 2004, 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 */
26 * @bug 5007165
27 *
28 * @summary Basic Test for LoggingMXBean via MBeanServer
29 * @author Ron Mann
30 *
31 * @build LoggingMXBeanTest
32 * @run main LoggingMXBeanTest
33 */
34
35 import javax.management.*;
36 import java.util.logging.*;
37
38
39 public class LoggingMXBeanTest
40 {
41
42 LoggingMXBean mBean;
43 ObjectName objectName = null;
44 static String LOGGER_NAME_1 = "com.sun.management.Logger1";
45 static String LOGGER_NAME_2 = "com.sun.management.Logger2";
46
47 public LoggingMXBeanTest() throws Exception {
48
49 /*
50 * Create the MBeanServeri, register the LoggingMXBean
51 */
52 System.out.println( "***************************************************" );
53 System.out.println( "********** LoggingMXBean Unit Test **********" );
54 System.out.println( "***************************************************" );
55 System.out.println( "" );
56 System.out.println( "*******************************" );
57 System.out.println( "*********** Phase 1 ***********" );
58 System.out.println( "*******************************" );
59 System.out.println( " Creating MBeanServer " );
60 System.out.print( " Register LoggingMXBean: " );
61 MBeanServer mbs = MBeanServerFactory.createMBeanServer();
62 String[] list = new String[0];
63
64 try {
65 objectName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);
114 String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
115 System.out.println(" : Logger #" + i + " = " + list[i] );
116 System.out.println(" : Level = " + levelName );
117 }
118 catch ( Exception e ) {
119 System.out.println(" : FAILED" );
120 throw e;
121 }
122 }
123 System.out.println(" : PASSED" );
124 }
125
126 /*
127 * Create two new loggers to the list of Loggers already present
128 */
129 System.out.println("");
130 System.out.println( "*******************************" );
131 System.out.println( "*********** Phase 3 ***********" );
132 System.out.println( "*******************************" );
133 System.out.println( " Create and test new Loggers" );
134 Logger logger1 = Logger.getLogger( LOGGER_NAME_1 );
135 Logger logger2 = Logger.getLogger( LOGGER_NAME_2 );
136
137 // check that Level object are returned properly
138 try {
139 list = (String[]) mbs.getAttribute( objectName, "LoggerNames" );
140 }
141 catch ( Exception e ) {
142 System.out.println(" : FAILED" );
143 throw e;
144 }
145
146 /*
147 * Check for the existence of our new Loggers
148 */
149 boolean log1 = false, log2 = false;
150
151 if ( list == null || list.length < 2 ) {
152 System.out.println(" : FAILED. Could not Detect the presense of the new Loggers" );
153 throw new RuntimeException(
154 "Could not Detect the presense of the new Loggers");
155 }
|
1 /*
2 * Copyright (c) 2003, 2012, 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 */
26 * @bug 5007165
27 *
28 * @summary Basic Test for LoggingMXBean via MBeanServer
29 * @author Ron Mann
30 *
31 * @build LoggingMXBeanTest
32 * @run main LoggingMXBeanTest
33 */
34
35 import javax.management.*;
36 import java.util.logging.*;
37
38
39 public class LoggingMXBeanTest
40 {
41
42 LoggingMXBean mBean;
43 ObjectName objectName = null;
44 static String LOGGER_NAME_1 = "com.sun.management.Logger1";
45 static String LOGGER_NAME_2 = "com.sun.management.Logger2";
46 static Logger logger1;
47 static Logger logger2;
48
49 public LoggingMXBeanTest() throws Exception {
50
51 /*
52 * Create the MBeanServeri, register the LoggingMXBean
53 */
54 System.out.println( "***************************************************" );
55 System.out.println( "********** LoggingMXBean Unit Test **********" );
56 System.out.println( "***************************************************" );
57 System.out.println( "" );
58 System.out.println( "*******************************" );
59 System.out.println( "*********** Phase 1 ***********" );
60 System.out.println( "*******************************" );
61 System.out.println( " Creating MBeanServer " );
62 System.out.print( " Register LoggingMXBean: " );
63 MBeanServer mbs = MBeanServerFactory.createMBeanServer();
64 String[] list = new String[0];
65
66 try {
67 objectName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);
116 String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
117 System.out.println(" : Logger #" + i + " = " + list[i] );
118 System.out.println(" : Level = " + levelName );
119 }
120 catch ( Exception e ) {
121 System.out.println(" : FAILED" );
122 throw e;
123 }
124 }
125 System.out.println(" : PASSED" );
126 }
127
128 /*
129 * Create two new loggers to the list of Loggers already present
130 */
131 System.out.println("");
132 System.out.println( "*******************************" );
133 System.out.println( "*********** Phase 3 ***********" );
134 System.out.println( "*******************************" );
135 System.out.println( " Create and test new Loggers" );
136 logger1 = Logger.getLogger( LOGGER_NAME_1 );
137 logger2 = Logger.getLogger( LOGGER_NAME_2 );
138
139 // check that Level object are returned properly
140 try {
141 list = (String[]) mbs.getAttribute( objectName, "LoggerNames" );
142 }
143 catch ( Exception e ) {
144 System.out.println(" : FAILED" );
145 throw e;
146 }
147
148 /*
149 * Check for the existence of our new Loggers
150 */
151 boolean log1 = false, log2 = false;
152
153 if ( list == null || list.length < 2 ) {
154 System.out.println(" : FAILED. Could not Detect the presense of the new Loggers" );
155 throw new RuntimeException(
156 "Could not Detect the presense of the new Loggers");
157 }
|