com.mockobjects.servlet.MockHttpServletRequest Java Examples

The following examples show how to use com.mockobjects.servlet.MockHttpServletRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActionChainHelperTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests prepopulateActionChains().
 */
public void testPrepopulateActionChains() {
    List<ActionChain> actionChains = new LinkedList<ActionChain>();
    for (int i = 0; i < 10; i++) {
        actionChains.add(ActionChainFactory.createActionChain(TestUtils.randomString(),
            user));
    }

    List<Map<String, String>> result = new LinkedList<Map<String, String>>();

    for (ActionChain actionChain : ActionChainFactory.getActionChains(user)) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("id", actionChain.getLabel());
        map.put("text", actionChain.getLabel());
        result.add(map);
    }

    MockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser();
    String s = new JSONWriter().write(result);
    request.addExpectedSetAttribute(
        ActionChainHelper.EXISTING_ACTION_CHAINS_PROPERTY_NAME, s);

    ActionChainHelper.prepopulateActionChains(request);
}
 
Example #2
Source File: NavDialogMenuTagTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
public void testTagOutput() {
    TagTestHelper tth = TagTestUtils.setupTagTest(nmt, url);

    try {
        // setup mock objects
        MockJspWriter out = (MockJspWriter) tth.getPageContext().getOut();
        out.setExpectedData(getReturnValue());

        // ok let's test the tag
        setupTag(nmt, 0, 4, NAV_XML, DIALOG_NAV);
        MockHttpServletRequest req = tth.getRequest();
        req.addExpectedSetAttribute("innernavtitle", " - Sign In");
        tth.assertDoStartTag(Tag.SKIP_BODY);
        out.verify();
    }
    catch (JspException e) {
        fail(e.toString());
    }
}
 
Example #3
Source File: NewUserEventTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
private NewUserEvent createTestEvent() {
    NewUserEvent evt = new NewUserEvent();
    // In the implementation we use getHeaderNames so we override it with
    // one that returns an empty implementation.
    MockHttpServletRequest request = new MockHttpServletRequest() {
        @Override
        public Enumeration<String> getHeaderNames() {
            return new Vector<String>().elements();
        }
    };
    request.setSession(new MockHttpSession());
    request.setupGetRequestURI("http://localhost:8080");
    request.setupGetMethod("POST");
    User usr = UserTestUtils.findNewUser("testUser",
            "testOrg" + this.getClass().getSimpleName());

    evt.setUser(usr);
    evt.setDomain("someserver.rhndev.redhat.com");
    evt.setAdmins(createAdmins());
    evt.setRequest(request);
    return evt;
}
 
Example #4
Source File: TraceBackEventTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
private TraceBackEvent createTestEvent() {
    TraceBackEvent evt = new TraceBackEvent();
    // In the implementation we use getHeaderNames so we override it with
    // one that returns an empty implementation.
    MockHttpServletRequest request = new MockHttpServletRequest() {
        public Enumeration<String> getHeaderNames() {
            return new Vector<String>().elements();
        }
    };
    request.setSession(new MockHttpSession());
    request.setupGetRequestURI("http://localhost:8080");
    request.setupGetMethod("POST");
    Vector<String> v = new Vector<String>();
    v.add("someparam");
    request.setupAddParameter("someparam", "somevalue");
    request.setupGetParameterNames(v.elements());
    evt.setUser(UserTestUtils.findNewUser("testUser",
                "testOrg" + this.getClass().getSimpleName()));
    evt.setRequest(request);
    Throwable e = new RuntimeException(MSG_OUTER_EXC);
    e.initCause(new RuntimeException(MSG_INNER_EXC));
    evt.setException(e);
    return evt;
}
 
Example #5
Source File: TraceBackEventTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
private TraceBackEvent createTestEventWithValue(String paramIn, String valueIn) {
    TraceBackEvent evt = new TraceBackEvent();
    // In the implementation we use getHeaderNames so we override it with
    // one that returns an empty implementation.
    MockHttpServletRequest request = new MockHttpServletRequest() {
        public Enumeration<String> getHeaderNames() {
            return new Vector<String>().elements();
        }
    };
    request.setSession(new MockHttpSession());
    request.setupGetRequestURI("http://localhost:8080");
    request.setupGetMethod("POST");
    Vector<String> v = new Vector<String>();
    v.add(paramIn);
    request.setupAddParameter(paramIn, valueIn);
    request.setupGetParameterNames(v.elements());
    evt.setUser(UserTestUtils.findNewUser("testUser",
                "testOrg" + this.getClass().getSimpleName()));
    evt.setRequest(request);
    Throwable e = new RuntimeException(MSG_OUTER_EXC);
    e.initCause(new RuntimeException(MSG_INNER_EXC));
    evt.setException(e);
    return evt;
}
 
Example #6
Source File: ActionChainHelperTest.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests prepopulateActionChains().
 */
