Search in sources :

Example 76 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method matchWithNegationAndMediaTypeAllWithQualityParameter.

// SPR-17550
@Test
public void matchWithNegationAndMediaTypeAllWithQualityParameter() {
    ProducesRequestCondition condition = new ProducesRequestCondition("!application/json");
    HttpServletRequest request = createRequest("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
    assertThat(condition.getMatchingCondition(request)).isNotNull();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 77 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method matchParseError.

@Test
public void matchParseError() {
    ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
    HttpServletRequest request = createRequest("bogus");
    assertThat(condition.getMatchingCondition(request)).isNull();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 78 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method compareToMultipleExpressionsAndMultipleAcceptHeaderValues.

@Test
public void compareToMultipleExpressionsAndMultipleAcceptHeaderValues() {
    ProducesRequestCondition condition1 = new ProducesRequestCondition("text/*", "text/plain");
    ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml");
    HttpServletRequest request = createRequest("text/plain", "application/xml");
    int result = condition1.compareTo(condition2, request);
    assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
    result = condition2.compareTo(condition1, request);
    assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
    request = createRequest("application/xml", "text/plain");
    result = condition1.compareTo(condition2, request);
    assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
    result = condition2.compareTo(condition1, request);
    assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 79 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method matchWithParameters.

// gh-21670
@Test
public void matchWithParameters() {
    String base = "application/atom+xml";
    ProducesRequestCondition condition = new ProducesRequestCondition(base + ";type=feed");
    HttpServletRequest request = createRequest(base + ";type=entry");
    assertThat(condition.getMatchingCondition(request)).as("Declared parameter value must match if present in request").isNull();
    condition = new ProducesRequestCondition(base + ";type=feed");
    request = createRequest(base + ";type=feed");
    assertThat(condition.getMatchingCondition(request)).as("Declared parameter value must match if present in request").isNotNull();
    condition = new ProducesRequestCondition(base + ";type=feed");
    request = createRequest(base);
    assertThat(condition.getMatchingCondition(request)).as("Declared parameter has no impact if not present in request").isNotNull();
    condition = new ProducesRequestCondition(base);
    request = createRequest(base + ";type=feed");
    assertThat(condition.getMatchingCondition(request)).as("No impact from other parameters in request").isNotNull();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 80 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method matchMultiple.

@Test
public void matchMultiple() {
    ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
    HttpServletRequest request = createRequest("text/plain");
    assertThat(condition.getMatchingCondition(request)).isNotNull();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServletRequest (jakarta.servlet.http.HttpServletRequest)289 Test (org.junit.jupiter.api.Test)160 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)93 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)88 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)67 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)44 Authentication (org.springframework.security.core.Authentication)31 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)31 Test (org.junit.Test)28 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)26 IOException (java.io.IOException)21 ServletException (jakarta.servlet.ServletException)20 HttpServlet (jakarta.servlet.http.HttpServlet)19 HashMap (java.util.HashMap)17 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)16 FilterChain (jakarta.servlet.FilterChain)15 HttpSession (jakarta.servlet.http.HttpSession)14 MockFilterChain (org.springframework.mock.web.MockFilterChain)14 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)14 ServletRequest (jakarta.servlet.ServletRequest)13