Package de.odysseus.calyxo.control.base

Source Code of de.odysseus.calyxo.control.base.ControlModuleContextTest

/*
* 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.base;

import java.util.HashMap;

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 junit.framework.TestCase;

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

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

  public void testBasics() throws ConfigException {
    ServletConfig config = new TestServletConfig("test");
    ControlModuleMapping mapping = new ControlModuleMapping("/test/*");
    ControlModuleContext context = new ControlModuleContext(config, mapping, null);
   
    assertSame("test", context.getName());
    assertSame(config.getServletContext(), context.getServletContext());
    assertEquals("/test/action", context.getPath("/action"));
  }

  public void testModuleAttributes() throws ConfigException {
    ServletConfig config = new TestServletConfig("test");
    ControlModuleMapping mapping = new ControlModuleMapping("/test/*");
    ControlModuleContext context = new ControlModuleContext(config, mapping, null);

    assertNull(context.getAttribute("foo"));
    context.setAttribute("foo", "bar");
    assertSame("bar", context.getAttribute("foo"));
    context.removeAttribute("foo");
    assertNull(context.getAttribute("foo"));
  }

  public void testInitParams() throws ConfigException {
    HashMap params = new HashMap();
    params.put("foo", "bar");
    TestServletConfig config = new TestServletConfig("test", params);
    ControlModuleMapping mapping = new ControlModuleMapping("/test/*");
    ControlModuleContext module = new ControlModuleContext(config, mapping, null);

    assertNull(module.getInitParameter("bar"));
    assertSame("bar", module.getInitParameter("foo"));
  }

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

}
TOP

Related Classes of de.odysseus.calyxo.control.base.ControlModuleContextTest

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.