AdminConsoleTest.java 3.49 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
 * Copyright (C) 2004 Jive Software. All rights reserved.
 */

package org.jivesoftware.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Iterator;
import java.lang.reflect.Method;
Bill Lynch's avatar
Bill Lynch committed
16 17
import junit.framework.TestCase;
import org.jivesoftware.admin.AdminConsole;
18
import org.dom4j.Element;
Bill Lynch's avatar
Bill Lynch committed
19 20 21 22 23 24 25 26 27 28 29 30

public class AdminConsoleTest extends TestCase {

    public AdminConsoleTest() {

    }

    /**
     * Resets the admin console internal data structures.
     */
    public void tearDown() throws Exception {
        Class c = AdminConsole.class;
31 32 33
        Method init = c.getDeclaredMethod("init", (Class[])null);
        init.setAccessible(true);
        init.invoke((Object)null, (Object[])null);
Bill Lynch's avatar
Bill Lynch committed
34 35
    }

Bill Lynch's avatar
Bill Lynch committed
36 37 38
    public void testGetGlobalProps() throws Exception {
        String name = AdminConsole.getAppName();
        String image = AdminConsole.getLogoImage();
39
        assertEquals("Wildfire", name);
Bill Lynch's avatar
Bill Lynch committed
40 41 42
        assertEquals("images/header-title.gif", image);
    }

Bill Lynch's avatar
Bill Lynch committed
43 44 45 46 47
    public void testModifyGlobalProps() throws Exception {
        // Add a new stream to the AdminConsole:
        String filename = TestUtils.prepareFilename(
                "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml");
        InputStream in = new FileInputStream(filename);
Matt Tucker's avatar
Matt Tucker committed
48
        AdminConsole.addModel("test1", in);
Bill Lynch's avatar
Bill Lynch committed
49 50 51 52 53 54 55 56 57 58 59 60
        in.close();
        String name = AdminConsole.getAppName();
        assertEquals("Foo Bar", name);
        String img = AdminConsole.getLogoImage();
        assertEquals("foo.gif", img);
    }

    public void testNewTabs() throws Exception {
        // Add a new stream to the AdminConsole:
        String filename = TestUtils.prepareFilename(
                "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml");
        InputStream in = new FileInputStream(filename);
Matt Tucker's avatar
Matt Tucker committed
61
        AdminConsole.addModel("test2", in);
Bill Lynch's avatar
Bill Lynch committed
62
        in.close();
63 64 65
        Collection tabs = AdminConsole.getModel().selectNodes("//tab");
        assertNotNull(tabs);
        assertTrue(tabs.size() > 0);
Bill Lynch's avatar
Bill Lynch committed
66
        boolean found = false;
67 68 69
        for (Iterator iter=tabs.iterator(); iter.hasNext(); ) {
            Element tab = (Element)iter.next();
            if ("foobar".equals(tab.attributeValue("id"))) {
Bill Lynch's avatar
Bill Lynch committed
70
                found = true;
71 72
                assertEquals("Foo Bar", tab.attributeValue("name"));
                assertEquals("Click to see foo bar", tab.attributeValue("description"));
Bill Lynch's avatar
Bill Lynch committed
73 74 75 76 77 78 79 80 81 82
            }
        }
        if (!found) {
            fail("Expected new item 'foobar' was not found.");
        }
    }

    public void testTabOverwrite() throws Exception {
        // Add a new stream to the AdminConsole:
        String filename = TestUtils.prepareFilename(
Bill Lynch's avatar
Bill Lynch committed
83
                "./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml");
Bill Lynch's avatar
Bill Lynch committed
84
        InputStream in = new FileInputStream(filename);
Matt Tucker's avatar
Matt Tucker committed
85
        AdminConsole.addModel("test3", in);
Bill Lynch's avatar
Bill Lynch committed
86 87
        in.close();
        boolean found = false;
88 89 90
        for (Iterator tabs=AdminConsole.getModel().selectNodes("//tab").iterator(); tabs.hasNext(); ) {
            Element tab = (Element)tabs.next();
            if ("server".equals(tab.attributeValue("id"))) {
Bill Lynch's avatar
Bill Lynch committed
91
                found = true;
92 93
                assertEquals("New Server Title", tab.attributeValue("name"));
                assertEquals("Testing 1 2 3", tab.attributeValue("description"));
Bill Lynch's avatar
Bill Lynch committed
94 95 96 97 98 99 100
            }
        }
        if (!found) {
            fail("Failed to overwrite 'server' tab with new properties.");
        }
    }
}