Search in sources :

Example 71 with HttpServletRequest

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

the class PatternsRequestConditionTests method compareNumberOfMatchingPatterns.

@Test
void compareNumberOfMatchingPatterns() {
    HttpServletRequest request = initRequest("/foo.html");
    PatternsRequestCondition c1 = new PatternsRequestCondition("/foo.html", "*.jpeg");
    PatternsRequestCondition c2 = new PatternsRequestCondition("/foo.html", "*.html");
    PatternsRequestCondition match1 = c1.getMatchingCondition(request);
    PatternsRequestCondition match2 = c2.getMatchingCondition(request);
    assertThat(match1.compareTo(match2, request)).isEqualTo(1);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 72 with HttpServletRequest

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

the class ProducesRequestConditionTests method compareToWithSingleExpression.

@Test
public void compareToWithSingleExpression() {
    HttpServletRequest request = createRequest("text/plain");
    ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
    ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*");
    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();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 73 with HttpServletRequest

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

the class ProducesRequestConditionTests method matchSingle.

@Test
public void matchSingle() {
    ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
    HttpServletRequest request = createRequest("application/xml");
    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 74 with HttpServletRequest

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

the class ProducesRequestConditionTests method matchByRequestParameter.

@Test
public void matchByRequestParameter() {
    String[] produces = { "text/plain" };
    String[] headers = {};
    ProducesRequestCondition condition = new ProducesRequestCondition(produces, headers);
    HttpServletRequest request = new MockHttpServletRequest("GET", "/foo.txt");
    assertThat(condition.getMatchingCondition(request)).isNotNull();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 75 with HttpServletRequest

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

the class ProducesRequestConditionTests method compareTo.

@Test
public void compareTo() {
    ProducesRequestCondition html = new ProducesRequestCondition("text/html");
    ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
    ProducesRequestCondition none = new ProducesRequestCondition();
    HttpServletRequest request = createRequest("application/xml, text/html");
    assertThat(html.compareTo(xml, request) > 0).isTrue();
    assertThat(xml.compareTo(html, request) < 0).isTrue();
    assertThat(xml.compareTo(none, request) < 0).isTrue();
    assertThat(none.compareTo(xml, request) > 0).isTrue();
    assertThat(html.compareTo(none, request) < 0).isTrue();
    assertThat(none.compareTo(html, request) > 0).isTrue();
    request = createRequest("application/xml, text/*");
    assertThat(html.compareTo(xml, request) > 0).isTrue();
    assertThat(xml.compareTo(html, request) < 0).isTrue();
    request = createRequest("application/pdf");
    assertThat(html.compareTo(xml, request)).isEqualTo(0);
    assertThat(xml.compareTo(html, request)).isEqualTo(0);
    // See SPR-7000
    request = createRequest("text/html;q=0.9,application/xml");
    assertThat(html.compareTo(xml, request) > 0).isTrue();
    assertThat(xml.compareTo(html, request) < 0).isTrue();
}
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