Java Code Examples for com.mockobjects.servlet.MockHttpServletRequest#setupAddParameter()

The following examples show how to use com.mockobjects.servlet.MockHttpServletRequest#setupAddParameter() . 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: 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 2
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 3
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 4
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 5
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 6
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();

}