001: /*
002: * Copyright 2004,2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.logging;
018:
019: import junit.framework.TestCase;
020:
021: /**
022: * Tests the basic logging operations to ensure that they all function
023: * without exception failure. In other words, that they do no fail by
024: * throwing exceptions.
025: * This is the minimum requirement for any well behaved logger
026: * and so this test should be run for each kind.
027: */
028: public class BasicOperationsTestCase extends TestCase {
029: public void testIsEnabledClassLog() {
030: Log log = LogFactory.getLog(BasicOperationsTestCase.class);
031: executeIsEnabledTest(log);
032: }
033:
034: public void testIsEnabledNamedLog() {
035: Log log = LogFactory.getLog(BasicOperationsTestCase.class
036: .getName());
037: executeIsEnabledTest(log);
038: }
039:
040: public void executeIsEnabledTest(Log log) {
041: try {
042: log.isTraceEnabled();
043: log.isDebugEnabled();
044: log.isInfoEnabled();
045: log.isWarnEnabled();
046: log.isErrorEnabled();
047: log.isFatalEnabled();
048: } catch (Throwable t) {
049: t.printStackTrace();
050: fail("Exception thrown: " + t);
051: }
052: }
053:
054: public void testMessageWithoutExceptionClassLog() {
055: Log log = LogFactory.getLog(BasicOperationsTestCase.class);
056: executeMessageWithoutExceptionTest(log);
057: }
058:
059: public void testMessageWithoutExceptionNamedLog() {
060: Log log = LogFactory.getLog(BasicOperationsTestCase.class
061: .getName());
062: executeMessageWithoutExceptionTest(log);
063: }
064:
065: public void executeMessageWithoutExceptionTest(Log log) {
066: try {
067: log.trace("Hello, Mum");
068: log.debug("Hello, Mum");
069: log.info("Hello, Mum");
070: log.warn("Hello, Mum");
071: log.error("Hello, Mum");
072: log.fatal("Hello, Mum");
073: } catch (Throwable t) {
074: t.printStackTrace();
075: fail("Exception thrown: " + t);
076: }
077: }
078:
079: public void testMessageWithExceptionClassLog() {
080: Log log = LogFactory.getLog(BasicOperationsTestCase.class);
081: executeMessageWithExceptionTest(log);
082: }
083:
084: public void testMessageWithExceptionNamedLog() {
085: Log log = LogFactory.getLog(BasicOperationsTestCase.class
086: .getName());
087: executeMessageWithExceptionTest(log);
088: }
089:
090: public void executeMessageWithExceptionTest(Log log) {
091: try {
092: log.trace("Hello, Mum", new ArithmeticException());
093: log.debug("Hello, Mum", new ArithmeticException());
094: log.info("Hello, Mum", new ArithmeticException());
095: log.warn("Hello, Mum", new ArithmeticException());
096: log.error("Hello, Mum", new ArithmeticException());
097: log.fatal("Hello, Mum", new ArithmeticException());
098: } catch (Throwable t) {
099: t.printStackTrace();
100: fail("Exception thrown: " + t);
101: }
102: }
103: }
|