1   /*
2    *  XNap
3    *
4    *  A pure java file sharing client.
5    *
6    *  See AUTHORS for copyright information.
7    *
8    *  This program is free software; you can redistribute it and/or modify
9    *  it under the terms of the GNU General Public License as published by
10   *  the Free Software Foundation; either version 2 of the License, or
11   *  (at your option) any later version.
12   *
13   *  This program is distributed in the hope that it will be useful,
14   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   *  GNU General Public License for more details.
17   *
18   *  You should have received a copy of the GNU General Public License
19   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   */
23  package org.xnap.util;
24  
25  import java.util.Properties;
26  
27  import junit.framework.TestCase;
28  
29  import org.apache.log4j.spi.ThrowableInformation;
30  import org.xnap.plugin.Plugin;
31  import org.xnap.plugin.PluginInfo;
32  import org.xnap.plugin.PluginManager;
33  
34  /***
35   * @author Steffen Pingel
36   */
37  public class UncaughtExceptionManagerTest extends TestCase {
38      
39      public UncaughtExceptionManagerTest(String name) 
40      {
41  		super(name);
42      }
43  
44      protected void setUp()
45      {
46      }
47  
48      protected void tearDown()
49      {
50      }
51  
52      public void testRemoveExceptionDescription() 
53      {
54  		String trace = "java.lang.ArrayIndexOutOfBoundsException: 0 >= 0\n"
55  			+ "\tat java.util.Vector.elementAt(Vector.java:431)\n";
56  		String cleanTrace = "java.lang.ArrayIndexOutOfBoundsException\n"
57  			+ "\tat java.util.Vector.elementAt(Vector.java:431)\n";
58  		assertEquals
59  			(UncaughtExceptionManager.removeExceptionDescription
60  			 (trace, "java.lang.ArrayIndexOutOfBoundsException"),
61  			 cleanTrace);
62      }
63  
64  	public void testGetPlugin()
65  	{
66  		Properties props = new Properties();
67  		props.put("Class-Name", "org.xnap.plugin.test.TestPlugin");
68  		props.put("Name", "Test");
69  		props.put("Version", "1.0.0");
70  
71  		PluginInfo info = new PluginInfo(props);
72  		info.setEnabled(true);
73  		PluginManager.getInstance().add(info);
74  		
75  		String trace = "java.lang.RuntimeException\n"
76  			+ "\tat org.xnap.plugin.test.ClassName(ClassName.java:1)\n";
77  		assertEquals(UncaughtExceptionManager.getPlugin(trace), "Test 1.0.0");
78  		
79  		PluginManager.getInstance().remove(info);
80  	}
81  	
82  }