⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conversionerrorinterceptortest.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
字号:
/* * Copyright (c) 2002-2006 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2.interceptor;import com.mockobjects.dynamic.C;import com.mockobjects.dynamic.Mock;import com.opensymphony.xwork2.*;import com.opensymphony.xwork2.util.ValueStack;import com.opensymphony.xwork2.util.ValueStackFactory;import com.opensymphony.xwork2.mock.MockActionInvocation;import java.util.HashMap;import java.util.Map;/** * Unit test for {@link ConversionErrorInterceptor}. * * @author Jason Carreira */public class ConversionErrorInterceptorTest extends XWorkTestCase {    protected ActionContext context;    protected ActionInvocation invocation;    protected ConversionErrorInterceptor interceptor;    protected Map conversionErrors;    protected Mock mockInvocation;    protected ValueStack stack;    public void testFieldErrorAdded() throws Exception {        conversionErrors.put("foo", new Long(123));        SimpleAction action = new SimpleAction();        mockInvocation.expectAndReturn("getAction", action);        stack.push(action);        mockInvocation.matchAndReturn("getAction", action);        assertNull(action.getFieldErrors().get("foo"));        interceptor.intercept(invocation);        assertTrue(action.hasFieldErrors());        assertNotNull(action.getFieldErrors().get("foo"));    }    public void testFieldErrorWithMapKeyAdded() throws Exception {        String fieldName = "foo['1'].intValue";        conversionErrors.put(fieldName, "bar");        ActionSupport action = new ActionSupport();        mockInvocation.expectAndReturn("getAction", action);        stack.push(action);        mockInvocation.matchAndReturn("getAction", action);        assertNull(action.getFieldErrors().get(fieldName));        interceptor.intercept(invocation);        assertTrue(action.hasFieldErrors()); // This fails!        assertNotNull(action.getFieldErrors().get(fieldName));    }    public void testWithPreResultListener() throws Exception {        conversionErrors.put("foo", "Hello");        ActionContext ac = new ActionContext(stack.getContext());        ac.setConversionErrors(conversionErrors);        ac.setValueStack(stack);        MockActionInvocation mai = new MockActionInvocation();        mai.setInvocationContext(ac);        mai.setStack(stack);        SimpleAction action = new SimpleAction();        action.setFoo(55);        mai.setAction(action);        stack.push(action);        assertNull(action.getFieldErrors().get("foo"));        assertEquals(new Integer(55), stack.findValue("foo"));        interceptor.intercept(mai);        assertTrue(action.hasFieldErrors());        assertNotNull(action.getFieldErrors().get("foo"));        assertEquals("Hello", stack.findValue("foo")); // assume that the original value is reset    }    protected void setUp() throws Exception {        super.setUp();        interceptor = new ConversionErrorInterceptor();        mockInvocation = new Mock(ActionInvocation.class);        invocation = (ActionInvocation) mockInvocation.proxy();        stack = ValueStackFactory.getFactory().createValueStack();        context = new ActionContext(stack.getContext());        conversionErrors = new HashMap();        context.setConversionErrors(conversionErrors);        mockInvocation.matchAndReturn("getInvocationContext", context);        mockInvocation.expect("addPreResultListener", C.isA(PreResultListener.class));        mockInvocation.expectAndReturn("invoke", Action.SUCCESS);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -