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

package org.jivesoftware.util;

import java.io.InputStream;
12
import java.lang.reflect.Method;
Bill Lynch's avatar
Bill Lynch committed
13
import java.util.Collection;
14

15
import org.dom4j.Element;
16
import org.jivesoftware.admin.AdminConsole;
17
import org.junit.After;
18
import org.junit.Ignore;
19
import org.junit.Test;
Bill Lynch's avatar
Bill Lynch committed
20

21
import static org.junit.Assert.*;
Bill Lynch's avatar
Bill Lynch committed
22

23
public class AdminConsoleTest {
Bill Lynch's avatar
Bill Lynch committed
24 25 26 27

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

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

45
    @Test
Bill Lynch's avatar
Bill Lynch committed
46 47
    public void testModifyGlobalProps() throws Exception {
        // Add a new stream to the AdminConsole:
48 49 50
        try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml")) {
            AdminConsole.addModel("test1", in);
        }
Bill Lynch's avatar
Bill Lynch committed
51 52 53 54 55 56
        String name = AdminConsole.getAppName();
        assertEquals("Foo Bar", name);
        String img = AdminConsole.getLogoImage();
        assertEquals("foo.gif", img);
    }

57
    @Test
Bill Lynch's avatar
Bill Lynch committed
58 59
    public void testNewTabs() throws Exception {
        // Add a new stream to the AdminConsole:
60 61 62
        try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml")) {
            AdminConsole.addModel("test2", in);
        }
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
        for (Object tab1 : tabs) {
            Element tab = (Element) tab1;
69
            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
            }
        }
        if (!found) {
            fail("Expected new item 'foobar' was not found.");
        }
    }

80
    @Test
Bill Lynch's avatar
Bill Lynch committed
81 82
    public void testTabOverwrite() throws Exception {
        // Add a new stream to the AdminConsole:
83 84 85
        try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml")) {
            AdminConsole.addModel("test3", in);
        }
Bill Lynch's avatar
Bill Lynch committed
86
        boolean found = false;
87 88
        for (Object o : AdminConsole.getModel().selectNodes("//tab")) {
            Element tab = (Element) o;
89
            if ("server".equals(tab.attributeValue("id"))) {
Bill Lynch's avatar
Bill Lynch committed
90
                found = true;
91 92
                assertEquals("New Server Title", tab.attributeValue("name"));
                assertEquals("Testing 1 2 3", tab.attributeValue("description"));
Bill Lynch's avatar
Bill Lynch committed
93 94 95 96 97 98 99
            }
        }
        if (!found) {
            fail("Failed to overwrite 'server' tab with new properties.");
        }
    }
}