/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2005 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or 1any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jonasadmin.test.resource;

import java.util.Properties;

import junit.framework.TestSuite;

import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;

import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.SubmitButton;
import com.meterware.httpunit.TableCell;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;

/**
 * Class for testing Resource
 * @author Paul Kemler
 *
 */
public class F_JonasAdminResourceMail extends JonasAdminTestCase {

    /**
     * URL of mail service
     */
    private static final String URL_JONASADMIN_MAIL_SERVICE = "EditMailService.do";

    /**
     * URL of Mail resource
     */
    private static final String URL_JONASADMIN_MAIL = "EditDeploy.do?type=mail";

    /**
     * URL of list mail factories
     */
    private static final String URL_JONASADMIN_LIST_MAIL_FACTORIES = "ListMailFactories.do";

    /**
     * URL of deploy
     */
    private static final String URL_JONASADMIN_DEPLOY = "EditDeploy.do";

    /**
     * URL of create mail factory
     */
    private static final String URL_JONASADMIN_CREATE_MAIL_FACTORY = "EditMailFactoryProperties.do?action=create";

    /**
     * URL of Mail resource viewTree
     */
    private static final String URL_JONASADMIN_VIEW_MAIL = "viewTree.do?tree=domain*jonas*resources";

    /**
     * number of tabs when you are in the mail tabs
     */
    private static final int NUMBER_OF_TABS_FOR_MAIL = 2;

    /**
     * number of tabs when you are in the CONFIRM tabs
     */
    private static final int NUMBER_OF_TABS_FOR_CONFIRM = 2;

    /**
     * number of tabs when you are in the 'new mail factory' tabs
     */
    private static final int NUMBER_OF_TABS_FOR_NEW_MAIL_FACTORY = 3;

    /**
     * name of the mail factory
     */
    private String name = "";

    /**
     * Constructor with a specified name
     * @param s name
     */
    public F_JonasAdminResourceMail(String s) {
        super(s, URL_JONASADMIN);
    }

    /**
     * Main method
     * @param args the arguments
     */
    public static void main(String[] args) {

        String testtorun = null;
        // Get args
        for (int argn = 0; argn < args.length; argn++) {
            String sArg = args[argn];
            if (sArg.equals("-n")) {
                testtorun = args[++argn];
            }
        }
        if (testtorun == null) {
            junit.textui.TestRunner.run(suite());
        } else {
            junit.textui.TestRunner.run(new F_JonasAdminResourceMail(testtorun));
        }
    }

    /**
     * Get a new TestSuite for this class
     * @return a new TestSuite for this class
     */
    public static TestSuite suite() {
        return new TestSuite(F_JonasAdminResourceMail.class);
    }

    /**
     * Setup need for these tests
     * jonasAdmin is required
     * @throws Exception if it fails
     */
    protected void setUp() throws Exception {
        super.setUp();

        if (wc.getCurrentPage().getURL() == null) {
            useWar("jonasAdmin");
            // login to jonas admin
            try {
                JonasAdminAuth.doValidAuth(wc, url);
            } catch (Exception e) {
                fail("authentification failed :  " + e);
            }
        } else {
            // if there was an error, the connection must be restablished
            try {
                wc.getFrameContents(FRAME_TREE);
            } catch (Exception e) {
                wc.getResponse(urlLogOut);
                // login to jonas admin
                try {
                    JonasAdminAuth.doValidAuth(wc, url);
                } catch (Exception auth) {
                    fail("authentification failed :  " + auth);
                }
            }
        }
    }

    /**
     * Test to deploy and undeploy a mail factory
     * @throws Exception if error occurs
     */
    public void testUndeployDeployMailFactory() throws Exception {

        WebResponse wr;
        WebLink link;
        WebTable table;
        WebTable tabTable;
        int selectedTab;
        /*
         * To get some utils for WebTable
         */
        JonasAdminUtils utils = new JonasAdminUtils();

        // Disable errors of javascript
        HttpUnitOptions.setExceptionsThrownOnScriptError(false);
        // Disable exception thrown on error status
        HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);

