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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations