Package org.strecks.controller.chain.command

Source Code of org.strecks.controller.chain.command.TestCreateAction

package org.strecks.controller.chain.command;

import static org.easymock.EasyMock.expect;
import static org.testng.Assert.*;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.chain.contexts.ServletActionContext;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ModuleConfig;
import org.strecks.controller.ActionCreator;
import org.testng.annotations.Test;

/**
* @author Phil Zoio
*/
public class TestCreateAction extends AbstractTestChain
{

  @Test
  public void testCreateAction() throws Exception
  {
    ActionCreator actionCreator = newMock(ActionCreator.class);
    CreateAction createAction = getCreateAction(actionCreator);
    ServletActionContext actionContext = getActionContext();
    ActionConfig actionConfig = newMock(ActionConfig.class);
    ModuleConfig moduleConfig = newMock(ModuleConfig.class);
    ActionServlet servlet = newMock(ActionServlet.class);
    Map applicationScope = newMock(Map.class);
    Map actions = new HashMap();
    Action action = new Action();
   
    expect(actionConfig.getModuleConfig()).andReturn(moduleConfig);
    expect(moduleConfig.getPrefix()).andReturn("prefix");
    expect(actionContext.getApplicationScope()).andReturn(applicationScope);
    expect(applicationScope.get("actionsprefix")).andReturn(actions);
    expect(actionCreator.createAction(String.class)).andReturn(action);
    expect(actionContext.getActionServlet()).andReturn(servlet);

    replayMocks();
    createAction.getAction(actionContext, "java.lang.String", actionConfig);
    verifyMocks();
   
    assertEquals(1, actions.size());
  }
 
  public CreateAction getCreateAction(final ActionCreator actionCreator)
  {
    return new CreateAction()
    {
      protected ActionCreator newActionCreator()
      {
        return actionCreator;
      }
    };
  }

}
TOP

Related Classes of org.strecks.controller.chain.command.TestCreateAction

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.