001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.util.test;
018:
019: import junit.framework.TestCase;
020:
021: import org.apache.avalon.framework.logger.ConsoleLogger;
022: import org.apache.avalon.framework.logger.Logger;
023: import org.apache.cocoon.util.Deprecation;
024: import org.apache.cocoon.util.DeprecationException;
025:
026: /**
027: * Test Cases for the Deprecation class.
028: * @see org.apache.cocoon.util.Deprecation
029: *
030: * @version $Id: DeprecationTestCase.java 433543 2006-08-22 06:22:54Z crossley $
031: */
032: public class DeprecationTestCase extends TestCase {
033: public DeprecationTestCase(String name) {
034: super (name);
035: }
036:
037: private Logger originalLogger;
038: private Logger consoleLogger;
039:
040: public void setUp() throws Exception {
041: super .setUp();
042: originalLogger = Deprecation.logger;
043: // Setup a disabled logger: avoids polluting the test output, and also test
044: // that isXXXEnabled also matches the forbidden deprecation level
045: consoleLogger = new ConsoleLogger(ConsoleLogger.LEVEL_DISABLED);
046: Deprecation.setLogger(consoleLogger);
047: Deprecation.setForbiddenLevel(Deprecation.ERROR);
048: }
049:
050: public void tearDown() throws Exception {
051: Deprecation.setLogger(originalLogger);
052: super .tearDown();
053: }
054:
055: public void testPrecond() {
056: // Double check that our logger won't let anything go through, and that
057: // enabled levels are because of the allowed level we've set.
058: assertFalse(consoleLogger.isInfoEnabled());
059: assertFalse(consoleLogger.isWarnEnabled());
060: assertFalse(consoleLogger.isErrorEnabled());
061: }
062:
063: public void testInfoOk() {
064: try {
065: Deprecation.logger.info("testing deprecation logs");
066: } catch (DeprecationException de) {
067: fail("Should not throw an exception");
068: }
069: }
070:
071: public void testWarnOk() {
072: try {
073: Deprecation.logger.warn("testing deprecation logs");
074: } catch (DeprecationException de) {
075: fail("Should not throw an exception");
076: }
077: }
078:
079: public void testErrorFails() {
080: try {
081: Deprecation.logger.error("testing deprecation logs");
082: } catch (DeprecationException de) {
083: return; // success
084: }
085: fail("Should throw an exception");
086: }
087:
088: public void testDebugFails() {
089: Deprecation.setForbiddenLevel(Deprecation.DEBUG);
090: try {
091: Deprecation.logger.debug("testing deprecation logs");
092: } catch (DeprecationException de) {
093: return; // success
094: }
095: fail("Should throw an exception");
096: }
097:
098: public void testInfoDisabled() {
099: assertFalse(Deprecation.logger.isInfoEnabled());
100: }
101:
102: public void testWarnDisabled() {
103: assertFalse(Deprecation.logger.isWarnEnabled());
104: }
105:
106: public void testErrorEnabled() {
107: assertTrue(Deprecation.logger.isErrorEnabled());
108: }
109: }
|