        if (jProp.isMail()) {
            // Add mail factory
            name = "new_mailFactory";
            Properties properties = new Properties();
            // mail.authentication.password=
            properties.put("mail.authentication.password", "");
            // mail.factory.type=javax.mail.Session
            properties.put("mail.factory.type", "javax.mail.Session");
            // mail.authentication.username=
            properties.put("mail.authentication.username", "");
            // mail.host=
            properties.put("mail.host", "");
            // mail.factory.name=   name
            properties.put("mail.factory.name", name);

            // Add a mail factory
            if (isInMailFactoryList(name)) {

                // remove mail factory
                unBindMailFactory(name);
            }
            createMailFactory(name, properties);

            // Go to Mail
            wr = wc.getFrameContents(FRAME_TREE);
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_MAIL);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 1;

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab, "Problem in 'Deployment' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES + " is not found in the second tab. ", tabTable
                    .getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));

            String txt = getDeployTable(wr, true);

            if (txt.indexOf(name) == -1) {
                fail("The file" + name + " was not found as deployed.");
            }

            // Undeploy mail factory
            WebForm[] webForms = wr.getForms();
            WebForm webForm = webForms[0];

            String params = webForm.getParameterValue("undeploy");
            WebForm.Scriptable script = webForm.getScriptableObject();
            if (params.length() == 0) {
                params += name;
            } else {
                params += "," + name;
            }
            script.setParameterValue("undeploy", params);

            SubmitButton button = webForm.getSubmitButtons()[0];
            button.click();

            // Confirm
            WebResponse submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 2;

            // Verify tabs
            tabTable = utils.getTabTable(submitUndeploy);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab, "Problem in 'Confirm' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_DEPLOY + " is not found in the first tab. ", tabTable.getTableCell(
                    0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPLOY));
            webForms = submitUndeploy.getForms();
            webForm = webForms[0];

            button = webForm.getSubmitButtons()[0];
            button.click();
            wr = wc.getFrameContents(FRAME_CONTENT);

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_CONFIRM, selectedTab, "Problem in 'Result' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_DEPLOY + " is not found in the first tab. ", tabTable.getTableCell(
                    0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPLOY));

            // Go back to Deployment
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_DEPLOY);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 1;

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab, "Problem in 'Deployment' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES + " is not found in the second tab. ", tabTable
                    .getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));

            txt = getDeployTable(wr, true);

            if (txt.indexOf(name) != -1) {
                fail("The jonasAdmin webApp has not removed " + name);
            }

            // now deploy
            webForms = wr.getForms();
            webForm = webForms[0];

            params = webForm.getParameterValue("deploy");
            script = webForm.getScriptableObject();

            if (params.length() == 0) {
                params += name;
            } else {
                params += "," + name;
            }

            script.setParameterValue("deploy", params);
            button = webForm.getSubmitButtons()[0];
            button.click();

            // Confirm
            submitUndeploy = wc.getFrameContents(FRAME_CONTENT);
            // war is in the table
            webForms = submitUndeploy.getForms();
            webForm = webForms[0];

            button = webForm.getSubmitButtons()[0];
            button.click();

            // Go back to Deployment
            wr = wc.getFrameContents(FRAME_CONTENT);
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_DEPLOY);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);

            txt = getDeployTable(wr, true);

            if (txt.indexOf(name) == -1) {
                fail("The file " + name + " was not found as deployed.");
            }
        }
    }

    /**
     * Test to create a new mail factory
     * @throws Exception if error occurs
     */
    public void testCreateNewSessionMailFactory() throws Exception {

        WebResponse wr;
        WebLink link;
        WebTable table;
        WebTable tabTable;
        int selectedTab;
        // Name of the mail factory
        name = "new_mailFactory_";
        String username = "";
        String password = "";
        String sessionProps = "";
        String to = "";
        String subject = "";
        String cc = "";
        String bcc = "";

        /*
         * To get some utils for WebTable
         */
        JonasAdminUtils utils = new JonasAdminUtils();

        // Disable errors of javascript
        HttpUnitOptions.setExceptionsThrownOnScriptError(false);
        // Disable exception thrown on error status
        HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);

        if (jProp.isMail()) {

            // Go to mail
            wr = wc.getFrameContents(FRAME_TREE);
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_MAIL);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 1;

            // Go to mail factories
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_LIST_MAIL_FACTORIES);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 2;

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab, "Problem in 'Mail Factories' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_DEPLOY + " is not found in the first tab. ", tabTable.getTableCell(
                    0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPLOY));

            // Find a new name
            boolean found = false;
            int i = 0;
            while (!found) {
                if ((wr.getText().indexOf(name + i) == -1)) {
                    name = name + i;
                    found = true;
                }
                i++;
            }

            // Create a new Session Mail Factory
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_CREATE_MAIL_FACTORY);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 3;

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_NEW_MAIL_FACTORY, selectedTab, "Problem in 'New mail factory' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_DEPLOY + " is not found in the first tab. ", tabTable.getTableCell(
                    0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPLOY));
            assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES + " is not found in the third tab. ", tabTable
                    .getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));

            WebForm form = wr.getForms()[0];

            createSessionFactory(form, name, name, username, password, sessionProps, to, subject, cc, bcc);

            wr = wc.getFrameContents(FRAME_CONTENT);

            // Verify if the mail factory is deployed
            assertTrue("The created mail factory ('" + name + "') is not deployed. Restart jonas and try again. ", isInMailFactoryList(name));
            table = utils.getTable(wr, 3);
            int mailFactoryRow = utils.getRow(name, table, 1).intValue();
            if (mailFactoryRow == -1) {
                fail("The mail factory '" + name + "' is not found in mail factory table. Restart jonas and try again. ");
            } else {
                // Verify if there is an image to indicate that the mail factory is deployed
                TableCell cell = table.getTableCell(mailFactoryRow, 0);
                assertEquals("There is no a image to indicate that '" + name + "' mail factory is deployed. ", 1, cell.getImages().length);
            }
        }
    }

    /**
     * Test to create a new MimePartDatasource mail factory
     * @throws Exception if error occurs
     */
    public void testCreateNewMimePartDSMailFactory() throws Exception {

        WebResponse wr;
        WebLink link;
        WebTable table;
        WebTable tabTable;
        int selectedTab;
        // Name of the mail factory
        name = "new_mimePartDS_mailFactory_";
        String username = "";
        String password = "";
        String sessionProps = "";
        String to = "";
        String subject = "";
        String cc = "";
        String bcc = "";

        /*
         * To get some utils for WebTable
         */
        JonasAdminUtils utils = new JonasAdminUtils();

        // Disable errors of javascript
        HttpUnitOptions.setExceptionsThrownOnScriptError(false);
        // Disable exception thrown on error status
        HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);

        if (jProp.isMail()) {

            // Go to mail
            wr = wc.getFrameContents(FRAME_TREE);
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_MAIL);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 1;

            // Go to mail factories
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_LIST_MAIL_FACTORIES);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 2;

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_MAIL, selectedTab, "Problem in 'Mail Factories' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_DEPLOY + " is not found in the first tab. ", tabTable.getTableCell(
                    0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPLOY));

            // Find a new name
            boolean found = false;
            int i = 0;
            while (!found) {
                if ((wr.getText().indexOf(name + i) == -1)) {
                    name = name + i;
                    found = true;
                }
                i++;
            }

            // Create a new MimePartDataSource Mail Factory
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_CREATE_MAIL_FACTORY);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 3;

            // Verify tabs
            tabTable = utils.getTabTable(wr);
            testTabs(tabTable, NUMBER_OF_TABS_FOR_NEW_MAIL_FACTORY, selectedTab, "Problem in 'New mail factory' tab.");
            // - links
            assertTrue("The link " + URL_JONASADMIN_DEPLOY + " is not found in the first tab. ", tabTable.getTableCell(
                    0, 0).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_DEPLOY));
            assertTrue("The link " + URL_JONASADMIN_LIST_MAIL_FACTORIES + " is not found in the third tab. ", tabTable
                    .getTableCell(0, 2).getLinks()[0].getURLString().endsWith(URL_JONASADMIN_LIST_MAIL_FACTORIES));

            WebForm form = wr.getForms()[0];

            createMimePartDataSourceFactory(form, name, name, username, password, sessionProps, to, subject, cc, bcc);

            wr = wc.getFrameContents(FRAME_CONTENT);

            // Verify if the mail factory is deployed
            assertTrue("The created mail factory ('" + name + "') is not deployed. Restart jonas and try again. ", isInMailFactoryList(name));
            table = utils.getTable(wr, 3);
            int mailFactoryRow = utils.getRow(name, table, 1).intValue();
            if (mailFactoryRow == -1) {
                fail("The mail factory '" + name + "' is not found in mail factory table. Restart jonas and try again. ");
            } else {
                // Verify if there is an image to indicate that the mail factory is deployed
                TableCell cell = table.getTableCell(mailFactoryRow, 0);
                assertEquals("There is no a image to indicate that '" + name + "' mail factory is deployed. ", 1, cell.getImages().length);
            }
        }
    }

    /**
     * Test to view empty value error message
     * @throws Exception if error occurs
     */
    public void testCreateMailFactoryWithEmptyValue() throws Exception {

        WebResponse wr;
        WebLink link;
        WebTable table;
        WebTable tabTable;
        int selectedTab;

        /*
         * To get some utils for WebTable
         */
        JonasAdminUtils utils = new JonasAdminUtils();

        // Disable errors of javascript
        HttpUnitOptions.setExceptionsThrownOnScriptError(false);
        // Disable exception thrown on error status
        HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);

        if (jProp.isMail()) {
            // Go to mail
            wr = wc.getFrameContents(FRAME_TREE);
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_MAIL);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 1;

            // Go to mail factories
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_LIST_MAIL_FACTORIES);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 2;

            // Create a new mail factory
            link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_CREATE_MAIL_FACTORY);
            link.click();
            wr = wc.getFrameContents(FRAME_CONTENT);
            selectedTab = 3;

            WebForm form = wr.getForms()[0];
            createNewEmptyMailFactory(form);
            wr = wc.getFrameContents(FRAME_CONTENT);

            // Verify error messages
            table = utils.getTable(wr, 0);
            TableCell cell = table.getTableCell(0, 0);

            // class        errors
            assertEquals("The value  of the class attribut of the cell is not 'errors'. ", "errors", cell.getAttribute("class"));
            // Can't accept empty Jndi name
            String emptyJndiName = "Can't accept empty Jndi name";
            assertTrue("The message '" + emptyJndiName + "' is not found. ", cell.getText().indexOf(emptyJndiName) != -1);
            // Can't accept empty factory name
            String emptyFactoryName = "Can't accept empty factory name";
            assertTrue("The message '" + emptyFactoryName + "' is not found. ", cell.getText().indexOf(emptyFactoryName) != -1);
            // Please check in the type
            String emptyType = "Can't accept empty factory name";
            assertTrue("The message '" + emptyType + "' is not found. ", cell.getText().indexOf(emptyType) != -1);
        }

    }

    /**
     * Tear Down
     * cleanUp action
     */
    public void tearDown() throws Exception {
        if (jProp.isMail()) {// remove created mail factory file
            if (!name.equals("")) {
                if (isInMailFactoryList(name)) {
                    // remove mail factory
                    unBindMailFactory(name);
                    // Delete file
                    JonasAdminFiles.deleteConfigFile(name + ".properties");
                    name = "";
                }
            }
        }
        super.tearDown();
    }

    /**
     * Create a new session Mail Factory
     * @param form the form
     * @param mailFactoryName the name
     * @param type "Session" or "MimePartDataSource"
     * @param jndiName the Jndi name
     * @param username username
     * @param password password
     * @param sessionProps Mail session configuration
     * @param to MimePartDataSource configuration
     * @param subject MimePartDataSource configuration
     * @param cc MimePartDataSource configuration
     * @param bcc MimePartDataSource configuration
     * @throws Exception if an error occurs
     */
    private void createSessionFactory(WebForm form, String mailFactoryName, String jndiName,
            String username, String password, String sessionProps, String to, String subject, String cc, String bcc)
            throws Exception {

        form.setParameter("mailFactoryName", mailFactoryName);
        form.setParameter("type", "javax.mail.Session");
        form.setParameter("jndiName", jndiName);
        form.setParameter("username", username);
        form.setParameter("password", password);
        form.setParameter("sessionProps", sessionProps);
        form.setParameter("to", to);
        form.setParameter("subject", subject);
        form.setParameter("cc", cc);
        form.setParameter("bcc", bcc);

        SubmitButton button = form.getSubmitButtons()[0];
        button.click();
    }

    /**
     * Create a new session Mail Factory
     * @param form the form
     * @param mailFactoryName the name
     * @param type "Session" or "MimePartDataSource"
     * @param jndiName the Jndi name
     * @param username username
     * @param password password
     * @param sessionProps Mail session configuration
     * @param to MimePartDataSource configuration
     * @param subject MimePartDataSource configuration
     * @param cc MimePartDataSource configuration
     * @param bcc MimePartDataSource configuration
     * @throws Exception if an error occurs
     */
    private void createMimePartDataSourceFactory(WebForm form, String mailFactoryName, String jndiName,
            String username, String password, String sessionProps, String to, String subject, String cc, String bcc)
            throws Exception {

        form.setParameter("mailFactoryName", mailFactoryName);
        form.setParameter("type", "javax.mail.internet.MimePartDataSource");
        form.setParameter("jndiName", jndiName);
        form.setParameter("username", username);
        form.setParameter("password", password);
        form.setParameter("sessionProps", sessionProps);
        form.setParameter("to", to);
        form.setParameter("subject", subject);
        form.setParameter("cc", cc);
        form.setParameter("bcc", bcc);

        SubmitButton button = form.getSubmitButtons()[0];
        button.click();
    }

    /**
     * Create an empty Mail Factory
     * @param form the form
     * @throws Exception if an error occurs
     */
    private void createNewEmptyMailFactory(WebForm form)
            throws Exception {

        form.setParameter("mailFactoryName", "");
        form.setParameter("jndiName", "");
        form.setParameter("username", "");
        form.setParameter("password", "");
        form.setParameter("sessionProps", "");
        form.setParameter("to", "");
        form.setParameter("subject", "");
        form.setParameter("cc", "");
        form.setParameter("bcc", "");

        SubmitButton button = form.getSubmitButtons()[0];
        button.click();
    }


    /**
     * Return the text of the deployed table or the deployable table
     * @param wr the WebResponse to use
     * @param deployed if true return the text deployed table, if false text of
     *        deployable
     * @return the text of the deployed table or the deployable table
     * @throws Exception if an error occurs
     */
    private String getDeployTable(WebResponse wr, boolean deployed) throws Exception {

        // Extract right table
        JonasAdminUtils utils = new JonasAdminUtils();
        WebTable table = utils.getTable(wr, 0);

        TableCell deployableCell = table.getTableCell(1, 0);
        TableCell deployedCell = table.getTableCell(1, 2);

        if (deployed) {
            return deployedCell.getText();
        } else {
            return deployableCell.getText();
        }
    }

}
