Package de.odysseus.calyxo.control

Source Code of de.odysseus.calyxo.control.PluginContextTest

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.control;

import javax.servlet.ServletConfig;

import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.test.TestServletConfig;
import de.odysseus.calyxo.control.base.ControlModuleContext;
import de.odysseus.calyxo.control.base.ControlModuleMapping;
import de.odysseus.calyxo.control.impl.DefaultAction;
import de.odysseus.calyxo.control.impl.DefaultDispatcher;
import de.odysseus.calyxo.control.misc.CancelFilter;
import junit.framework.TestCase;

/**
*
* @author Christoph Beck
*/
public class PluginContextTest extends TestCase {

  /**
   * Constructor for PluginContextTest.
   * @param arg0
   */
  public PluginContextTest(String arg0) {
    super(arg0);
  }

  public void testDispatcher() throws ConfigException {
    ServletConfig config = new TestServletConfig("test");
    ControlModuleMapping mapping = new ControlModuleMapping("/test/*");
    ControlModuleContext module = new ControlModuleContext(config, mapping, null);
    PluginContext context = new PluginContext(module, DefaultAction.class, new DefaultDispatcher(module));
    DefaultDispatcher dispatcher = new DefaultDispatcher(context.getModuleContext());

    assertNull(context.getDispatcher("foo"));
    context.setDispatcher("foo", dispatcher);
    assertSame(dispatcher, context.getDispatcher("foo"));
    context.setDefaultDispatcher(dispatcher);
    assertSame(dispatcher, context.getDefaultDispatcher());   
    try {
      context.setDefaultDispatcher(new DefaultDispatcher(context.getModuleContext()));
      fail("Exception expected (default dispatcher already set)");
    } catch (Exception e) {
    }
    try {
      context.setDispatcher("foo", new DefaultDispatcher(context.getModuleContext()));
      fail("Exception expected (dispatcher 'foo' already set)");
    } catch (Exception e) {
    }
  }

  public void testFilterClass() throws ConfigException {
    ServletConfig config = new TestServletConfig("test");
    ControlModuleMapping mapping = new ControlModuleMapping("/test/*");
    ControlModuleContext module = new ControlModuleContext(config, mapping, null);
    PluginContext context = new PluginContext(module, DefaultAction.class, new DefaultDispatcher(module));

    assertNull(context.getFilterClass("foo"));
    context.setFilterClass("foo", CancelFilter.class);
    try {
      context.setFilterClass("foo", Object.class);
      fail("Exception expected (duplicate filter factory name)");
    } catch (ConfigException e) {
    }
    assertSame(CancelFilter.class, context.getFilterClass("foo"));
  }

  public static void main(String[] args) {
    junit.textui.TestRunner.run(PluginContextTest.class);
  }

}
TOP

Related Classes of de.odysseus.calyxo.control.PluginContextTest

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.