KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > AdminConsoleTest


1 /**
2  * $RCSfile: AdminConsoleTest.java,v $
3  * $Revision: 1.4 $
4  * $Date: 2005/01/09 21:50:27 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  */

8
9 package org.jivesoftware.util;
10
11 import java.io.FileInputStream JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.util.Collection JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.lang.reflect.Method JavaDoc;
16 import junit.framework.TestCase;
17 import org.jivesoftware.admin.AdminConsole;
18 import org.dom4j.Element;
19
20 public class AdminConsoleTest extends TestCase {
21
22     public AdminConsoleTest() {
23
24     }
25
26     /**
27      * Resets the admin console internal data structures.
28      */

29     public void tearDown() throws Exception JavaDoc {
30         Class JavaDoc c = AdminConsole.class;
31         Method JavaDoc init = c.getDeclaredMethod("init", (Class JavaDoc[])null);
32         init.setAccessible(true);
33         init.invoke((Object JavaDoc)null, (Object JavaDoc[])null);
34     }
35
36     public void testGetGlobalProps() throws Exception JavaDoc {
37         String JavaDoc name = AdminConsole.getAppName();
38         String JavaDoc image = AdminConsole.getLogoImage();
39         assertEquals("Jive Messenger", name);
40         assertEquals("images/header-title.gif", image);
41     }
42
43     public void testModifyGlobalProps() throws Exception JavaDoc {
44         // Add a new stream to the AdminConsole:
45
String JavaDoc filename = TestUtils.prepareFilename(
46                 "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml");
47         InputStream JavaDoc in = new FileInputStream JavaDoc(filename);
48         AdminConsole.addModel("test1", in);
49         in.close();
50         String JavaDoc name = AdminConsole.getAppName();
51         assertEquals("Foo Bar", name);
52         String JavaDoc img = AdminConsole.getLogoImage();
53         assertEquals("foo.gif", img);
54     }
55
56     public void testNewTabs() throws Exception JavaDoc {
57         // Add a new stream to the AdminConsole:
58
String JavaDoc filename = TestUtils.prepareFilename(
59                 "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml");
60         InputStream JavaDoc in = new FileInputStream JavaDoc(filename);
61         AdminConsole.addModel("test2", in);
62         in.close();
63         Collection JavaDoc tabs = AdminConsole.getModel().selectNodes("//tab");
64         assertNotNull(tabs);
65         assertTrue(tabs.size() > 0);
66         boolean found = false;
67         for (Iterator JavaDoc iter=tabs.iterator(); iter.hasNext(); ) {
68             Element tab = (Element)iter.next();
69             if ("foobar".equals(tab.attributeValue("id"))) {
70                 found = true;
71                 assertEquals("Foo Bar", tab.attributeValue("name"));
72                 assertEquals("Click to see foo bar", tab.attributeValue("description"));
73             }
74         }
75         if (!found) {
76             fail("Expected new item 'foobar' was not found.");
77         }
78     }
79
80     public void testTabOverwrite() throws Exception JavaDoc {
81         // Add a new stream to the AdminConsole:
82
String JavaDoc filename = TestUtils.prepareFilename(
83                 "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml");
84         InputStream JavaDoc in = new FileInputStream JavaDoc(filename);
85         AdminConsole.addModel("test3", in);
86         in.close();
87         boolean found = false;
88         for (Iterator JavaDoc tabs=AdminConsole.getModel().selectNodes("//tab").iterator(); tabs.hasNext(); ) {
89             Element tab = (Element)tabs.next();
90             if ("server".equals(tab.attributeValue("id"))) {
91                 found = true;
92                 assertEquals("New Server Title", tab.attributeValue("name"));
93                 assertEquals("Testing 1 2 3", tab.attributeValue("description"));
94             }
95         }
96         if (!found) {
97             fail("Failed to overwrite 'server' tab with new properties.");
98         }
99     }
100 }
101
Popular Tags