⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewgeneratortest.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.unittests.service.services.views;

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.service.services.views.TreeNode;
import opiam.admin.faare.service.services.views.ViewGenerator;
import opiam.admin.faare.unittests.TestResult;
import opiam.admin.faare.unittests.TestUtils;
import opiam.admin.faare.unittests.javabeans.SiteTest;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.log4j.Logger;

import java.io.ByteArrayOutputStream;

import java.util.Hashtable;
import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;


/**
 * Test of the ViewGenerator service.
 */
public class ViewGeneratorTest extends TestCase
{
    /** Test user DN. */
    private static final String DN_USER = "uid=jreuter, ou=People, dc=mycompany,dc=com";

    /** Test user login. */
    private static final String LOGIN_USER = "jreuter"; //uid

    /** Test user password. */
    private static final String PASSWORD_USER = "destroy";

    /** User context. */
    private static UserContext _USERCONTEXT = new UserContext();

    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(ViewGeneratorTest.class);

    /** Instance of the trace class. */
    private static TestUtils _test = new TestUtils(_logger);

    /** Identifier of the treeview. */
    private static final String TREEVIEW_ID_NAME = "treeview_id";

    /** Name of the treeview hashtable representation. */
    private static final String TREEVIEW_HASHTABLE_NAME = "treeview_hashtable";

    /** Name of the orgchart hashtable representation. */
    private static final String ORGCHART_HASHTABLE_NAME = "orgchart_hashtable";

    /** Identifier of the orgchart. */
    private static final String ORGCHART_ID_NAME = "orgchart_id";

    /** Number of views defined in the views.xml file. */
    private static final int VIEWS_NUMBER = 5;

    /** DN of the site type entry. */
    private static final String DN_SITE = "l=Santa Clara,ou=Sites,dc=mycompany,dc=com";

    /** Name of a view defined in the views.xml file. */
    private static final String VIEW_NAME = "Vue Logique";

    /** Horizontal direction. */
    private static final String HORIZONTAL_DIRECTION = "1";

    /** Vertical direction. */
    private static final String VERTICAL_DIRECTION = "2";

    /** File tree direction. */
    private static final String FILETREE_DIRECTION = "3";

    /** Mode fo orgchart. */
    private static final String ORGCHART_MODE = "1";

    /** JPG image type. */
    private static final String JPG_IMAGE_TYPE = "jpg";

    /** GIF image type. */
    private static final String GIF_IMAGE_TYPE = "gif";

    /** PNG image type. */
    private static final String PNG_IMAGE_TYPE = "png";

    /** Vertical image prefix. */
    private static final String PREF_IMAGE_V = "Vertical_";

    /** Horizontal image prefix. */
    private static final String PREF_IMAGE_H = "Horizontal_";

    /** Image file name. */
    private static final String IMAGE_NAME = "orgchart.";

    /** Image file path. */
    private static final String IMAGE_PATH = "opiam.admin/faare/unittests/data/";

    /** PDF file name. */
    private static final String PDF_NAME = "orgchart.pdf";

    /** PDF file path. */
    private static final String PDF_PATH = "opiam.admin/faare/unittests/data/";

    /**
     * Creates a new ViewGenerator object.
     *
     * @param param  Parameter.
     */
    public ViewGeneratorTest(String param)
    {
        super(param);

        try
        {
            PropertiesManager.getInstance();

            if (!_USERCONTEXT.isLoggedIn())
            {
                StandardService.logon(LOGIN_USER, PASSWORD_USER, _USERCONTEXT);
            }
        }
        catch (Exception e)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("ViewGeneratorTest constructor error");
            msg.append(TestUtils.NEXT);
            msg.append(e.toString());
            _test.displayResultError(msg.toString());
        }
    }

    /**
     * Method of the tests suite.
     *
     * @return Tests result.
     */
    public static Test suite()
    {
        TestSuite suite = new TestSuite();

        suite.addTest(new ViewGeneratorTest("testBegin"));

        // TESTS SET
        suite.addTest(new ViewGeneratorTest("testGetViewNamesList"));
        suite.addTest(new ViewGeneratorTest("testGenerateTreeView"));
        suite.addTest(new ViewGeneratorTest("testGenerateOrgChart"));
        suite.addTest(new ViewGeneratorTest("testGenerateOrgChartAsGif"));
        suite.addTest(new ViewGeneratorTest("testGenerateOrgChartAsJpgOrPng"));
        suite.addTest(new ViewGeneratorTest("testGetTextOrgChart"));
        suite.addTest(new ViewGeneratorTest("testEnd"));

        return (suite);
    }

    /**
     * Main method of the test class.
     *
     * @param args  Sets of the parameters.
     */
    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

    /**
     * Method to indicate the beginning of the class test.
     *
     */
    public static void testBegin()
    {
        //  To initialize the tests statement
        TestResult.getInstance().setInitiator("ViewGeneratorTest");

        _test.displayHeaderClass("ViewGeneratorTest");
        assertTrue(true);
    }

    /**
     * Method to indicate the end of the class test.
     *
     */
    public static void testEnd()
    {
        _test.displayFooterClass(null);
        assertTrue(true);

        // To display the tests statement
        _test.displayTestStatement("ViewGeneratorTest");
    }

    /**
     * Test the getViewNamesList method.
     *
     */
    public static void testGetViewNamesList()
    {
        _test.displayHeaderMethod("GetViewNamesList");

        try
        {
            List viewsList = ViewGenerator.getViewNamesList();

            if (viewsList != null)
            {
                if (viewsList.size() == VIEWS_NUMBER)
                {
                    _test.displayResultSuccess(null);
                }
                else
                {
                    _test.displayResultFailure("the list size is " +
                        viewsList.size());
                }
            }
            else
            {
                _test.displayResultFailure(
                    "the list of the views names is null");
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("GetViewNamesList");
    }

    /**
     * Test the generateTreeView methods.
     *
     */
    public void testGenerateTreeView()
    {
        _test.displayHeaderMethod("testGenerateTreeView");

        try
        {
            _test.displayMsg(TestUtils.NEXT + "Parameters = List, usercontext");

            try
            {
                List viewsList = ViewGenerator.getViewNamesList();

                if ((viewsList != null) && (viewsList.size() > 0))
                {
                    TreeNode treeNode = ViewGenerator.generateTreeView(viewsList,
                            _USERCONTEXT);

                    if (treeNode != null)
                    {
                        Integer generatedId = (Integer) _USERCONTEXT.getParameters()
                                                                     .get(TREEVIEW_ID_NAME);

                        if (generatedId != null)
                        {
                            Hashtable hnodes = (Hashtable) _USERCONTEXT.getParameters()
                                                                       .get(TREEVIEW_HASHTABLE_NAME);

                            if ((hnodes != null) && (hnodes.size() > 0))
                            {
                                _test.displayResultSuccess(null);
                            }
                            else
                            {
                                _test.displayResultFailure(TREEVIEW_HASHTABLE_NAME +
                                    " is null or empty");
                            }
                        }
                        else
                        {
                            _test.displayResultFailure(TREEVIEW_ID_NAME + " " +
                                generatedId);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -