001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestComponentLogger.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import com.sun.jbi.ComponentType;
032: import java.io.File;
033: import java.util.ArrayList;
034: import java.util.Properties;
035: import java.util.logging.Level;
036: import java.util.logging.Logger;
037:
038: /**
039: * Tests for the ComponentLogger class.
040: *
041: * @author Sun Microsystems, Inc.
042: */
043: public class TestComponentLogger extends junit.framework.TestCase {
044: /**
045: * Current test name.
046: */
047: private String mTestName;
048:
049: /**
050: * Current SRCROOT path.
051: */
052: private String mSrcroot;
053:
054: /**
055: * EnvironmentContext
056: */
057: private EnvironmentContext mEnvironmentContext;
058:
059: /**
060: * Component Root directory
061: */
062: private String mInstallRoot;
063:
064: /**
065: * Component instance created during setup.
066: */
067: private Component mComponent;
068:
069: /**
070: * ComponentLogger instance created during setup.
071: */
072: private ComponentLogger mComponentLogger;
073:
074: /**
075: * Component logger.
076: */
077: private Logger mLogger1 = Logger.getLogger(LOGGER_NAME_1);
078:
079: /**
080: * Component logger.
081: */
082: private Logger mLogger2 = Logger.getLogger(LOGGER_NAME_2);
083:
084: /**
085: * Component logger.
086: */
087: private Logger mLogger3 = Logger.getLogger(LOGGER_NAME_3);
088:
089: /**
090: * Parent logger.
091: */
092: private Logger mParentLogger;
093:
094: /**
095: * Array of component loggers.
096: */
097: private Logger[] mLoggers = { mLogger1, mLogger2, mLogger3 };
098:
099: /**
100: * Component name for the tests.
101: */
102: private static final String COMPONENT_NAME = "Engine1";
103:
104: /**
105: * Component logger display name for the tests.
106: */
107: private static final String DISPLAY_NAME_1 = "Logger1";
108:
109: /**
110: * Component logger display name for the tests.
111: */
112: private static final String DISPLAY_NAME_2 = "Logger2";
113:
114: /**
115: * Component logger display name for the tests.
116: */
117: private static final String DISPLAY_NAME_3 = "Logger3";
118:
119: /**
120: * Component logger name for the tests.
121: */
122: private static final String LOGGER_NAME_1 = "Engine1.logger1";
123:
124: /**
125: * Component logger name for the tests.
126: */
127: private static final String LOGGER_NAME_2 = "Engine1.logger2";
128:
129: /**
130: * Component logger name for the tests.
131: */
132: private static final String LOGGER_NAME_3 = "Engine1.logger3";
133:
134: /**
135: * Component parent logger name for the tests.
136: */
137: private static final String PARENT_LOGGER_NAME = "com.sun.test.parent";
138:
139: /**
140: * Array of component logger names and display names.
141: */
142: private static final String[][] NAMES = {
143: { LOGGER_NAME_1, DISPLAY_NAME_1 },
144: { LOGGER_NAME_2, DISPLAY_NAME_2 },
145: { LOGGER_NAME_3, DISPLAY_NAME_3 } };
146:
147: /**
148: * Index of logger name.
149: */
150: private static final int LOGGER_NAME_INDEX = 0;
151:
152: /**
153: * Index of display name.
154: */
155: private static final int DISPLAY_NAME_INDEX = 1;
156:
157: /**
158: * The constructor for this testcase, forwards the test name to
159: * the jUnit TestCase base class.
160: * @param aTestName String with the name of this test.
161: */
162: public TestComponentLogger(String aTestName) {
163: super (aTestName);
164: mTestName = aTestName;
165: }
166:
167: /**
168: * Setup for the test. This creates the ComponentLoggerMBean instance
169: * and other objects needed for the tests.
170: * @throws Exception when set up fails for any reason.
171: */
172: public void setUp() throws Exception {
173: super .setUp();
174: System.err.println("***** START of test " + mTestName);
175: mSrcroot = System.getProperty("junit.srcroot") + "/";
176: mInstallRoot = mSrcroot
177: + "runtime/framework/bld/Engine1/install_root";
178:
179: mEnvironmentContext = new EnvironmentContext(
180: new ScaffoldPlatformContext(), new JBIFramework(),
181: new Properties());
182:
183: // Create loggers for the test.
184:
185: mParentLogger = Logger.getLogger(PARENT_LOGGER_NAME);
186: mParentLogger.setLevel(Level.FINEST);
187:
188: for (int i = 0; i < mLoggers.length; i++) {
189: mLoggers[i].setLevel(null);
190: mLoggers[i].setParent(mParentLogger);
191: }
192:
193: // Create and initialize a Component instance and a ComponentLogger
194: // instance.
195:
196: mComponent = new Component();
197: mComponent.setName(COMPONENT_NAME);
198: mComponent.setComponentType(ComponentType.ENGINE);
199: mComponent.setInstallRoot(mInstallRoot);
200: mComponentLogger = new ComponentLogger(mComponent);
201: }
202:
203: /**
204: * Cleanup for the test.
205: * @throws Exception when tearDown fails for any reason.
206: */
207: public void tearDown() throws Exception {
208: File installRoot = new File(mInstallRoot);
209: File f = new File(installRoot.getParent()
210: + ComponentLogger.CONFIG_DIRECTORY
211: + ComponentLogger.LOGGER_SETTINGS);
212: f.delete();
213: System.err.println("***** END of test " + mTestName);
214: super .tearDown();
215: }
216:
217: // ============================= test methods ================================
218:
219: /**
220: * Test the addLogger method.
221: * @throws Exception if an unexpected error occurs.
222: */
223: public void testAddLogger() throws Exception {
224: String displayName = "Test Engine";
225: String name = "com.sun.jbi.component.TestEngine";
226: Logger log = Logger.getLogger(name);
227:
228: assertTrue("Failure adding new logger entry", mComponentLogger
229: .addLogger(log, displayName));
230: assertFalse("Failure adding existing logger entry",
231: mComponentLogger.addLogger(log, displayName));
232: }
233:
234: /**
235: * Test the addLoggerInfo method.
236: * @throws Exception if an unexpected error occurs.
237: */
238: public void testAddLoggerInfo() throws Exception {
239: // This will retrieve the top-level logger entry, created by the
240: // constructor.
241:
242: String[] topName = mComponentLogger.getLoggerNames();
243:
244: assertEquals("Failure getting logger names: ", 1,
245: topName.length);
246: assertEquals("Failure getting logger names: ", COMPONENT_NAME,
247: topName[0]);
248:
249: // Add some more logger names to the list.
250:
251: int i;
252: for (i = 0; i < mLoggers.length; i++) {
253: mComponentLogger.addLoggerInfo(NAMES[i][LOGGER_NAME_INDEX],
254: NAMES[i][DISPLAY_NAME_INDEX], true);
255: }
256:
257: // Verification. Note that the top-level component logger is added
258: // to the count.
259:
260: String[] names = mComponentLogger.getLoggerNames();
261: assertEquals("Failure getting logger names: ",
262: mLoggers.length + 1, names.length);
263: assertEquals("Failure getting logger names: ", COMPONENT_NAME,
264: names[0]);
265:
266: // Note that the table is a TreeMap, so the names come out in
267: // alphabetical order, so skip the first entry for the top-level logger.
268:
269: for (i = 1; i < names.length; i++) {
270: assertEquals("Logger info entry name mismatch: ",
271: NAMES[i - 1][LOGGER_NAME_INDEX], names[i]);
272: }
273: }
274:
275: /**
276: * Test the addLoggerInfo method with a default display name.
277: * @throws Exception if an unexpected error occurs.
278: */
279: public void testAddLoggerInfoDefault() throws Exception {
280: // This will retrieve the top-level logger entry, created by the
281: // constructor.
282:
283: String[] topName = mComponentLogger.getLoggerNames();
284:
285: assertEquals("Failure getting logger names: ", 1,
286: topName.length);
287: assertEquals("Failure getting logger names: ", COMPONENT_NAME,
288: topName[0]);
289:
290: // Add some more logger names to the list.
291:
292: int i;
293: for (i = 0; i < mLoggers.length; i++) {
294: mComponentLogger.addLoggerInfo(NAMES[i][LOGGER_NAME_INDEX],
295: null, true);
296: }
297:
298: // Verification. Note that the top-level component logger is added
299: // to the count.
300:
301: String[] names = mComponentLogger.getLoggerNames();
302: assertEquals("Failure getting logger names: ",
303: mLoggers.length + 1, names.length);
304: assertEquals("Failure getting logger names: ", COMPONENT_NAME,
305: names[0]);
306:
307: // Note that the table is a TreeMap, so the names come out in
308: // alphabetical order, so skip the first entry for the top-level logger.
309:
310: for (i = 1; i < names.length; i++) {
311: assertEquals("Logger info entry name mismatch: ", names[i],
312: NAMES[i - 1][LOGGER_NAME_INDEX]);
313: String displayName = getLastLevel(names[i]);
314: assertEquals("Logger info display name mismatch: ",
315: displayName, mComponentLogger
316: .getDisplayName(names[i]));
317: }
318: }
319:
320: /**
321: * Test the addLoggerInfo method with a prefix that doesn't match the
322: * component name.
323: * @throws Exception if an unexpected error occurs.
324: */
325: public void testAddLoggerInfoWithPrefix() throws Exception {
326: // This will retrieve the top-level logger entry, created by the
327: // constructor.
328:
329: String[] topName = mComponentLogger.getLoggerNames();
330:
331: assertEquals("Failure getting logger names: ", 1,
332: topName.length);
333: assertEquals("Failure getting logger names: ", COMPONENT_NAME,
334: topName[0]);
335:
336: // Add some more logger names to the list, but with a prefix set.
337:
338: String prefix = "Tests.";
339: mComponentLogger.setLoggerNamePrefix(prefix);
340: int i;
341: for (i = 0; i < mLoggers.length; i++) {
342: mComponentLogger.addLoggerInfo(NAMES[i][LOGGER_NAME_INDEX],
343: NAMES[i][DISPLAY_NAME_INDEX], true);
344: }
345:
346: // Verification. Note that the top-level component logger is added
347: // to the count.
348:
349: String[] names = mComponentLogger.getLoggerNames();
350: assertEquals("Failure getting logger names: ",
351: mLoggers.length + 1, names.length);
352: assertEquals("Failure getting logger names: ", COMPONENT_NAME,
353: names[0]);
354:
355: // Note that the table is a TreeMap, so the names come out in
356: // alphabetical order, so skip the first entry for the top-level logger.
357:
358: for (i = 1; i < names.length; i++) {
359: assertEquals("Logger info entry name mismatch: ", prefix
360: + NAMES[i - 1][LOGGER_NAME_INDEX], names[i]);
361: }
362: }
363:
364: /**
365: * Test the getLoggerNames method.
366: * @throws Exception if an unexpected error occurs.
367: */
368: public void testGetLoggerNames() throws Exception {
369: // Because the constructor always creates the top-level logger, at
370: // least one name is always returned.
371:
372: String[] oneName = mComponentLogger.getLoggerNames();
373: assertEquals("Failure getting logger names: ", 1,
374: oneName.length);
375:
376: int i;
377: for (i = 0; i < mLoggers.length; i++) {
378: mComponentLogger.addLogger(mLoggers[i],
379: NAMES[i][DISPLAY_NAME_INDEX]);
380: }
381:
382: String[] names = mComponentLogger.getLoggerNames();
383: assertEquals("Failure getting logger names: ",
384: mLoggers.length + 1, names.length);
385:
386: // Note that the table is a TreeMap, so the names come out in
387: // alphabetical order, so skip the first entry (which is "Engine1").
388:
389: for (i = 1; i < names.length; i++) {
390: assertEquals("Logger info entry name mismatch: ",
391: NAMES[i - 1][LOGGER_NAME_INDEX], names[i]);
392: }
393: }
394:
395: /**
396: * Test the get method for the display name for a logger that has been
397: * added dynamically.
398: * @throws Exception if an unexpected error occurs.
399: */
400: public void testGetDisplayNameGood() throws Exception {
401: for (int i = 0; i < mLoggers.length; i++) {
402: mComponentLogger.addLogger(mLoggers[i],
403: NAMES[i][DISPLAY_NAME_INDEX]);
404: assertEquals(
405: "Failure getting display name at index " + i + ": ",
406: NAMES[i][DISPLAY_NAME_INDEX],
407: mComponentLogger
408: .getDisplayName(NAMES[i][LOGGER_NAME_INDEX]));
409: }
410: }
411:
412: /**
413: * Test the get method for the display name for a logger that was not added
414: * dynamically and was not pre-defined.
415: * @throws Exception if an unexpected error occurs.
416: */
417: public void testGetDisplayNameDefault() throws Exception {
418: for (int i = 0; i < mLoggers.length; i++) {
419: String displayName = null;
420: String logName = NAMES[i][LOGGER_NAME_INDEX];
421: displayName = getLastLevel(logName);
422: assertEquals("Failure getting display name at index " + i
423: + ": ", displayName, mComponentLogger
424: .getDisplayName(NAMES[i][LOGGER_NAME_INDEX]));
425: }
426: }
427:
428: /**
429: * Test the get method for the display name for a logger with a null
430: * argument.
431: * @throws Exception if an unexpected error occurs.
432: */
433: public void testGetDisplayNameBadNullLoggerName() throws Exception {
434: try {
435: mComponentLogger.getDisplayName(null);
436: fail("Expected exception not received");
437: } catch (java.lang.IllegalArgumentException ex) {
438: // Verification
439: assertTrue(
440: "Incorrect exception received: " + ex.toString(),
441: (-1 < ex.getMessage().indexOf("logName")));
442: }
443: }
444:
445: /**
446: * Test the get method for the logger level.
447: * @throws Exception if an unexpected error occurs.
448: */
449: public void testGetLevelGood() throws Exception {
450: // Now register the logger with no level set
451: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
452: assertEquals("Failure getting log level with no level set: ",
453: mLogger1.getParent().getLevel().getLocalizedName(),
454: mComponentLogger.getLevel(LOGGER_NAME_1));
455:
456: // Now test with a level set
457: mLogger1.setLevel(Level.SEVERE);
458: assertEquals("Failure getting log level: ", mLogger1.getLevel()
459: .getLocalizedName(), mComponentLogger
460: .getLevel(LOGGER_NAME_1));
461: }
462:
463: /**
464: * Test the get method for the logger level with a null argument.
465: * @throws Exception if an unexpected error occurs.
466: */
467: public void testGetLevelBadNullLoggerName() throws Exception {
468: try {
469: mComponentLogger.getLevel(null);
470: fail("Expected exception not received");
471: } catch (java.lang.IllegalArgumentException ex) {
472: // Verification
473: assertTrue(
474: "Incorrect exception received: " + ex.toString(),
475: (-1 < ex.getMessage().indexOf("logName")));
476: }
477: }
478:
479: /**
480: * Test the get method for the logger level with an unregistered logger.
481: * @throws Exception if an unexpected error occurs.
482: */
483: public void testGetLevelBadNotRegistered() throws Exception {
484: try {
485: mComponentLogger.getLevel(LOGGER_NAME_1);
486: fail("Expected exception not received");
487: } catch (javax.jbi.JBIException ex) {
488: // Verification
489: assertTrue(
490: "Incorrect exception received: " + ex.toString(),
491: (-1 < ex.getMessage().indexOf("JBIFW2016")));
492: }
493: }
494:
495: /**
496: * Test the get method for the saved logger level with a null logger name.
497: * An exception is expected
498: * @throws Exception if an unexpected error occurs.
499: */
500: public void testGetSavedLevelBadNull() throws Exception {
501: try {
502: mComponentLogger.getSavedLevel(null);
503: fail("Expected exception not received");
504: } catch (java.lang.IllegalArgumentException ex) {
505: // Verification
506: assertTrue(
507: "Incorrect exception received: " + ex.toString(),
508: (-1 < ex.getMessage().indexOf("Null argument")));
509: }
510: }
511:
512: /**
513: * Test the get method for a saved logger level when no level has been
514: * set.
515: * @throws Exception if an unexpected error occurs.
516: */
517: public void testGetSavedLevelGoodNotSet() throws Exception {
518: Level l = mComponentLogger
519: .getSavedLevel("com.sun.jbi.test.logger");
520: assertNull(
521: "getLoggerLevel with no prior setLoggerLevel should return"
522: + " a null value, got " + l, l);
523: }
524:
525: /**
526: * Test the get and set methods for the logger name prefix.
527: * @throws Exception if an unexpected error occurs.
528: */
529: public void testGetSetLoggerNamePrefix() throws Exception {
530: String prefix = "com.sun.jbi.binding.test.";
531: mComponentLogger.setLoggerNamePrefix(prefix);
532: assertEquals("Failure setting/getting logger name prefix: ",
533: prefix, mComponentLogger.getLoggerNamePrefix());
534:
535: prefix = "com.acme.jbi.engine";
536: mComponentLogger.setLoggerNamePrefix(prefix);
537: assertEquals("Failure setting/getting logger name prefix: ",
538: prefix + ".", mComponentLogger.getLoggerNamePrefix());
539: }
540:
541: /**
542: * Test the isLoggerRegistered method.
543: * @throws Exception if an unexpected error occurs.
544: */
545: public void testIsLoggerRegistered() throws Exception {
546: String displayName = "Test Binding";
547: String name = "com.sun.jbi.component.TestBinding";
548: Logger log = Logger.getLogger(name);
549:
550: assertFalse("Failure checking for logger", mComponentLogger
551: .isLoggerRegistered(name));
552:
553: assertTrue("Failure adding new logger entry", mComponentLogger
554: .addLogger(log, displayName));
555:
556: assertTrue("Failure checking for logger", mComponentLogger
557: .isLoggerRegistered(name));
558: }
559:
560: /**
561: * Test the load/save methods for component logger levels. This test
562: * uses the get/set methods for verification. It also uses the
563: * setInstallRoot() method to set up the directory used by the load/save
564: * methods.
565: * @throws Exception if an unexpected error occurs.
566: */
567: public void testLoadSaveLoggerSettings() throws Exception {
568: File installRoot = new File(mInstallRoot);
569: installRoot.mkdirs();
570:
571: int i;
572:
573: for (i = 0; i < mLoggers.length; i++) {
574: mComponentLogger.addLogger(mLoggers[i],
575: NAMES[i][DISPLAY_NAME_INDEX]);
576: }
577:
578: // Save with no levels, then load. All levels should be null.
579:
580: mComponentLogger.saveLoggerSettings();
581: mComponentLogger.loadLoggerSettings();
582: for (i = 0; i < mLoggers.length; i++) {
583: Level level = mComponentLogger
584: .getSavedLevel(NAMES[i][LOGGER_NAME_INDEX]);
585: assertNull("Logger " + NAMES[i][LOGGER_NAME_INDEX]
586: + " level should have been null, not " + level,
587: level);
588: }
589:
590: // Set up some logger levels to persist
591:
592: Level[] levels = { Level.FINEST, Level.WARNING, Level.ALL };
593: for (i = 0; i < mLoggers.length; i++) {
594: mComponentLogger.setLevel(NAMES[i][LOGGER_NAME_INDEX],
595: levels[i]);
596: }
597:
598: // Now save logger levels and load again. All levels should be what
599: // was set.
600:
601: mComponentLogger.saveLoggerSettings();
602: mComponentLogger.loadLoggerSettings();
603: for (i = 0; i < mLoggers.length; i++) {
604: assertEquals(
605: "setLoggerLevel failed to set level for logger "
606: + NAMES[i][LOGGER_NAME_INDEX], levels[i],
607: mComponentLogger
608: .getSavedLevel(NAMES[i][LOGGER_NAME_INDEX]));
609: }
610: }
611:
612: /**
613: * Test the set method for the logger level with a null argument. This
614: * test covers all of the set<level> methods because they all delegate to
615: * this method.
616: * @throws Exception if an unexpected error occurs.
617: */
618: public void testSetLevelBadNullLoggerName() throws Exception {
619: try {
620: mComponentLogger.setLevel(null, null);
621: fail("Expected exception not received");
622: } catch (java.lang.IllegalArgumentException ex) {
623: // Verification
624: assertTrue(
625: "Incorrect exception received: " + ex.toString(),
626: (-1 < ex.getMessage().indexOf("logName")));
627: }
628: }
629:
630: /**
631: * Test the set method for the logger level with an unregistered logger.
632: * This test covers all of the set<level> methods because they all delegate
633: * to this method.
634: * @throws Exception if an unexpected error occurs.
635: */
636: public void testSetLevelBadNotRegistered() throws Exception {
637: try {
638: mComponentLogger.setLevel(LOGGER_NAME_1, null);
639: fail("Expected exception not received");
640: } catch (javax.jbi.JBIException ex) {
641: // Verification
642: assertTrue(
643: "Incorrect exception received: " + ex.toString(),
644: (-1 < ex.getMessage().indexOf("JBIFW2016")));
645: }
646: }
647:
648: /**
649: * Tests the setAll method.
650: * @throws Exception if an unexpected error occurs.
651: */
652:
653: public void testSetAll() throws Exception {
654: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
655: mComponentLogger.setAll(LOGGER_NAME_1);
656: assertEquals("setAll failed: ", Level.ALL, mLogger1.getLevel());
657: }
658:
659: /**
660: * Tests the setConfig method.
661: * @throws Exception if an unexpected error occurs.
662: */
663:
664: public void testSetConfig() throws Exception {
665: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
666: mComponentLogger.setConfig(LOGGER_NAME_1);
667: assertEquals("setConfig failed: ", Level.CONFIG, mLogger1
668: .getLevel());
669: }
670:
671: /**
672: * Tests the setDefault method.
673: * @throws Exception if an unexpected error occurs.
674: */
675:
676: public void testSetDefault() throws Exception {
677: // Set the child and parent loggers so that we can validate the results
678: mParentLogger.setLevel(Level.FINEST);
679: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
680: mLogger1.setLevel(Level.INFO);
681: assertEquals("getLevel failed to get correct level: ",
682: Level.INFO.getLocalizedName(), mComponentLogger
683: .getLevel(LOGGER_NAME_1));
684:
685: mComponentLogger.setDefault(LOGGER_NAME_1);
686: assertNull("setDefault failed: ", mLogger1.getLevel());
687: assertEquals("setDefault failed: ", mParentLogger.getLevel()
688: .getLocalizedName(), mComponentLogger
689: .getLevel(LOGGER_NAME_1));
690: }
691:
692: /**
693: * Tests the setFine method.
694: * @throws Exception if an unexpected error occurs.
695: */
696:
697: public void testSetFine() throws Exception {
698: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
699: mComponentLogger.setFine(LOGGER_NAME_1);
700: assertEquals("setFine failed: ", Level.FINE, mLogger1
701: .getLevel());
702: }
703:
704: /**
705: * Tests the setFiner method.
706: * @throws Exception if an unexpected error occurs.
707: */
708:
709: public void testSetFiner() throws Exception {
710: mComponentLogger.addLogger(mLogger2, DISPLAY_NAME_2);
711: mComponentLogger.setFiner(LOGGER_NAME_2);
712: assertEquals("setFiner failed: ", Level.FINER, mLogger2
713: .getLevel());
714: }
715:
716: /**
717: * Tests the setFinest method.
718: * @throws Exception if an unexpected error occurs.
719: */
720:
721: public void testSetFinest() throws Exception {
722: mComponentLogger.addLogger(mLogger3, DISPLAY_NAME_3);
723: mComponentLogger.setFinest(LOGGER_NAME_3);
724: assertEquals("setFinest failed: ", Level.FINEST, mLogger3
725: .getLevel());
726: }
727:
728: /**
729: * Tests the setInfo method.
730: * @throws Exception if an unexpected error occurs.
731: */
732:
733: public void testSetInfo() throws Exception {
734: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
735: mComponentLogger.setInfo(LOGGER_NAME_1);
736: assertEquals("setInfo failed: ", Level.INFO, mLogger1
737: .getLevel());
738: }
739:
740: /**
741: * Tests the setOff method.
742: * @throws Exception if an unexpected error occurs.
743: */
744:
745: public void testSetOff() throws Exception {
746: mComponentLogger.addLogger(mLogger2, DISPLAY_NAME_2);
747: mComponentLogger.setOff(LOGGER_NAME_2);
748: assertEquals("setOff failed: ", Level.OFF, mLogger2.getLevel());
749: }
750:
751: /**
752: * Tests the setSevere method.
753: * @throws Exception if an unexpected error occurs.
754: */
755:
756: public void testSetSevere() throws Exception {
757: mComponentLogger.addLogger(mLogger3, DISPLAY_NAME_3);
758: mComponentLogger.setSevere(LOGGER_NAME_3);
759: assertEquals("setSevere failed: ", Level.SEVERE, mLogger3
760: .getLevel());
761: }
762:
763: /**
764: * Tests the setWarning method.
765: * @throws Exception if an unexpected error occurs.
766: */
767:
768: public void testSetWarning() throws Exception {
769: mComponentLogger.addLogger(mLogger1, DISPLAY_NAME_1);
770: mComponentLogger.setWarning(LOGGER_NAME_1);
771: assertEquals("setWarning failed: ", Level.WARNING, mLogger1
772: .getLevel());
773: }
774:
775: /**
776: * Utility method to return the last level of a logger name.
777: * @param logName the logger name.
778: * @return the last level of the logger name.
779: */
780: private String getLastLevel(String logName) {
781: String lastLevel = null;
782: int lastDot = logName.lastIndexOf(".");
783: if (-1 < lastDot) {
784: lastLevel = logName.substring(lastDot + 1);
785: } else {
786: lastLevel = logName;
787: }
788: return lastLevel;
789: }
790:
791: }
|