Package speculoos.manager

Source Code of speculoos.manager.ManagerConfigureTest

/*---------------------------------------------------------------------------
* Speculoos, LDAP to objet mapping.
* Copyright (C) 2006  Norsys and oQube
*
* 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 (at your option) any 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Created on Oct 21, 2005
* --------------------------------------------------------------------------*/
package speculoos.manager;

import org.jmock.Mock;
import org.jmock.MockObjectTestCase;

import speculoos.core.Mapper;
import speculoos.core.MapperException;
import speculoos.spi.Source;


public class ManagerConfigureTest extends MockObjectTestCase {

    private Configure configure;

    private Mock mockmapper;

    private Mock mocksrc;

    protected void setUp() throws Exception {
        super.setUp();
        /* create stub and driver */
        mockmapper = mock(Mapper.class);
        mocksrc = mock(Source.class);
        /* create manager */
        configure = new MapperManager();
    }

    /**
     * Test basic configuration
     *
     * @throws MapperConfigurationException
     */
    public void test01BasicConfigure() throws MapperConfigurationException {
        /* configure */
        Mapper m = (Mapper) mockmapper.proxy();
        Source s = (Source) mocksrc.proxy();
        mockmapper.expects(atLeastOnce()).method("getName");
        configure.addMapper("map", m);
        configure.addSource("source", s);
        configure.link("map", "source");
        configure.setConfigured();
        /* everything should be OK */
    }

    /**
     * Test basic configuration
     *
     * @throws MapperConfigurationException
     */
    public void test02Reset() throws MapperConfigurationException {
        /* configure */
        Mapper m = (Mapper) mockmapper.proxy();
        Source s = (Source) mocksrc.proxy();
        mockmapper.expects(atLeastOnce()).method("getName");
configure.addMapper("map", m);
        configure.addSource("source", s);
        configure.addParameter("toto", "toto");
        configure.link("map", "source");
        configure.setConfigured();
        /* everything should be OK */
        configure.reset();
        try {
            configure.lookup("toto");
            fail("Should have thrown exception");
        } catch (MapperException e) {
        }
    }

    /**
     * Test basic parameters handling
     *
     * @throws MapperException
     */
    public void test02Parameters() throws MapperException {
        configure.addParameter("toto", "tutu");
        Object p = configure.lookup("toto");
        assertEquals("tutu", p);
    }

    /**
     * Test setting params
     *
     * @throws MapperException
     */
    public void test03ParameterSetting() throws MapperException {
        configure.addParameter("toto", "tutu");
        configure.set("toto", new Integer(1));
        Object p = configure.lookup("toto");
        assertEquals(new Integer(1), p);
    }

    /**
     * Test unsetting parameters.
     *
     * @throws MapperException
     *
     */
    public void test04ParameterUnset() throws MapperException {
        configure.addParameter("toto", "tutu");
        configure.set("toto", new Integer(1));
        configure.set("toto", new Object());
        configure.unset("toto");
        Object p = configure.lookup("toto");
        assertEquals("tutu", p);
    }

    /**
     * Test setting unknown parameter
     *
     */
    public void test05ParameterSettingFailure() {
        try {
          configure.addParameter("titi","tutu");
        } catch (MapperConfigurationException e1) {
            fail("Unexpected exception: " + e1);
        }
        try {
            configure.set("toto", new Integer(1));
            fail("Should have thrown configuration exception");    
        } catch (MapperConfigurationException e2) {
        }
        try {
          configure.setConfigured();
            configure.set("titi", new Integer(1));
            fail("Should have thrown configuration exception");    
        } catch (MapperConfigurationException e2) {
        }
    }

    public void test06DoubleParameterSetting() {
        try {
            configure.addParameter("toto", "tutu");
            configure.addParameter("toto", "tata");
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
            // OK
        }
    }

    public void test07DoubleMapperSetting() {
        try {
            configure.addMapper("toto", (Mapper) mockmapper.proxy());
            configure.addMapper("toto", (Mapper) mockmapper.proxy());
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
            // OK
        }
    }

    public void test08DoubleSourceSetting() {
        try {
            configure.addSource("toto", (Source) mocksrc.proxy());
            configure.addSource("toto", (Source) mocksrc.proxy());
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
            // OK
        }
    }

    public void test09DoubleLinkOK() {
        try {
            configure.addSource("tata", (Source) mocksrc.proxy());
            configure.addMapper("toto", (Mapper) mockmapper.proxy());
            mockmapper.expects(atLeastOnce()).method("getName");
            configure.link("toto", "tata");
            configure.link("toto", "tata");
        } catch (MapperConfigurationException e) {
            fail("Throw exception " + e);
        }
    }

    public void test10ParametterSettingAfterConfigured() {
        try {
            configure.addParameter("toto", "tutu");
            configure.setConfigured();
            configure.addParameter("titi", "tata");
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
            // OK
        }

    }

    public void test11MapperSettingAfterConfigured() {
        try {
            configure.addMapper("toto", (Mapper) mockmapper.proxy());
            configure.setConfigured();
            configure.addMapper("titi", (Mapper) mockmapper.proxy());
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
            // OK
        }

    }

    public void test12SourceSettingAfterConfigured() {
        try {
            configure.addSource("toto", (Source) mocksrc.proxy());
            configure.setConfigured();
            configure.addSource("titi", (Source) mocksrc.proxy());
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
            // OK
        }

    }

    public void test13NullSource() {
        try {
            configure.addSource("toto", null);
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test14NullSourceName() {
        try {
            configure.addSource(null, (Source) mocksrc.proxy());
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test15NullMapper() {
        try {
            configure.addMapper("toto", null);
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test16NullMapperName() {
        try {
            configure.addMapper(null, (Mapper) mockmapper.proxy());
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test17EmptyMapperName() {
        try {
            configure.addMapper("", (Mapper) mockmapper.proxy());
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test18EmptySourceName() {
        try {
            configure.addSource("", (Source) mocksrc.proxy());
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test19NullParameterValue() {
        try {
            configure.addParameter("toto", null);
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test20NullParameterName() {
        try {
            configure.addParameter(null, "toto");
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }

    public void test21EmptyParameterName() {
        try {
            configure.addParameter("", "toto");
            fail("Should have thrown exception");
        } catch (IllegalArgumentException e) {
            // OK
        } catch (MapperConfigurationException e) {
            fail(e.getLocalizedMessage());
        }
    }
   
    public void test22NoMapperLink() throws MapperConfigurationException {
        Mapper m = (Mapper) mockmapper.proxy();
        Source s = (Source) mocksrc.proxy();
        configure.addSource("source", s);
        try {
            configure.link("map", "source");
            fail("Should have thrown mapper exception");
        } catch (MapperConfigurationException e) {
//OK
            }
    }
    public void test23NoSourceLink() throws MapperConfigurationException {
        Mapper m = (Mapper) mockmapper.proxy();
        Source s = (Source) mocksrc.proxy();
        configure.addMapper("map", m);
        try {
            configure.link("map", "source");
            fail("Should have thrown mapper exception");
        } catch (MapperConfigurationException e) {
//OK
            }
    }

    public void test24FailedLookupInUnset() {
        try {
            configure.unset("toto");
            fail("Should have thrown exception");
        } catch (MapperConfigurationException e) {
// OK
            }       
    }
}
TOP

Related Classes of speculoos.manager.ManagerConfigureTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.