Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4279 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/merge
21 changed files with 1030 additions and 791 deletions
@ -1,41 +0,0 @@
@@ -1,41 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
/** |
||||
* Abstract base class for {@link RequestCondition} that provides a standard {@link Comparable} implementation based on |
||||
* the conditions {@linkplain #getSpecificity() specificity}. |
||||
* |
||||
* @author Arjen Poutsma |
||||
* @since 3.1 |
||||
*/ |
||||
public abstract class AbstractRequestCondition implements RequestCondition { |
||||
|
||||
/** |
||||
* Returns the conditions specificity. More specific conditions should return a higher value than ones which are less |
||||
* so. |
||||
* |
||||
* @return the conditions specificity |
||||
*/ |
||||
protected abstract int getSpecificity(); |
||||
|
||||
public int compareTo(RequestCondition o) { |
||||
AbstractRequestCondition other = (AbstractRequestCondition) o; |
||||
return other.getSpecificity() - this.getSpecificity(); |
||||
} |
||||
|
||||
} |
||||
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
/** |
||||
* Request header name-value condition. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @author Arjen Poutsma |
||||
* @see org.springframework.web.bind.annotation.RequestMapping#headers() |
||||
* @since 3.1 |
||||
*/ |
||||
class HeaderRequestCondition extends AbstractNameValueCondition<String> { |
||||
|
||||
public HeaderRequestCondition(String expression) { |
||||
super(expression); |
||||
} |
||||
|
||||
@Override |
||||
protected String parseValue(String valueExpression) { |
||||
return valueExpression; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchName(HttpServletRequest request) { |
||||
return request.getHeader(name) != null; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchValue(HttpServletRequest request) { |
||||
return value.equals(request.getHeader(name)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (obj != null && obj instanceof HeaderRequestCondition) { |
||||
HeaderRequestCondition other = (HeaderRequestCondition) obj; |
||||
return ((this.name.equalsIgnoreCase(other.name)) && |
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) && |
||||
this.isNegated == other.isNegated); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,134 @@
@@ -0,0 +1,134 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Collection; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashSet; |
||||
import java.util.Set; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
/** |
||||
* Represents a collection of header request conditions, typically obtained from {@link |
||||
* org.springframework.web.bind.annotation.RequestMapping#headers() @RequestMapping.headers()}. |
||||
* |
||||
* @author Arjen Poutsma |
||||
* @see RequestConditionFactory#parseHeaders(String...) |
||||
* @since 3.1 |
||||
*/ |
||||
public class HeadersRequestCondition |
||||
extends LogicalConjunctionRequestCondition<HeadersRequestCondition.HeaderRequestCondition> |
||||
implements Comparable<HeadersRequestCondition> { |
||||
|
||||
HeadersRequestCondition(Collection<HeaderRequestCondition> conditions) { |
||||
super(conditions); |
||||
} |
||||
|
||||
HeadersRequestCondition(String... headers) { |
||||
this(parseConditions(Arrays.asList(headers))); |
||||
} |
||||
|
||||
private static Set<HeaderRequestCondition> parseConditions(Collection<String> params) { |
||||
Set<HeaderRequestCondition> conditions = new LinkedHashSet<HeaderRequestCondition>(params.size()); |
||||
for (String param : params) { |
||||
conditions.add(new HeaderRequestCondition(param)); |
||||
} |
||||
return conditions; |
||||
} |
||||
|
||||
/** |
||||
* Creates an empty set of header request conditions. |
||||
*/ |
||||
public HeadersRequestCondition() { |
||||
this(Collections.<HeaderRequestCondition>emptySet()); |
||||
} |
||||
|
||||
/** |
||||
* Returns a new {@code RequestCondition} that contains all conditions of this key that match the request. |
||||
* |
||||
* @param request the request |
||||
* @return a new request condition that contains all matching attributes, or {@code null} if not all conditions match |
||||
*/ |
||||
public HeadersRequestCondition getMatchingCondition(HttpServletRequest request) { |
||||
return match(request) ? this : null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Combines this collection of request condition with another by combining all header request conditions into a |
||||
* logical AND. |
||||
* |
||||
* @param other the condition to combine with |
||||
*/ |
||||
public HeadersRequestCondition combine(HeadersRequestCondition other) { |
||||
Set<HeaderRequestCondition> conditions = new LinkedHashSet<HeaderRequestCondition>(getConditions()); |
||||
conditions.addAll(other.getConditions()); |
||||
return new HeadersRequestCondition(conditions); |
||||
} |
||||
|
||||
|
||||
public int compareTo(HeadersRequestCondition other) { |
||||
return other.getConditions().size() - this.getConditions().size(); |
||||
} |
||||
|
||||
static class HeaderRequestCondition extends AbstractNameValueCondition<String> { |
||||
|
||||
public HeaderRequestCondition(String expression) { |
||||
super(expression); |
||||
} |
||||
|
||||
@Override |
||||
protected String parseValue(String valueExpression) { |
||||
return valueExpression; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchName(HttpServletRequest request) { |
||||
return request.getHeader(name) != null; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchValue(HttpServletRequest request) { |
||||
return value.equals(request.getHeader(name)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (obj != null && obj instanceof HeaderRequestCondition) { |
||||
HeaderRequestCondition other = (HeaderRequestCondition) obj; |
||||
return ((this.name.equalsIgnoreCase(other.name)) && |
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) && |
||||
this.isNegated == other.isNegated); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int result = name.toLowerCase().hashCode(); |
||||
result = 31 * result + (value != null ? value.hashCode() : 0); |
||||
result = 31 * result + (isNegated ? 1 : 0); |
||||
return result; |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
||||
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* {@link RequestCondition} implementation that represents a logical NOT (i.e. !). |
||||
* |
||||
* @author Arjen Poutsma |
||||
* @since 3.1 |
||||
*/ |
||||
class LogicalNegationRequestCondition extends AbstractRequestCondition { |
||||
|
||||
private final RequestCondition requestCondition; |
||||
|
||||
LogicalNegationRequestCondition(RequestCondition requestCondition) { |
||||
Assert.notNull(requestCondition, "'requestCondition' must not be null"); |
||||
this.requestCondition = requestCondition; |
||||
} |
||||
|
||||
@Override |
||||
protected int getSpecificity() { |
||||
if (requestCondition instanceof AbstractRequestCondition) { |
||||
return ((AbstractRequestCondition) requestCondition).getSpecificity(); |
||||
} |
||||
else { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
public boolean match(HttpServletRequest request) { |
||||
return !requestCondition.match(request); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (o != null && o instanceof LogicalNegationRequestCondition) { |
||||
LogicalNegationRequestCondition other = (LogicalNegationRequestCondition) o; |
||||
return this.requestCondition.equals(other.requestCondition); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return requestCondition.hashCode(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "!(" + requestCondition.toString() + ")"; |
||||
} |
||||
} |
||||
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
import org.springframework.http.MediaType; |
||||
|
||||
/** |
||||
* A RequestCondition that for headers that contain {@link org.springframework.http.MediaType MediaTypes}. |
||||
*/ |
||||
class MediaTypeHeaderRequestCondition extends AbstractNameValueCondition<List<MediaType>> { |
||||
|
||||
public MediaTypeHeaderRequestCondition(String expression) { |
||||
super(expression); |
||||
} |
||||
|
||||
@Override |
||||
protected List<MediaType> parseValue(String valueExpression) { |
||||
return Collections.unmodifiableList(MediaType.parseMediaTypes(valueExpression)); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchName(HttpServletRequest request) { |
||||
return request.getHeader(name) != null; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchValue(HttpServletRequest request) { |
||||
List<MediaType> requestMediaTypes = MediaType.parseMediaTypes(request.getHeader(name)); |
||||
|
||||
for (MediaType mediaType : this.value) { |
||||
for (MediaType requestMediaType : requestMediaTypes) { |
||||
if (mediaType.includes(requestMediaType)) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (obj != null && obj instanceof MediaTypeHeaderRequestCondition) { |
||||
MediaTypeHeaderRequestCondition other = (MediaTypeHeaderRequestCondition) obj; |
||||
return ((this.name.equalsIgnoreCase(other.name)) && |
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) && |
||||
this.isNegated == other.isNegated); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -1,66 +0,0 @@
@@ -1,66 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
import org.springframework.web.util.WebUtils; |
||||
|
||||
/** |
||||
* Request parameter name-value condition. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @author Arjen Poutsma |
||||
* @see org.springframework.web.bind.annotation.RequestMapping#params() |
||||
* @since 3.1 |
||||
*/ |
||||
class ParamRequestCondition extends AbstractNameValueCondition<String> { |
||||
|
||||
ParamRequestCondition(String expression) { |
||||
super(expression); |
||||
} |
||||
|
||||
@Override |
||||
protected String parseValue(String valueExpression) { |
||||
return valueExpression; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchName(HttpServletRequest request) { |
||||
return WebUtils.hasSubmitParameter(request, name); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchValue(HttpServletRequest request) { |
||||
return value.equals(request.getParameter(name)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (obj != null && obj instanceof ParamRequestCondition) { |
||||
ParamRequestCondition other = (ParamRequestCondition) obj; |
||||
return ((this.name.equals(other.name)) && |
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) && |
||||
this.isNegated == other.isNegated); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,126 @@
@@ -0,0 +1,126 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Collection; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashSet; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
import org.springframework.web.util.WebUtils; |
||||
|
||||
/** |
||||
* Represents a collection of parameter request conditions, typically obtained from {@link |
||||
* org.springframework.web.bind.annotation.RequestMapping#params() @RequestMapping.params()}. |
||||
* |
||||
* @author Arjen Poutsma |
||||
* @see RequestConditionFactory#parseParams(String...) |
||||
* @since 3.1 |
||||
*/ |
||||
public class ParamsRequestCondition |
||||
extends LogicalConjunctionRequestCondition<ParamsRequestCondition.ParamRequestCondition> |
||||
implements Comparable<ParamsRequestCondition> { |
||||
|
||||
private ParamsRequestCondition(Collection<ParamRequestCondition> conditions) { |
||||
super(conditions); |
||||
} |
||||
|
||||
ParamsRequestCondition(String... params) { |
||||
this(parseConditions(Arrays.asList(params))); |
||||
} |
||||
|
||||
private static Set<ParamRequestCondition> parseConditions(List<String> params) { |
||||
Set<ParamRequestCondition> conditions = new LinkedHashSet<ParamRequestCondition>(params.size()); |
||||
for (String param : params) { |
||||
conditions.add(new ParamRequestCondition(param)); |
||||
} |
||||
return conditions; |
||||
} |
||||
|
||||
/** |
||||
* Creates an empty set of parameter request conditions. |
||||
*/ |
||||
public ParamsRequestCondition() { |
||||
this(Collections.<ParamRequestCondition>emptySet()); |
||||
} |
||||
|
||||
/** |
||||
* Returns a new {@code RequestCondition} that contains all conditions of this key that match the request. |
||||
* |
||||
* @param request the request |
||||
* @return a new request condition that contains all matching attributes, or {@code null} if not all conditions match |
||||
*/ |
||||
public ParamsRequestCondition getMatchingCondition(HttpServletRequest request) { |
||||
return match(request) ? this : null; |
||||
} |
||||
|
||||
/** |
||||
* Combines this collection of request condition with another by combining all parameter request conditions into a |
||||
* logical AND. |
||||
* |
||||
* @param other the condition to combine with |
||||
*/ |
||||
public ParamsRequestCondition combine(ParamsRequestCondition other) { |
||||
Set<ParamRequestCondition> conditions = new LinkedHashSet<ParamRequestCondition>(getConditions()); |
||||
conditions.addAll(other.getConditions()); |
||||
return new ParamsRequestCondition(conditions); |
||||
} |
||||
|
||||
public int compareTo(ParamsRequestCondition other) { |
||||
return other.getConditions().size() - this.getConditions().size(); |
||||
} |
||||
|
||||
static class ParamRequestCondition extends AbstractNameValueCondition<String> { |
||||
|
||||
ParamRequestCondition(String expression) { |
||||
super(expression); |
||||
} |
||||
|
||||
@Override |
||||
protected String parseValue(String valueExpression) { |
||||
return valueExpression; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchName(HttpServletRequest request) { |
||||
return WebUtils.hasSubmitParameter(request, name); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean matchValue(HttpServletRequest request) { |
||||
return value.equals(request.getParameter(name)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (obj != null && obj instanceof ParamRequestCondition) { |
||||
ParamRequestCondition other = (ParamRequestCondition) obj; |
||||
return ((this.name.equals(other.name)) && |
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) && |
||||
this.isNegated == other.isNegated); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,192 @@
@@ -0,0 +1,192 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import java.util.Set; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Arjen Poutsma |
||||
*/ |
||||
public class ConsumesRequestConditionTests { |
||||
|
||||
@Test |
||||
public void consumesMatch() { |
||||
RequestCondition condition = new ConsumesRequestCondition("text/plain"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void negatedConsumesMatch() { |
||||
RequestCondition condition = new ConsumesRequestCondition("!text/plain"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesWildcardMatch() { |
||||
RequestCondition condition = new ConsumesRequestCondition("text/*"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesMultipleMatch() { |
||||
RequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesSingleNoMatch() { |
||||
RequestCondition condition = new ConsumesRequestCondition("text/plain"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("application/xml"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void compareToSingle() { |
||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain"); |
||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*"); |
||||
|
||||
int result = condition1.compareTo(condition2); |
||||
assertTrue("Invalid comparison result: " + result, result < 0); |
||||
|
||||
result = condition2.compareTo(condition1); |
||||
assertTrue("Invalid comparison result: " + result, result > 0); |
||||
} |
||||
|
||||
@Test |
||||
public void compareToMultiple() { |
||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain"); |
||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*", "text/plain;q=0.7"); |
||||
|
||||
int result = condition1.compareTo(condition2); |
||||
assertTrue("Invalid comparison result: " + result, result < 0); |
||||
|
||||
result = condition2.compareTo(condition1); |
||||
assertTrue("Invalid comparison result: " + result, result > 0); |
||||
} |
||||
|
||||
|
||||
@Test |
||||
public void combine() { |
||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain"); |
||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("application/xml"); |
||||
|
||||
ConsumesRequestCondition result = condition1.combine(condition2); |
||||
assertEquals(condition2, result); |
||||
} |
||||
|
||||
@Test |
||||
public void combineWithDefault() { |
||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain"); |
||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("*/*"); |
||||
|
||||
ConsumesRequestCondition result = condition1.combine(condition2); |
||||
assertEquals(condition1, result); |
||||
} |
||||
|
||||
@Test |
||||
public void parseConsumesAndHeaders() { |
||||
String[] consumes = new String[] {"text/plain"}; |
||||
String[] headers = new String[]{"foo=bar", "content-type=application/xml,application/pdf"}; |
||||
ConsumesRequestCondition condition = RequestConditionFactory.parseConsumes(consumes, headers); |
||||
|
||||
assertConditions(condition, "text/plain", "application/xml", "application/pdf"); |
||||
} |
||||
|
||||
@Test |
||||
public void parseConsumesDefault() { |
||||
String[] consumes = new String[] {"*/*"}; |
||||
String[] headers = new String[0]; |
||||
ConsumesRequestCondition condition = RequestConditionFactory.parseConsumes(consumes, headers); |
||||
|
||||
assertConditions(condition, "*/*"); |
||||
} |
||||
@Test |
||||
public void parseConsumesDefaultAndHeaders() { |
||||
String[] consumes = new String[] {"*/*"}; |
||||
String[] headers = new String[]{"foo=bar", "content-type=text/plain"}; |
||||
ConsumesRequestCondition condition = RequestConditionFactory.parseConsumes(consumes, headers); |
||||
|
||||
assertConditions(condition, "text/plain"); |
||||
} |
||||
|
||||
@Test |
||||
public void getMatchingCondition() { |
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml"); |
||||
|
||||
ConsumesRequestCondition result = condition.getMatchingCondition(request); |
||||
assertConditions(result, "text/plain"); |
||||
|
||||
condition = new ConsumesRequestCondition("application/xml"); |
||||
|
||||
result = condition.getMatchingCondition(request); |
||||
assertNull(result); |
||||
} |
||||
|
||||
private void assertConditions(ConsumesRequestCondition condition, String... expected) { |
||||
Set<ConsumesRequestCondition.ConsumeRequestCondition> conditions = condition.getConditions(); |
||||
assertEquals("Invalid amount of conditions", conditions.size(), expected.length); |
||||
for (String s : expected) { |
||||
boolean found = false; |
||||
for (ConsumesRequestCondition.ConsumeRequestCondition requestCondition : conditions) { |
||||
String conditionMediaType = requestCondition.getMediaType().toString(); |
||||
if (conditionMediaType.equals(s)) { |
||||
found = true; |
||||
break; |
||||
|
||||
} |
||||
} |
||||
if (!found) { |
||||
fail("Condition [" + s + "] not found"); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import java.util.Set; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Arjen Poutsma |
||||
*/ |
||||
public class HeadersRequestConditionTests { |
||||
|
||||
@Test |
||||
public void headerEquals() { |
||||
assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("foo")); |
||||
assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("FOO")); |
||||
assertFalse(new HeadersRequestCondition("foo").equals(new HeadersRequestCondition("bar"))); |
||||
assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("foo=bar")); |
||||
assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("FOO=bar")); |
||||
} |
||||
|
||||
@Test |
||||
public void headerPresent() { |
||||
RequestCondition condition = new HeadersRequestCondition("accept"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("Accept", ""); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerPresentNoMatch() { |
||||
RequestCondition condition = new HeadersRequestCondition("foo"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("bar", ""); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerNotPresent() { |
||||
RequestCondition condition = new HeadersRequestCondition("!accept"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerValueMatch() { |
||||
RequestCondition condition = new HeadersRequestCondition("foo=bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bar"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerValueNoMatch() { |
||||
RequestCondition condition = new HeadersRequestCondition("foo=bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bazz"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerCaseSensitiveValueMatch() { |
||||
RequestCondition condition = new HeadersRequestCondition("foo=Bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bar"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerValueMatchNegated() { |
||||
RequestCondition condition = new HeadersRequestCondition("foo!=bar"); |
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "baz"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void compareTo() { |
||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz"); |
||||
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo", "bar"); |
||||
|
||||
int result = condition1.compareTo(condition2); |
||||
assertTrue("Invalid comparison result: " + result, result < 0); |
||||
|
||||
result = condition2.compareTo(condition1); |
||||
assertTrue("Invalid comparison result: " + result, result > 0); |
||||
} |
||||
|
||||
|
||||
@Test |
||||
public void combine() { |
||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo=bar"); |
||||
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=baz"); |
||||
|
||||
HeadersRequestCondition result = condition1.combine(condition2); |
||||
Set<HeadersRequestCondition.HeaderRequestCondition> conditions = result.getConditions(); |
||||
assertEquals(2, conditions.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getMatchingCondition() { |
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bar"); |
||||
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo"); |
||||
|
||||
HeadersRequestCondition result = condition.getMatchingCondition(request); |
||||
assertEquals(condition, result); |
||||
|
||||
condition = new HeadersRequestCondition("bar"); |
||||
|
||||
result = condition.getMatchingCondition(request); |
||||
assertNull(result); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,129 @@
@@ -0,0 +1,129 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import java.util.Set; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Arjen Poutsma |
||||
*/ |
||||
public class ParamsRequestConditionTests { |
||||
|
||||
@Test |
||||
public void paramEquals() { |
||||
assertEquals(new ParamsRequestCondition("foo"), new ParamsRequestCondition("foo")); |
||||
assertFalse(new ParamsRequestCondition("foo").equals(new ParamsRequestCondition("bar"))); |
||||
assertFalse(new ParamsRequestCondition("foo").equals(new ParamsRequestCondition("FOO"))); |
||||
assertEquals(new ParamsRequestCondition("foo=bar"), new ParamsRequestCondition("foo=bar")); |
||||
assertFalse( |
||||
new ParamsRequestCondition("foo=bar").equals(new ParamsRequestCondition("FOO=bar"))); |
||||
} |
||||
|
||||
@Test |
||||
public void paramPresent() { |
||||
RequestCondition condition = new ParamsRequestCondition("foo"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addParameter("foo", ""); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void paramPresentNoMatch() { |
||||
RequestCondition condition = new ParamsRequestCondition("foo"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("bar", ""); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void paramNotPresent() { |
||||
RequestCondition condition = new ParamsRequestCondition("!foo"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void paramValueMatch() { |
||||
RequestCondition condition = new ParamsRequestCondition("foo=bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addParameter("foo", "bar"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void paramValueNoMatch() { |
||||
RequestCondition condition = new ParamsRequestCondition("foo=bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addParameter("foo", "bazz"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void compareTo() { |
||||
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo", "bar", "baz"); |
||||
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo", "bar"); |
||||
|
||||
int result = condition1.compareTo(condition2); |
||||
assertTrue("Invalid comparison result: " + result, result < 0); |
||||
|
||||
result = condition2.compareTo(condition1); |
||||
assertTrue("Invalid comparison result: " + result, result > 0); |
||||
} |
||||
|
||||
@Test |
||||
public void combine() { |
||||
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo=bar"); |
||||
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo=baz"); |
||||
|
||||
ParamsRequestCondition result = condition1.combine(condition2); |
||||
Set<ParamsRequestCondition.ParamRequestCondition> conditions = result.getConditions(); |
||||
assertEquals(2, conditions.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getMatchingCondition() { |
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addParameter("foo", "bar"); |
||||
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo"); |
||||
|
||||
ParamsRequestCondition result = condition.getMatchingCondition(request); |
||||
assertEquals(condition, result); |
||||
|
||||
condition = new ParamsRequestCondition("bar"); |
||||
|
||||
result = condition.getMatchingCondition(request); |
||||
assertNull(result); |
||||
} |
||||
|
||||
} |
||||
@ -1,212 +0,0 @@
@@ -1,212 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.mvc.method.condition; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Arjen Poutsma |
||||
*/ |
||||
public class RequestConditionFactoryTests { |
||||
|
||||
|
||||
@Test |
||||
public void andMatch() { |
||||
RequestCondition condition1 = RequestConditionFactory.trueCondition(); |
||||
RequestCondition condition2 = RequestConditionFactory.trueCondition(); |
||||
RequestCondition and = RequestConditionFactory.and(condition1, condition2); |
||||
assertTrue(and.match(new MockHttpServletRequest())); |
||||
} |
||||
|
||||
@Test |
||||
public void andNoMatch() { |
||||
RequestCondition condition1 = RequestConditionFactory.trueCondition(); |
||||
RequestCondition condition2 = RequestConditionFactory.falseCondition(); |
||||
RequestCondition and = RequestConditionFactory.and(condition1, condition2); |
||||
assertFalse(and.match(new MockHttpServletRequest())); |
||||
} |
||||
|
||||
@Test |
||||
public void orMatch() { |
||||
RequestCondition condition1 = RequestConditionFactory.trueCondition(); |
||||
RequestCondition condition2 = RequestConditionFactory.falseCondition(); |
||||
RequestCondition and = RequestConditionFactory.or(condition1, condition2); |
||||
assertTrue(and.match(new MockHttpServletRequest())); |
||||
} |
||||
|
||||
@Test |
||||
public void orNoMatch() { |
||||
RequestCondition condition1 = RequestConditionFactory.falseCondition(); |
||||
RequestCondition condition2 = RequestConditionFactory.falseCondition(); |
||||
RequestCondition and = RequestConditionFactory.and(condition1, condition2); |
||||
assertFalse(and.match(new MockHttpServletRequest())); |
||||
} |
||||
|
||||
@Test |
||||
public void paramEquals() { |
||||
assertEquals(RequestConditionFactory.parseParams("foo"), RequestConditionFactory.parseParams("foo")); |
||||
assertFalse(RequestConditionFactory.parseParams("foo").equals(RequestConditionFactory.parseParams("bar"))); |
||||
assertFalse(RequestConditionFactory.parseParams("foo").equals(RequestConditionFactory.parseParams("FOO"))); |
||||
assertEquals(RequestConditionFactory.parseParams("foo=bar"), RequestConditionFactory.parseParams("foo=bar")); |
||||
assertFalse( |
||||
RequestConditionFactory.parseParams("foo=bar").equals(RequestConditionFactory.parseParams("FOO=bar"))); |
||||
} |
||||
|
||||
@Test |
||||
public void headerEquals() { |
||||
assertEquals(RequestConditionFactory.parseHeaders("foo"), RequestConditionFactory.parseHeaders("foo")); |
||||
assertEquals(RequestConditionFactory.parseHeaders("foo"), RequestConditionFactory.parseHeaders("FOO")); |
||||
assertFalse(RequestConditionFactory.parseHeaders("foo").equals(RequestConditionFactory.parseHeaders("bar"))); |
||||
assertEquals(RequestConditionFactory.parseHeaders("foo=bar"), RequestConditionFactory.parseHeaders("foo=bar")); |
||||
assertEquals(RequestConditionFactory.parseHeaders("foo=bar"), RequestConditionFactory.parseHeaders("FOO=bar")); |
||||
assertEquals(RequestConditionFactory.parseHeaders("content-type=text/xml"), |
||||
RequestConditionFactory.parseHeaders("Content-Type=TEXT/XML")); |
||||
} |
||||
|
||||
@Test |
||||
public void headerPresent() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("accept"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("Accept", ""); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerPresentNoMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("foo"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("bar", ""); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerNotPresent() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("!accept"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerValueMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("foo=bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bar"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerValueNoMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("foo=bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bazz"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerCaseSensitiveValueMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("foo=Bar"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "bar"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void headerValueMatchNegated() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("foo!=bar"); |
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("foo", "baz"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void mediaTypeHeaderValueMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("accept=text/html"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("Accept", "text/html"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void mediaTypeHeaderValueMatchNegated() { |
||||
RequestCondition condition = RequestConditionFactory.parseHeaders("accept!=text/html"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.addHeader("Accept", "application/html"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseConsumes("text/plain"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesWildcardMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseConsumes("text/*"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesMultipleMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseConsumes("text/plain", "application/xml"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("text/plain"); |
||||
|
||||
assertTrue(condition.match(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void consumesSingleNoMatch() { |
||||
RequestCondition condition = RequestConditionFactory.parseConsumes("text/plain"); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setContentType("application/xml"); |
||||
|
||||
assertFalse(condition.match(request)); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue