public void testModelOnSession() throws Exception {
    inter.setScope("session");
    inter.setName("king");

    User user = new User();
    user.setName("King George");
    Map session = new HashMap();
    ActionContext.getContext().setSession(session);
    ActionContext.getContext().getSession().put("king", user);

    ScopedModelDriven action = new MyUserScopedModelDrivenAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);

    inter.intercept(mai);
    inter.destroy();

    assertNotNull(action.getModel());
    assertNotNull(action.getScopeKey());
    assertEquals("king", action.getScopeKey());

    Object model = ActionContext.getContext().getSession().get(action.getScopeKey());
    assertNotNull(model);
    assertTrue("Model should be an User object", model instanceof User);
    assertEquals("King George", ((User) model).getName());
  }
  public void testNoScopedModelAction() throws Exception {
    Action action = new SimpleAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);

    inter.intercept(mai);
    inter.destroy();
    // nothing happends
  }
  public void testScopedModelDrivenAction() throws Exception {
    inter.setScope("request");

    ScopedModelDriven action = new MyUserScopedModelDrivenAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);

    inter.intercept(mai);
    inter.destroy();

    assertNotNull(action.getModel());
    assertNotNull(action.getScopeKey());
    assertEquals("com.opensymphony.xwork2.test.User", action.getScopeKey());

    Object model = ActionContext.getContext().get(action.getScopeKey());
    assertNotNull(model);
    assertTrue("Model should be an User object", model instanceof User);
  }
  public void testModelAlreadySetOnAction() throws Exception {
    inter.setScope("request");
    inter.setName("king");

    User user = new User();
    user.setName("King George");

    ScopedModelDriven action = new MyUserScopedModelDrivenAction();
    action.setModel(user);
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);

    inter.intercept(mai);
    inter.destroy();

    assertNotNull(action.getModel());
    assertNull(action.getScopeKey()); // no scope key as nothing happended
  }
  public void setUp() throws Exception {
    interceptor = new I18nInterceptor();
    interceptor.init();
    session = new HashMap();

    Map<String, Object> ctx = new HashMap<String, Object>();
    ctx.put(ActionContext.PARAMETERS, HttpParameters.createEmpty().build());
    ctx.put(ActionContext.SESSION, session);

    ac = new ActionContext(ctx);

    ServletActionContext.setContext(ac);
    ServletActionContext.setRequest(new MockHttpServletRequest());

    Action action =
        new Action() {
          public String execute() throws Exception {
            return SUCCESS;
          }
        };
    mai = new MockActionInvocation();
    ((MockActionInvocation) mai).setAction(action);
    ((MockActionInvocation) mai).setInvocationContext(ac);
  }