Search in sources :

Example 41 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testBuildUrlCorrectlyAddsDoNotEscapeAmp.

/**
 * just one &, not &
 */
public void testBuildUrlCorrectlyAddsDoNotEscapeAmp() {
    String expectedString = "my.actionName?foo=bar&hello=world";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedString, expectedString);
    String actionName = "my.actionName";
    TreeMap params = new TreeMap();
    params.put("hello", "world");
    params.put("foo", "bar");
    String urlString = urlHelper.buildUrl(actionName, (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), params, null, true, true, false, false);
    assertEquals(expectedString, urlString);
}
Also used : TreeMap(java.util.TreeMap) Mock(com.mockobjects.dynamic.Mock)

Example 42 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testBuildUrlCorrectlyAddsAmp.

/**
 * just one &, not &
 */
public void testBuildUrlCorrectlyAddsAmp() {
    String expectedString = "my.actionName?foo=bar&hello=world";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedString, expectedString);
    String actionName = "my.actionName";
    TreeMap params = new TreeMap();
    params.put("hello", "world");
    params.put("foo", "bar");
    String urlString = urlHelper.buildUrl(actionName, (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), params);
    assertEquals(expectedString, urlString);
}
Also used : TreeMap(java.util.TreeMap) Mock(com.mockobjects.dynamic.Mock)

Example 43 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testBuildUrlWithStringArray.

public void testBuildUrlWithStringArray() {
    String expectedString = "my.actionName?foo=bar&hello=earth&hello=mars";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedString, expectedString);
    String actionName = "my.actionName";
    TreeMap params = new TreeMap();
    params.put("hello", new String[] { "earth", "mars" });
    params.put("foo", "bar");
    String urlString = urlHelper.buildUrl(actionName, (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), params);
    assertEquals(expectedString, urlString);
}
Also used : TreeMap(java.util.TreeMap) Mock(com.mockobjects.dynamic.Mock)

Example 44 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class VelocityResultTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    namespace = "/html";
    result = new VelocityResult();
    stack = ActionContext.getContext().getValueStack();
    velocity = new TestVelocityEngine();
    mockActionProxy = new Mock(ActionProxy.class);
    mockActionProxy.expectAndReturn("getNamespace", "/html");
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getProxy", mockActionProxy.proxy());
    mockActionInvocation.expectAndReturn("getStack", stack);
    actionInvocation = (ActionInvocation) mockActionInvocation.proxy();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) Mock(com.mockobjects.dynamic.Mock)

Example 45 with Mock

use of com.mockobjects.dynamic.Mock in project commons-configuration by apache.

the class MockInitialContextFactory method createCtxMock.

/**
 * Creates a mock for a Context with the specified prefix.
 *
 * @param prefix the prefix
 * @return the mock for the context
 */
private Mock createCtxMock(final String prefix) {
    final Mock mockCtx = new Mock(Context.class);
    for (int i = 0; i < PROP_NAMES.length; i++) {
        bind(mockCtx, prefix + PROP_NAMES[i], PROP_VALUES[i]);
        final String errProp = prefix.isEmpty() ? PREFIX + PROP_NAMES[i] : PROP_NAMES[i];
        bindError(mockCtx, errProp);
    }
    for (final String element : MISSING_NAMES) {
        bindError(mockCtx, element);
    }
    mockCtx.matchAndReturn("hashCode", System.identityHashCode(mockCtx.proxy()));
    return mockCtx;
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Aggregations

Mock (com.mockobjects.dynamic.Mock)91 HashMap (java.util.HashMap)14 ValidationException (com.opensymphony.xwork2.validator.ValidationException)12 StrutsException (org.apache.struts2.StrutsException)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 TreeMap (java.util.TreeMap)8 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 HttpParameters (org.apache.struts2.dispatcher.HttpParameters)6 MockHttpSession (org.springframework.mock.web.MockHttpSession)6 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)4 Container (com.opensymphony.xwork2.inject.Container)4 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)4 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)4 LinkedHashMap (java.util.LinkedHashMap)4 Action (com.opensymphony.xwork2.Action)3