public void testPrepopulateActionChains() {
    List<ActionChain> actionChains = new LinkedList<ActionChain>();
    for (int i = 0; i < 10; i++) {
        actionChains.add(ActionChainFactory.createActionChain(TestUtils.randomString(),
            user));
    }

    List<Map<String, String>> result = new LinkedList<Map<String, String>>();

    for (ActionChain actionChain : ActionChainFactory.getActionChains(user)) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("id", actionChain.getLabel());
        map.put("text", actionChain.getLabel());
        result.add(map);
    }

    MockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser();
    String s = new JSONWriter().write(result);
    request.addExpectedSetAttribute(
        ActionChainHelper.EXISTING_ACTION_CHAINS_PROPERTY_NAME, s);

    ActionChainHelper.prepopulateActionChains(request);
}
 
Example #7
Source File: NavDialogMenuTagTest.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
public void testTagOutput() {
    TagTestHelper tth = TagTestUtils.setupTagTest(nmt, url);

    try {
        // setup mock objects
        MockJspWriter out = (MockJspWriter) tth.getPageContext().getOut();
        out.setExpectedData(getReturnValue());

        // ok let's test the tag
        setupTag(nmt, 0, 4, NAV_XML, DIALOG_NAV);
        MockHttpServletRequest req = tth.getRequest();
        req.addExpectedSetAttribute("innernavtitle", " - Sign In");
        tth.assertDoStartTag(Tag.SKIP_BODY);
        out.verify();
    }
    catch (JspException e) {
        fail(e.toString());
    }
}
 
Example #8
Source File: NewUserEventTest.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
private NewUserEvent createTestEvent() {
    NewUserEvent evt = new NewUserEvent();
    // In the implementation we use getHeaderNames so we override it with
    // one that returns an empty implementation.
    MockHttpServletRequest request = new MockHttpServletRequest() {
        @Override
        public Enumeration<String> getHeaderNames() {
            return new Vector<String>().elements();
        }
    };
    request.setSession(new MockHttpSession());
    request.setupGetRequestURI("http://localhost:8080");
    request.setupGetMethod("POST");
    User usr = UserTestUtils.findNewUser("testUser",
            "testOrg" + this.getClass().getSimpleName());

    evt.setUser(usr);
    evt.setDomain("someserver.rhndev.redhat.com");
    evt.setAdmins(createAdmins());
    evt.setRequest(request);
    return evt;
}
 
Example #9
Source File: TraceBackEventTest.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
private TraceBackEvent createTestEvent() {
    TraceBackEvent evt = new TraceBackEvent();
    // In the implementation we use getHeaderNames so we override it with
    // one that returns an empty implementation.
    MockHttpServletRequest request = new MockHttpServletRequest() {
        public Enumeration<String> getHeaderNames() {
            return new Vector<String>().elements();
        }
    };
    request.setSession(new MockHttpSession());
    request.setupGetRequestURI("http://localhost:8080");
    request.setupGetMethod("POST");
    Vector<String> v = new Vector<String>();
    v.add("someparam");
    request.setupAddParameter("someparam", "somevalue");
    request.setupGetParameterNames(v.elements());
    evt.setUser(UserTestUtils.findNewUser("testUser",
                "testOrg" + this.getClass().getSimpleName()));
    evt.setRequest(request);
    Throwable e = new RuntimeException(MSG_OUTER_EXC);
    e.initCause(new RuntimeException(MSG_INNER_EXC));
    evt.setException(e);
    return evt;
}
 
Example #10
Source File: TraceBackEventTest.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
private TraceBackEvent createTestEventWithValue(String paramIn, String valueIn) {
    TraceBackEvent evt = new TraceBackEvent();
    // In the implementation we use getHeaderNames so we override it with
    // one that returns an empty implementation.
    MockHttpServletRequest request = new MockHttpServletRequest() {
        public Enumeration<String> getHeaderNames() {
            return new Vector<String>().elements();
        }
    };
    request.setSession(new MockHttpSession());
    request.setupGetRequestURI("http://localhost:8080");
    request.setupGetMethod("POST");
    Vector<String> v = new Vector<String>();
    v.add(paramIn);
    request.setupAddParameter(paramIn, valueIn);
    request.setupGetParameterNames(v.elements());
    evt.setUser(UserTestUtils.findNewUser("testUser",
                "testOrg" + this.getClass().getSimpleName()));
    evt.setRequest(request);
    Throwable e = new RuntimeException(MSG_OUTER_EXC);
    e.initCause(new RuntimeException(MSG_INNER_EXC));
    evt.setException(e);
    return evt;
}
 
Example #11
Source File: TestServletRequestConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Override
protected AbstractConfiguration getEmptyConfiguration()
{
    final ServletRequest request = new MockHttpServletRequest()
    {
        @Override
        public String getParameter(final String key)
        {
            return null;
        }

        @Override
        public Map<?, ?> getParameterMap()
        {
            return new HashMap<>();
        }
    };

    return new ServletRequestConfiguration(request);
}
 
