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

📄 standardservicetest.java

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

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

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.SearchResult;
import opiam.admin.faare.config.javabeans.JBLdapConfig;
import opiam.admin.faare.exception.InsufficientAccessRights;
import opiam.admin.faare.exception.ServiceException;
import opiam.admin.faare.persistence.javabeans.JBTop;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.javabeans.Criteria;
import opiam.admin.faare.service.javabeans.SearchArgument;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.unittests.TestResult;
import opiam.admin.faare.unittests.TestUtils;
import opiam.admin.faare.unittests.javabeans.PersonTest;

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

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;


/**
 * Test of the StandardService methods.
 *
 */
public class StandardServiceTest extends TestCase
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(StandardServiceTest.class);

    // USER WITHOUT ANY ACCESS (FAARE / OPENLDAP)

    /** Test user DN. */
//DW/2662/BeginPatch
    private static final String DN_USERWA = "uid=jwalker,ou=people,dc=mycompany,dc=com";

    /** Test user DN, with modified RDN. */
    private static final String DN_USERWA_M = "uid=Arthur2,ou=people,dc=mycompany,dc=com";

    /** Test user login. */
    private static final String LOGIN_USERWA = "jwalker"; //uid

    /** Test user password. */
    private static final String PASSWORD_USERWA = "dogleg";
//DW/2662/EndPatch

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

    // USER WITH ACCESS BY FAARE AND WITH ONLY READ ACCESS BY OPENLDAP

    /** 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();

    // USER WITH ALL ACCESS (FAARE / OPENLDAP)

    /** Test administrator DN. */
    private static final String DN_ADMIN = "uid=hmiller,ou=people,dc=mycompany,dc=com";

    /** Test administrator login. */
    private static final String LOGIN_ADMIN = "hmiller";

    /** Test administrator password. */
    private static final String PASSWORD_ADMIN = "hillock";

    /** Admin context. */
    private static UserContext _ADMINCONTEXT = new UserContext();

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

    /** Entry for lazyloading tests. */
    private static final String DN_LAZY = "uid=ythestay,ou=people,dc=mycompany,dc=com";

    /** Reference image name. */
    private static final String IMAGE_NAME = "ythestay.jpg";

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

    /** GivenName field as defined in faare_mapping. */
    private static final String GIVENNAME_ATTRIBUTE = "prenom";

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

        try
        {
            PropertiesManager.getInstance();

            if ((param == null) || (param.indexOf("testLogon") == -1))
            {
                // Loads the different users accounts
                if (!_USERCONTEXTWA.isLoggedIn())
                {
                    StandardService.logon(LOGIN_USERWA, PASSWORD_USERWA,
                        _USERCONTEXTWA);
                }

                if (!_USERCONTEXT.isLoggedIn())
                {
                    StandardService.logon(LOGIN_USER, PASSWORD_USER,
                        _USERCONTEXT);
                }

                if (!_ADMINCONTEXT.isLoggedIn())
                {
                    StandardService.logon(LOGIN_ADMIN, PASSWORD_ADMIN,
                        _ADMINCONTEXT);
                }
            }
        }
        catch (Exception e)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("StandardServiceTest 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 StandardServiceTest("testBegin"));

        // LOGON
        suite.addTest(new StandardServiceTest("testLogon"));
        suite.addTest(new StandardServiceTest("testLogonNullParameters"));
        suite.addTest(new StandardServiceTest("testLogonEmptyParameters"));
        suite.addTest(new StandardServiceTest("testLogonIncorrectParameters"));

        suite.addTest(new StandardServiceTest(
              "testLogonLdapConfigNullParameters"));
        suite.addTest(new StandardServiceTest(
              "testLogonLdapConfigEmptyParameters"));
        suite.addTest(new StandardServiceTest(
              "testLogonLdapConfigIncorrectParameters"));
        suite.addTest(new StandardServiceTest("testLogonLdapConfig"));

        // LOAD
        suite.addTest(new StandardServiceTest("testLoad"));
        suite.addTest(new StandardServiceTest("testLoadNullParameter"));
        suite.addTest(new StandardServiceTest("testLoadEmptyParameter"));
        suite.addTest(new StandardServiceTest("testLoadIncorrectParameter"));
        suite.addTest(new StandardServiceTest("testLoadInsufficientRight"));
        suite.addTest(new StandardServiceTest("testLoadLazyLoading"));

        // SEARCH
        suite.addTest(new StandardServiceTest("testSearch"));
        suite.addTest(new StandardServiceTest("testSortSearch"));

        // CREATE
        suite.addTest(new StandardServiceTest("testCreate"));

        // MODIFY
        suite.addTest(new StandardServiceTest("testModify"));
        suite.addTest(new StandardServiceTest("testModifyAttribute"));

        // DELETE
        suite.addTest(new StandardServiceTest("testDelete"));

        suite.addTest(new StandardServiceTest("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("StandardServiceTest");

        _test.displayHeaderClass("StandardServiceTest");
        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("StandardServiceTest");
    }

    /**
     * Tests the logon with null parameters.
     *
     */
    public static void testLogonNullParameters()
    {
        _test.displayHeaderMethod("testLogonNullParameters");

        try
        {
            _test.displayMsg(TestUtils.NEXT + "Parameters = Login null");

            try
            {
                StandardService.logon(null, PASSWORD_USER, _USERCONTEXT);
                _test.displayResultFailure(null);
            }
            catch (ServiceException se)
            {
                _test.displayResultSuccess(null);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        try
        {
            _test.displayMsg(TestUtils.NEXT + "Parameters = Password null");

            try
            {
                StandardService.logon(LOGIN_USER, null, _USERCONTEXT);
                _test.displayResultFailure(null);
            }
            catch (ServiceException se)
            {
                _test.displayResultSuccess(null);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        try
        {
            _test.displayMsg(TestUtils.NEXT + "Parameters = UserContext null");

            try
            {
                StandardService.logon(LOGIN_USER, PASSWORD_USER, null);
                _test.displayResultFailure(null);
            }
            catch (ServiceException se)
            {
                _test.displayResultSuccess(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("testLogonNullParameters");
    }

    /**
     * Tests the logon with empty parameters.
     *
     */
    public static void testLogonEmptyParameters()
    {
        _test.displayHeaderMethod("testLogonEmptyParameters");

        try
        {
            _test.displayMsg(TestUtils.NEXT +
                "Parameters = Login  empty String");

            try
            {
                UserContext userCT = new UserContext();
                StandardService.logon("", PASSWORD_USER, userCT);
                _test.displayResultFailure(null);
            }
            catch (ServiceException se)
            {
                _test.displayResultSuccess(null);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        try
        {
            _test.displayMsg(TestUtils.NEXT +
                "Parameters = Password  empty String");

            try
            {
                UserContext userCT = new UserContext();
                StandardService.logon(LOGIN_USER, "", userCT);
                _test.displayResultFailure(null);
            }
            catch (ServiceException se)
            {
                _test.displayResultSuccess(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("testLogonEmptyParameters");
    }

    /**
     * Tests the logon with incorrect parameters.
     *
     */
    public static void testLogonIncorrectParameters()
    {

⌨️ 快捷键说明

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