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