Example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse.

Prototype

MockHttpServletResponse

Source Link

Usage

From source file:org.araneaframework.tests.framework.filter.StandardSynchronizingFilterServiceTests.java

public void setUp() throws Exception {
    service = new StandardSynchronizingFilterService();
    child = new MockEventfulBaseService();
    service.setChildService(child);/*  w  w  w  .j  a  va2s  . c  o  m*/
    MockLifeCycle.begin(service);

    req = new MockHttpServletRequest();
    res = new MockHttpServletResponse();

    input = new StandardServletInputData(req);
    output = new StandardServletOutputData(req, res);
}

From source file:org.javalite.activeweb.SpecHelper.java

@Before
public void atStart() {
    sessionFacade = new SessionTestFacade(new MockHttpSession());
    setTemplateLocation("src/main/webapp/WEB-INF/views");//default location of all views

    Context.setTLs(null, new MockHttpServletResponse(), new MockFilterConfig(),
            new ControllerRegistry(new MockFilterConfig()), new AppContext(), new RequestContext(), null);
}

From source file:com.baidu.rigel.test.strut2.AbstractStruts2SpringContextTests.java

/**
 * Execute before test method./*  w  w  w. j  a  v a  2  s.c o m*/
 */
public void executeBeforeTestMethod() {
    response = new MockHttpServletResponse();
    request = new MockHttpServletRequest();
    pageContext = new MockPageContext();
    servletContext = new MockServletContext();

    ActionContext context = new ActionContext(new HashMap<String, Object>());
    ServletActionContext.setContext(context);

    ServletActionContext.setRequest(request);
    ServletActionContext.setResponse(response);
}

From source file:com.gantzgulch.taglibs.html.BodyTagRunner.java

public BodyTagRunner(BodyTag bodyTag, String contextPath) throws JspException {

    servletRequest = new MockHttpServletRequest();
    servletResponse = new MockHttpServletResponse();
    servletContext = new MockServletContext();
    servletContext.setContextPath(contextPath);
    pageContext = new MockPageContext(servletContext, servletRequest, servletResponse);

    this.bodyTag = bodyTag;
    state = doInitializeState.execute();
}

From source file:org.openmrs.web.controller.form.FieldFormControllerTest.java

/**
 * @see FieldFormController#formBackingObject(HttpServletRequest)
 */// ww w .  j  av  a  2  s  . co m
// @Transactional annotation needed because the parent class is @Transactional and so screws propagates to this readOnly test
@Transactional(readOnly = true)
@Test
@Verifies(value = "should get field", method = "formBackingObject(HttpServletRequest)")
public void formBackingObject_shouldGetField() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    request.setParameter("fieldId", "1");

    HttpServletResponse response = new MockHttpServletResponse();

    FieldFormController controller = (FieldFormController) applicationContext.getBean("fieldForm");

    ModelAndView modelAndView = controller.handleRequest(request, response);

    // make sure there is a "userId" filled in on the concept
    Field command = (Field) modelAndView.getModel().get("field");
    Assert.assertNotNull(command.getFieldId());
}

From source file:org.araneaframework.tests.framework.container.StandardServiceContainerWidgetTests.java

public void setUp() throws Exception {
    child = new MockEventfulStandardService();
    parent = new StandardServiceAdapterWidget();
    parent.setChildService(child);//from ww w.  java2  s.c om
    MockLifeCycle.begin(parent);

    req = new MockHttpServletRequest();
    res = new MockHttpServletResponse();

    input = new StandardServletInputData(req);
    output = new StandardServletOutputData(req, res);
}

From source file:org.eclipse.virgo.apps.repository.web.RepositoryControllerTests.java

@Test
public void getIndex() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setRequestURI("http://localhost:8080/org.eclipse.virgo.server.repository/my-repo");
    request.setMethod("GET");

    byte[] indexBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

    RepositoryIndex repositoryIndex = createMock(RepositoryIndex.class);
    expect(repositoryIndex.getInputStream()).andReturn(new ByteArrayInputStream(indexBytes)).anyTimes();
    expect(repositoryIndex.getETag()).andReturn("123456789").anyTimes();
    expect(repositoryIndex.getLength()).andReturn(indexBytes.length).anyTimes();

    expect(this.repositoryManager.getIndex("my-repo")).andReturn(repositoryIndex);

    replay(this.repositoryManager, repositoryIndex);

    repositoryController.getIndex(request, response);

    verify(this.repositoryManager, repositoryIndex);

    assertEquals("application/org.eclipse.virgo.repository.Index", response.getContentType());
    assertArrayEquals(indexBytes, response.getContentAsByteArray());
}

From source file:org.jasig.cas.support.oauth.web.OAuth20WrapperControllerTests.java

@Test
public void verifyWrongMethod() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + "wrongmethod");

    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);

    assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
    assertEquals("text/plain", mockResponse.getContentType());
    assertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString());
}

From source file:com.thoughtworks.go.server.controller.actions.JsonActionTest.java

@Test
public void shouldReturnJsonConflictInNormalConflict() throws Exception {
    when(configValidity.isType(GoConfigValidity.VT_CONFLICT)).thenReturn(true);
    JsonAction action = JsonAction.jsonByValidity(jsonAware, configValidity);
    MockHttpServletResponse response = new MockHttpServletResponse();
    action.respond(response);//from w  w  w  .  j  ava 2  s.co m
    assertThat(response.getStatus(), is(SC_CONFLICT));
    verify(configValidity).isType(GoConfigValidity.VT_CONFLICT);
}