Example #12
Source File: TestServletRequestConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new servlet request configuration that is backed by the passed
 * in configuration.
 *
 * @param base the configuration with the underlying values
 * @return the servlet request configuration
 */
private ServletRequestConfiguration createConfiguration(final Configuration base)
{
    final ServletRequest request = new MockHttpServletRequest()
    {
        @Override
        public String[] getParameterValues(final String key)
        {
            return base.getStringArray(key);
        }

        @Override
        public Map<?, ?> getParameterMap()
        {
            return new ConfigurationMap(base);
        }
    };

    final ServletRequestConfiguration config = new ServletRequestConfiguration(request);
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return config;
}
 
Example #13
Source File: ColumnTagTest.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
public void testDoStartTag() throws JspException {
    disableLocalizationServiceLogging();
    ListDisplayTag ldt = new ListDisplayTag();
    ColumnTag ct = new ColumnTag();
    ct.setSortProperty("sortProp");
    assertNull(ct.getParent());

    ct.setParent(ldt);
    ct.setHeader("headervalue");
    assertEquals(ldt, ct.getParent());

    TagTestHelper tth = TagTestUtils.setupTagTest(ct, null);
    MockHttpServletRequest mockRequest = (MockHttpServletRequest)
            tth.getPageContext().getRequest();
    // Dumb, dumb, dumb
    // Mock request doesn't parse the query string!
    // I've had salads with more intelligence
    mockRequest.setupAddParameter("order", "asc");
    // And we STILL have to set the query string
    // otherwise MockObjects complains bitterly....
    mockRequest.setupQueryString("this=stupid&library=needs_this");
    // setup mock objects
    MockJspWriter out = (MockJspWriter)tth.getPageContext().getOut();

    out.setExpectedData("<th>" +
            "<a title=\"Sort By This Column\" " +
            "href=\"http://localhost:8080/rhnjava/index.jsp?order=desc" +
            "&sort=sortProp\">**headervalue**</a></th>");
    MockPageContext mpc = tth.getPageContext();
    mpc.setAttribute("current", new Object());
    ct.setPageContext(mpc);
    tth.assertDoStartTag(Tag.SKIP_BODY);
    tth.assertDoEndTag(Tag.EVAL_BODY_INCLUDE);
    //TODO: verify if this test is needed, followup with bug 458688
    //out.verify();
    enableLocalizationServiceLogging();

}
 
Example #14
Source File: BaseTestToolbarTag.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
public void setUp() {
    tt = new ToolbarTag();
    tth = TagTestUtils.setupTagTest(tt, null);
    out = (MockJspWriter) tth.getPageContext().getOut();
    MockHttpServletRequest req = tth.getRequest();
    req.setupGetAttribute(new HashMap());
}
 
Example #15
Source File: ColumnTagTest.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
public void testDoStartTag() throws JspException {
    disableLocalizationServiceLogging();
    ListDisplayTag ldt = new ListDisplayTag();
    ColumnTag ct = new ColumnTag();
    ct.setSortProperty("sortProp");
    assertNull(ct.getParent());

    ct.setParent(ldt);
    ct.setHeader("headervalue");
    assertEquals(ldt, ct.getParent());

    TagTestHelper tth = TagTestUtils.setupTagTest(ct, null);
    MockHttpServletRequest mockRequest = (MockHttpServletRequest)
            tth.getPageContext().getRequest();
    // Dumb, dumb, dumb
    // Mock request doesn't parse the query string!
    // I've had salads with more intelligence
    mockRequest.setupAddParameter("order", "asc");
    // And we STILL have to set the query string
    // otherwise MockObjects complains bitterly....
    mockRequest.setupQueryString("this=stupid&library=needs_this");
    // setup mock objects
    MockJspWriter out = (MockJspWriter)tth.getPageContext().getOut();

    out.setExpectedData("<th>" +
            "<a title=\"Sort By This Column\" " +
            "href=\"http://localhost:8080/rhnjava/index.jsp?order=desc" +
            "&sort=sortProp\">**headervalue**</a></th>");
    MockPageContext mpc = tth.getPageContext();
    mpc.setAttribute("current", new Object());
    ct.setPageContext(mpc);
    tth.assertDoStartTag(Tag.SKIP_BODY);
    tth.assertDoEndTag(Tag.EVAL_BODY_INCLUDE);
    //TODO: verify if this test is needed, followup with bug 458688
    //out.verify();
    enableLocalizationServiceLogging();

}
 
Example #16
Source File: BaseTestToolbarTag.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
public void setUp() {
    tt = new ToolbarTag();
    tth = TagTestUtils.setupTagTest(tt, null);
    out = (MockJspWriter) tth.getPageContext().getOut();
    MockHttpServletRequest req = tth.getRequest();
    req.setupGetAttribute(new HashMap());
}