The "consumes" condition compares MediaType parameters
Closes gh-9257
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -88,6 +88,27 @@ public class ConsumesRequestConditionTests {
|
||||
assertThat(condition.getMatchingCondition(request)).isNull();
|
||||
}
|
||||
|
||||
@Test // gh-28024
|
||||
public void matchWithParameters() {
|
||||
String base = "application/hal+json";
|
||||
ConsumesRequestCondition condition = new ConsumesRequestCondition(base + ";profile=\"a\"");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setContentType(base + ";profile=\"a\"");
|
||||
assertThat(condition.getMatchingCondition(request)).isNotNull();
|
||||
|
||||
condition = new ConsumesRequestCondition(base + ";profile=\"a\"");
|
||||
request.setContentType(base + ";profile=\"b\"");
|
||||
assertThat(condition.getMatchingCondition(request)).isNull();
|
||||
|
||||
condition = new ConsumesRequestCondition(base + ";profile=\"a\"");
|
||||
request.setContentType(base);
|
||||
assertThat(condition.getMatchingCondition(request)).isNotNull();
|
||||
|
||||
condition = new ConsumesRequestCondition(base);
|
||||
request.setContentType(base + ";profile=\"a\"");
|
||||
assertThat(condition.getMatchingCondition(request)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consumesParseError() {
|
||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -99,19 +99,19 @@ public class ProducesRequestConditionTests {
|
||||
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();
|
||||
assertThat(condition.getMatchingCondition(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();
|
||||
assertThat(condition.getMatchingCondition(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();
|
||||
assertThat(condition.getMatchingCondition(request)).isNotNull();
|
||||
|
||||
condition = new ProducesRequestCondition(base);
|
||||
request = createRequest(base + ";type=feed");
|
||||
assertThat(condition.getMatchingCondition(request)).as("No impact from other parameters in request").isNotNull();
|
||||
assertThat(condition.getMatchingCondition(request)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user