KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > io > SinkHandlerTest


1 /* SinkHandlerTest.java
2  *
3  * $Id: SinkHandlerTest.java,v 1.1 2005/08/15 23:34:55 stack-sf Exp $
4  *
5  * Created Aug 9, 2005
6  *
7  * Copyright (C) 2005 Internet Archive.
8  *
9  * This file is part of the Heritrix web crawler (crawler.archive.org).
10  *
11  * Heritrix is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or
14  * any later version.
15  *
16  * Heritrix is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser Public License
22  * along with Heritrix; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */

25 package org.archive.io;
26
27 import java.io.ByteArrayInputStream JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.LogManager JavaDoc;
30 import java.util.logging.Logger JavaDoc;
31
32 import junit.framework.TestCase;
33
34 public class SinkHandlerTest extends TestCase {
35     private static final Logger JavaDoc LOGGER =
36         Logger.getLogger(SinkHandlerTest.class.getName());
37     
38     protected void setUp() throws Exception JavaDoc {
39         super.setUp();
40         String JavaDoc logConfig = "handlers = " +
41             "org.archive.io.SinkHandler\n" +
42             "org.archive.io.SinkHandler.level = ALL";
43         ByteArrayInputStream JavaDoc bais =
44             new ByteArrayInputStream JavaDoc(logConfig.getBytes());
45         LogManager.getLogManager().readConfiguration(bais);
46     }
47     
48     public void testLogging() throws Exception JavaDoc {
49         LOGGER.severe("Test1");
50         LOGGER.severe("Test2");
51         LOGGER.warning("Test3");
52         RuntimeException JavaDoc e = new RuntimeException JavaDoc("Nothing exception");
53         LOGGER.log(Level.SEVERE, "with exception", e);
54         SinkHandler h = SinkHandler.getInstance();
55         assertEquals(h.getAllUnread().size(), 4);
56         SinkHandlerLogRecord shlr = h.get(3);
57         h.remove(3);
58         assertEquals(h.getAllUnread().size(), 3);
59         h.publish(shlr);
60         assertEquals(h.getAllUnread().size(), 4);
61     }
62     /*
63     public void testToString() throws Exception {
64         RuntimeException e = new RuntimeException("Some-Message");
65         LOGGER.log(Level.SEVERE, "With-Exception", e);
66         SinkHandler h = SinkHandler.getInstance();
67         System.out.print(((SeenLogRecord)h.getSink().get(0)).toString());
68         LOGGER.log(Level.SEVERE, "No-Exception");
69         System.out.print(((SeenLogRecord)h.getSink().get(1)).toString());
70     }*/

71 }
72
Popular Tags