001: /**
002: * $RCSfile$
003: * $Revision: 7655 $
004: * $Date: 2007-03-22 13:50:33 -0700 (Thu, 22 Mar 2007) $
005: *
006: * Copyright (C) 2004 Jive Software. All rights reserved.
007: */package org.jivesoftware.util;
008:
009: import java.io.FileInputStream;
010: import java.io.InputStream;
011: import java.util.Collection;
012: import java.util.Iterator;
013: import java.lang.reflect.Method;
014: import junit.framework.TestCase;
015: import org.jivesoftware.admin.AdminConsole;
016: import org.dom4j.Element;
017:
018: public class AdminConsoleTest extends TestCase {
019:
020: public AdminConsoleTest() {
021:
022: }
023:
024: /**
025: * Resets the admin console internal data structures.
026: */
027: public void tearDown() throws Exception {
028: Class c = AdminConsole.class;
029: Method init = c.getDeclaredMethod("init", (Class[]) null);
030: init.setAccessible(true);
031: init.invoke((Object) null, (Object[]) null);
032: }
033:
034: public void testGetGlobalProps() throws Exception {
035: String name = AdminConsole.getAppName();
036: String image = AdminConsole.getLogoImage();
037: assertEquals("Openfire", name);
038: assertEquals("images/header-title.gif", image);
039: }
040:
041: public void testModifyGlobalProps() throws Exception {
042: // Add a new stream to the AdminConsole:
043: String filename = TestUtils
044: .prepareFilename("./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml");
045: InputStream in = new FileInputStream(filename);
046: AdminConsole.addModel("test1", in);
047: in.close();
048: String name = AdminConsole.getAppName();
049: assertEquals("Foo Bar", name);
050: String img = AdminConsole.getLogoImage();
051: assertEquals("foo.gif", img);
052: }
053:
054: public void testNewTabs() throws Exception {
055: // Add a new stream to the AdminConsole:
056: String filename = TestUtils
057: .prepareFilename("./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml");
058: InputStream in = new FileInputStream(filename);
059: AdminConsole.addModel("test2", in);
060: in.close();
061: Collection tabs = AdminConsole.getModel().selectNodes("//tab");
062: assertNotNull(tabs);
063: assertTrue(tabs.size() > 0);
064: boolean found = false;
065: for (Iterator iter = tabs.iterator(); iter.hasNext();) {
066: Element tab = (Element) iter.next();
067: if ("foobar".equals(tab.attributeValue("id"))) {
068: found = true;
069: assertEquals("Foo Bar", tab.attributeValue("name"));
070: assertEquals("Click to see foo bar", tab
071: .attributeValue("description"));
072: }
073: }
074: if (!found) {
075: fail("Expected new item 'foobar' was not found.");
076: }
077: }
078:
079: public void testTabOverwrite() throws Exception {
080: // Add a new stream to the AdminConsole:
081: String filename = TestUtils
082: .prepareFilename("./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml");
083: InputStream in = new FileInputStream(filename);
084: AdminConsole.addModel("test3", in);
085: in.close();
086: boolean found = false;
087: for (Iterator tabs = AdminConsole.getModel().selectNodes(
088: "//tab").iterator(); tabs.hasNext();) {
089: Element tab = (Element) tabs.next();
090: if ("server".equals(tab.attributeValue("id"))) {
091: found = true;
092: assertEquals("New Server Title", tab
093: .attributeValue("name"));
094: assertEquals("Testing 1 2 3", tab
095: .attributeValue("description"));
096: }
097: }
098: if (!found) {
099: fail("Failed to overwrite 'server' tab with new properties.");
100: }
101: }
102: }
|