Package de.odysseus.calyxo.panels

Source Code of de.odysseus.calyxo.panels.PanelsContextTest

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

import java.util.EmptyStackException;
import java.util.Iterator;
import java.util.Locale;

import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.test.TestModuleContext;
import de.odysseus.calyxo.panels.conf.ItemConfig;
import de.odysseus.calyxo.panels.conf.ListConfig;
import de.odysseus.calyxo.panels.conf.PanelConfig;
import de.odysseus.calyxo.panels.conf.ParamConfig;
import junit.framework.TestCase;

/**
*
* @author Christoph Beck
*/
public class PanelsContextTest extends TestCase {
  private static final String PACKAGE_PATH =
    "/" + PanelsContextTest.class.getPackage().getName().replace('.', '/');

  private PanelsContext context;

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

  public void setUp() throws ConfigException {
    TestModuleContext module = new TestModuleContext("test");
    PanelsService service = new PanelsService();
    service.init(module, PACKAGE_PATH + "/" + "PanelsContextTest.xml");
    PanelsSupport support = PanelsSupport.getInstance(module);
    context = new PanelsContext(support, new Locale("", ""));
  }

  public void testPushPop() {

    PanelConfig test = context.lookupPanelConfig("test");
    assertNotNull(test);

    context.push(test);

    assertNotNull(context.lookupParamConfig("param"));
    assertNotNull(context.lookupPanelConfig("panel"));
    assertNotNull(context.lookupListConfig("list"));

    context.pop();

    assertNull(context.lookupParamConfig("param"));
    assertNull(context.lookupPanelConfig("panel"));
    assertNull(context.lookupListConfig("list"));
  }

  public void testLookup() throws ConfigException {

    PanelConfig test = context.lookupPanelConfig("test");
    assertNotNull(test);

    context.push(test); // --> /panel

    ParamConfig param = context.lookupParamConfig("param");
    assertNotNull(param);
    assertEquals("test.param", param.getValue());

    PanelConfig panel = context.lookupPanelConfig("panel");
    assertNotNull(panel);
    context.push(panel); // --> /panel/panel
    param = context.lookupParamConfig("param");
    assertNotNull(param);
    assertEquals("test.panel.param", param.getValue());
    context.pop(); // --> /panel

    ListConfig list = context.lookupListConfig("list");
    assertNotNull(list);
    Iterator items = list.getItemConfigs();
    assertTrue(items.hasNext());
    ItemConfig item = (ItemConfig)items.next();
    context.push(item); // --> /panel/item

    param = context.lookupParamConfig("param");
    assertNotNull(param);
    assertEquals("test.item.param", param.getValue());

    panel = context.lookupPanelConfig("panel");
    assertNotNull(panel);
    context.push(panel); // --> /panel/item/panel
    param = context.lookupParamConfig("param");
    assertNotNull(param);
    assertEquals("test.item.panel.param", param.getValue());
    context.pop(); // --> /panel/item

    context.pop(); // --> /panel

    assertTrue(items.hasNext());
    item = (ItemConfig)items.next();
    context.push(item); // --> /panel/item

    param = context.lookupParamConfig("param");
    assertNotNull(param);
    assertEquals("test.param", param.getValue());

    panel = context.lookupPanelConfig("panel");
    assertNotNull(panel);
    context.push(panel); // --> /panel/item/panel
    param = context.lookupParamConfig("param");
    assertNotNull(param);
    assertEquals("test.panel.param", param.getValue());
    context.pop(); // --> /panel/item

    context.pop(); // --> /panel

    context.pop(); // --> /
  }

  public void testPopEmpty() {
    try {
      context.pop();
      fail();
    } catch (EmptyStackException e) {
    }
  }


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

}
TOP

Related Classes of de.odysseus.calyxo.panels.PanelsContextTest

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.