Search in sources :

Example 66 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class CompositeRequestConditionTests method match.

@Test
public void match() {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
    request.setParameter("param1", "paramValue1");
    request.addHeader("header1", "headerValue1");
    RequestCondition<?> getPostCond = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
    RequestCondition<?> getCond = new RequestMethodsRequestCondition(RequestMethod.GET);
    CompositeRequestCondition condition = new CompositeRequestCondition(this.param1, getPostCond);
    CompositeRequestCondition matchingCondition = new CompositeRequestCondition(this.param1, getCond);
    assertEquals(matchingCondition, condition.getMatchingCondition(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 67 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class CompositeRequestConditionTests method compareDifferentLength.

@Test(expected = IllegalArgumentException.class)
public void compareDifferentLength() {
    CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
    CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
    cond1.compareTo(cond2, new MockHttpServletRequest());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 68 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method consumesMultipleMatch.

@Test
public void consumesMultipleMatch() {
    ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContentType("text/plain");
    assertNotNull(condition.getMatchingCondition(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 69 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method negatedConsumesMatch.

@Test
public void negatedConsumesMatch() {
    ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContentType("text/plain");
    assertNull(condition.getMatchingCondition(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 70 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method consumesParseErrorWithNegation.

@Test
public void consumesParseErrorWithNegation() {
    ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContentType("01");
    assertNull(condition.getMatchingCondition(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)646 Test (org.junit.Test)540 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)330 Before (org.junit.Before)78 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)77 MockServletContext (org.springframework.mock.web.test.MockServletContext)56 TestBean (org.springframework.tests.sample.beans.TestBean)43 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)41 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)30 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)29 ITestBean (org.springframework.tests.sample.beans.ITestBean)28 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)28 ServletException (javax.servlet.ServletException)27 HashMap (java.util.HashMap)26 FilterChain (javax.servlet.FilterChain)26 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)23 Cookie (javax.servlet.http.Cookie)22