001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2001, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.util;
018:
019: // J2SE dependencies
020: import java.util.logging.Level;
021: import java.util.logging.Logger;
022:
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: import org.geotools.resources.Arguments;
028:
029: /**
030: * Test the {@link MonolineFormatter} class.
031: *
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/util/MonolineFormatterTest.java $
033: * @version $Id: MonolineFormatterTest.java 24576 2007-02-24 00:07:40Z desruisseaux $
034: * @author Martin Desruisseaux
035: */
036: public final class MonolineFormatterTest extends TestCase {
037: /**
038: * Returns the test suite.
039: */
040: public static Test suite() {
041: return new TestSuite(MonolineFormatterTest.class);
042: }
043:
044: /**
045: * Constructs a test case with the given name.
046: */
047: public MonolineFormatterTest(final String name) {
048: super (name);
049: }
050:
051: /**
052: * Set to <code>true</code> if this is run has a JUnit test
053: * (i.e. not from the command line).
054: */
055: private static boolean runFromJUnit;
056:
057: /**
058: * Set up common objects used for all tests. This initialization is performed by
059: * JUnit, but is <strong>not</strong> performed when the test is run from the
060: * command line. Instead, the initialization on command line is controled by
061: * the optional "-init" argument.
062: */
063: protected void setUp() throws Exception {
064: runFromJUnit = true;
065: super .setUp();
066: Logging.GEOTOOLS.forceMonolineConsoleOutput();
067: }
068:
069: /**
070: * Run the test. This is only a visual test.
071: */
072: public void testInitialization() {
073: if (runFromJUnit) {
074: // Avoid polluting the output stream during JUnit tests.
075: return;
076: }
077: final String[] namespaces = { "org.geotools.core",
078: "org.geotools.resources", "org.geotools.referencing",
079: "org.opengis.referencing" // Non-geotools logger should not be affected.
080: };
081: for (int i = 0; i < namespaces.length; i++) {
082: System.out.println();
083: System.out.print("Testing ");
084: final Logger logger = Logger.getLogger(namespaces[i]);
085: System.out.println(logger.getName());
086: logger.severe("Don't worry, just a test");
087: logger.warning("This is an imaginary warning");
088: logger.info("This is a pseudo-information message");
089: logger.config("Not really configuring anything...");
090: logger
091: .fine("This is a detailed (but useless) message\nWe log this one on two lines!");
092: logger.finer("This is a debug message");
093: }
094: }
095:
096: /**
097: * Run the test from the commande line. The {@link GeotoolsHandler} will be registered
098: * only if the <code>-init</code> option was explicitely specified on the command line.
099: * Otherwise, <code>GeotoolsHandler</code> will be used only if declared in
100: * <code>jre/lib/logging.properties</code>.
101: */
102: public static void main(final String[] args) {
103: final Arguments arguments = new Arguments(args);
104: if (arguments.getFlag("-init")) {
105: Logging.GEOTOOLS.forceMonolineConsoleOutput();
106: }
107: if (arguments.getFlag("-geotools")) {
108: MonolineFormatter.init("org.geotools", (Level) null);
109: }
110: arguments.getRemainingArguments(0);
111: new MonolineFormatterTest(null).testInitialization();
112: }
113: }
|