1 8 9 package org.jivesoftware.util; 10 11 import java.io.FileInputStream ; 12 import java.io.InputStream ; 13 import java.util.Collection ; 14 import java.util.Iterator ; 15 import java.lang.reflect.Method ; 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 29 public void tearDown() throws Exception { 30 Class c = AdminConsole.class; 31 Method init = c.getDeclaredMethod("init", (Class [])null); 32 init.setAccessible(true); 33 init.invoke((Object )null, (Object [])null); 34 } 35 36 public void testGetGlobalProps() throws Exception { 37 String name = AdminConsole.getAppName(); 38 String image = AdminConsole.getLogoImage(); 39 assertEquals("Jive Messenger", name); 40 assertEquals("images/header-title.gif", image); 41 } 42 43 public void testModifyGlobalProps() throws Exception { 44 String filename = TestUtils.prepareFilename( 46 "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml"); 47 InputStream in = new FileInputStream (filename); 48 AdminConsole.addModel("test1", in); 49 in.close(); 50 String name = AdminConsole.getAppName(); 51 assertEquals("Foo Bar", name); 52 String img = AdminConsole.getLogoImage(); 53 assertEquals("foo.gif", img); 54 } 55 56 public void testNewTabs() throws Exception { 57 String filename = TestUtils.prepareFilename( 59 "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml"); 60 InputStream in = new FileInputStream (filename); 61 AdminConsole.addModel("test2", in); 62 in.close(); 63 Collection tabs = AdminConsole.getModel().selectNodes("//tab"); 64 assertNotNull(tabs); 65 assertTrue(tabs.size() > 0); 66 boolean found = false; 67 for (Iterator 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 { 81 String filename = TestUtils.prepareFilename( 83 "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml"); 84 InputStream in = new FileInputStream (filename); 85 AdminConsole.addModel("test3", in); 86 in.close(); 87 boolean found = false; 88 for (Iterator 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 |