SPR-7812 Add CustomRequestCondition, PatternsRequestCondition, and other condition related tests
This commit is contained in:
@@ -118,7 +118,7 @@ public class HandlerMethodMappingTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> getMappingPaths(String key) {
|
||||
protected Set<String> getMappingPathPatterns(String key) {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.condition;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class PatternsRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void prependSlash() {
|
||||
PatternsRequestCondition c = new PatternsRequestCondition("foo");
|
||||
assertEquals("/foo", c.getPatterns().iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prependNonEmptyPatternsOnly() {
|
||||
PatternsRequestCondition c = new PatternsRequestCondition("");
|
||||
assertEquals("Do not prepend empty patterns (SPR-8255)", "", c.getPatterns().iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combineEmptySets() {
|
||||
PatternsRequestCondition c1 = new PatternsRequestCondition();
|
||||
PatternsRequestCondition c2 = new PatternsRequestCondition();
|
||||
|
||||
assertEquals(new PatternsRequestCondition(""), c1.combine(c2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combineOnePatternWithEmptySet() {
|
||||
PatternsRequestCondition c1 = new PatternsRequestCondition("/type1", "/type2");
|
||||
PatternsRequestCondition c2 = new PatternsRequestCondition();
|
||||
|
||||
assertEquals(new PatternsRequestCondition("/type1", "/type2"), c1.combine(c2));
|
||||
|
||||
c1 = new PatternsRequestCondition();
|
||||
c2 = new PatternsRequestCondition("/method1", "/method2");
|
||||
|
||||
assertEquals(new PatternsRequestCondition("/method1", "/method2"), c1.combine(c2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combineMultiplePatterns() {
|
||||
PatternsRequestCondition c1 = new PatternsRequestCondition("/t1", "/t2");
|
||||
PatternsRequestCondition c2 = new PatternsRequestCondition("/m1", "/m2");
|
||||
|
||||
assertEquals(new PatternsRequestCondition("/t1/m1", "/t1/m2", "/t2/m1", "/t2/m2"), c1.combine(c2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchDirectPath() {
|
||||
PatternsRequestCondition condition = new PatternsRequestCondition("/foo");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo"));
|
||||
|
||||
assertNotNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchPattern() {
|
||||
PatternsRequestCondition condition = new PatternsRequestCondition("/foo/*");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo/bar"));
|
||||
|
||||
assertNotNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchSortPatterns() {
|
||||
PatternsRequestCondition condition = new PatternsRequestCondition("/**", "/foo/bar", "/foo/*");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo/bar"));
|
||||
PatternsRequestCondition expected = new PatternsRequestCondition("/foo/bar", "/foo/*", "/**");
|
||||
|
||||
assertEquals(expected, match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchImplicitByExtension() {
|
||||
PatternsRequestCondition condition = new PatternsRequestCondition("/foo");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo.html"));
|
||||
|
||||
assertNotNull(match);
|
||||
assertEquals("/foo.*", match.getPatterns().iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchImplicitTrailingSlash() {
|
||||
PatternsRequestCondition condition = new PatternsRequestCondition("/foo");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo/"));
|
||||
|
||||
assertNotNull(match);
|
||||
assertEquals("/foo/", match.getPatterns().iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchPatternContainsExtension() {
|
||||
PatternsRequestCondition condition = new PatternsRequestCondition("/foo.jpg");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(new MockHttpServletRequest("GET", "/foo.html"));
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareEqualPatterns() {
|
||||
PatternsRequestCondition c1 = new PatternsRequestCondition("/foo*");
|
||||
PatternsRequestCondition c2 = new PatternsRequestCondition("/foo*");
|
||||
|
||||
assertEquals(0, c1.compareTo(c2, new MockHttpServletRequest("GET", "/foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comparePatternSpecificity() {
|
||||
PatternsRequestCondition c1 = new PatternsRequestCondition("/fo*");
|
||||
PatternsRequestCondition c2 = new PatternsRequestCondition("/foo");
|
||||
|
||||
assertEquals(1, c1.compareTo(c2, new MockHttpServletRequest("GET", "/foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareNumberOfMatchingPatterns() throws Exception {
|
||||
HttpServletRequest request = new MockHttpServletRequest("GET", "/foo.html");
|
||||
|
||||
PatternsRequestCondition c1 = new PatternsRequestCondition("/foo", "*.jpeg");
|
||||
PatternsRequestCondition c2 = new PatternsRequestCondition("/foo", "*.html");
|
||||
|
||||
PatternsRequestCondition match1 = c1.getMatchingCondition(request);
|
||||
PatternsRequestCondition match2 = c2.getMatchingCondition(request);
|
||||
|
||||
assertEquals(1, match1.compareTo(match2, request));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.ProduceMediaTypeExpression;
|
||||
|
||||
/**
|
||||
@@ -84,6 +83,42 @@ public class ProducesRequestConditionTests {
|
||||
assertNull(condition.getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo() {
|
||||
ProducesRequestCondition html = new ProducesRequestCondition("text/html");
|
||||
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
|
||||
ProducesRequestCondition none = new ProducesRequestCondition();
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "application/xml, text/html");
|
||||
|
||||
assertTrue(html.compareTo(xml, request) > 0);
|
||||
assertTrue(xml.compareTo(html, request) < 0);
|
||||
assertTrue(xml.compareTo(none, request) < 0);
|
||||
assertTrue(none.compareTo(xml, request) > 0);
|
||||
assertTrue(html.compareTo(none, request) < 0);
|
||||
assertTrue(none.compareTo(html, request) > 0);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "application/xml, text/*");
|
||||
|
||||
assertTrue(html.compareTo(xml, request) > 0);
|
||||
assertTrue(xml.compareTo(html, request) < 0);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "application/pdf");
|
||||
|
||||
assertTrue(html.compareTo(xml, request) == 0);
|
||||
assertTrue(xml.compareTo(html, request) == 0);
|
||||
|
||||
// See SPR-7000
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "text/html;q=0.9,application/xml");
|
||||
|
||||
assertTrue(html.compareTo(xml, request) > 0);
|
||||
assertTrue(xml.compareTo(html, request) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareToSingle() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -151,7 +186,7 @@ public class ProducesRequestConditionTests {
|
||||
result = condition2.compareTo(condition1, request);
|
||||
assertTrue("Invalid comparison result: " + result, result < 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void combine() {
|
||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||
@@ -212,12 +247,6 @@ public class ProducesRequestConditionTests {
|
||||
fail("Condition [" + s + "] not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.condition;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -56,6 +57,14 @@ public class RequestMethodsRequestConditionTests {
|
||||
assertNotNull(condition.getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noMethodsMatchAll() {
|
||||
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("GET", "")));
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("POST", "")));
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("HEAD", "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo() {
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class CustomRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void combineEmpty() {
|
||||
CustomRequestCondition empty = new CustomRequestCondition();
|
||||
CustomRequestCondition custom = new CustomRequestCondition(new ParamsRequestCondition("name"));
|
||||
|
||||
assertSame(empty, empty.combine(new CustomRequestCondition()));
|
||||
assertSame(custom, custom.combine(empty));
|
||||
assertSame(custom, empty.combine(custom));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combine() {
|
||||
CustomRequestCondition params1 = new CustomRequestCondition(new ParamsRequestCondition("name1"));
|
||||
CustomRequestCondition params2 = new CustomRequestCondition(new ParamsRequestCondition("name2"));
|
||||
CustomRequestCondition expected = new CustomRequestCondition(new ParamsRequestCondition("name1", "name2"));
|
||||
|
||||
assertEquals(expected, params1.combine(params2));
|
||||
}
|
||||
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void combineIncompatible() {
|
||||
CustomRequestCondition params = new CustomRequestCondition(new ParamsRequestCondition("name"));
|
||||
CustomRequestCondition headers = new CustomRequestCondition(new HeadersRequestCondition("name"));
|
||||
params.combine(headers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void match() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
request.setParameter("name1", "value1");
|
||||
|
||||
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
|
||||
CustomRequestCondition custom = new CustomRequestCondition(rm);
|
||||
RequestMethodsRequestCondition expected = new RequestMethodsRequestCondition(RequestMethod.GET);
|
||||
|
||||
assertEquals(expected, custom.getMatchingCondition(request).getCondition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchEmpty() {
|
||||
CustomRequestCondition empty = new CustomRequestCondition();
|
||||
assertSame(empty, empty.getMatchingCondition(new MockHttpServletRequest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compare() {
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
CustomRequestCondition params11 = new CustomRequestCondition(new ParamsRequestCondition("1"));
|
||||
CustomRequestCondition params12 = new CustomRequestCondition(new ParamsRequestCondition("1", "2"));
|
||||
|
||||
assertEquals(1, params11.compareTo(params12, request));
|
||||
assertEquals(-1, params12.compareTo(params11, request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareEmpty() {
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
CustomRequestCondition empty = new CustomRequestCondition();
|
||||
CustomRequestCondition empty2 = new CustomRequestCondition();
|
||||
CustomRequestCondition custom = new CustomRequestCondition(new ParamsRequestCondition("name"));
|
||||
|
||||
assertEquals(0, empty.compareTo(empty2, request));
|
||||
assertEquals(-1, custom.compareTo(empty, request));
|
||||
assertEquals(1, empty.compareTo(custom, request));
|
||||
}
|
||||
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void compareIncompatible() {
|
||||
CustomRequestCondition params = new CustomRequestCondition(new ParamsRequestCondition("name"));
|
||||
CustomRequestCondition headers = new CustomRequestCondition(new HeadersRequestCondition("name"));
|
||||
params.compareTo(headers, new MockHttpServletRequest());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,167 +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;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link RequestMappingHandlerMapping} testing its {@link RequestMappingInfo} comparator.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class RequestMappingInfoComparatorTests {
|
||||
|
||||
private TestRequestMappingInfoHandlerMapping handlerMapping;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
|
||||
this.request = new MockHttpServletRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreSpecificPatternWins() {
|
||||
request.setRequestURI("/foo");
|
||||
Comparator<RequestMappingInfo> comparator = handlerMapping.getMappingComparator(request);
|
||||
RequestMappingInfo key1 = new RequestMappingInfo(new String[]{"/fo*"});
|
||||
RequestMappingInfo key2 = new RequestMappingInfo(new String[]{"/foo"});
|
||||
|
||||
assertEquals(1, comparator.compare(key1, key2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalPatterns() {
|
||||
request.setRequestURI("/foo");
|
||||
Comparator<RequestMappingInfo> comparator = handlerMapping.getMappingComparator(request);
|
||||
RequestMappingInfo key1 = new RequestMappingInfo(new String[]{"/foo*"});
|
||||
RequestMappingInfo key2 = new RequestMappingInfo(new String[]{"/foo*"});
|
||||
|
||||
assertEquals(0, comparator.compare(key1, key2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greaterNumberOfMatchingPatternsWins() throws Exception {
|
||||
request.setRequestURI("/foo.html");
|
||||
RequestMappingInfo key1 = new RequestMappingInfo(new String[]{"/foo", "*.jpeg"});
|
||||
RequestMappingInfo key2 = new RequestMappingInfo(new String[]{"/foo", "*.html"});
|
||||
RequestMappingInfo match1 = handlerMapping.getMatchingMapping(key1, request);
|
||||
RequestMappingInfo match2 = handlerMapping.getMatchingMapping(key2, request);
|
||||
List<RequestMappingInfo> matches = asList(match1, match2);
|
||||
Collections.sort(matches, handlerMapping.getMappingComparator(request));
|
||||
|
||||
assertSame(match2.getPatternsCondition(), matches.get(0).getPatternsCondition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneMethodWinsOverNone() {
|
||||
Comparator<RequestMappingInfo> comparator = handlerMapping.getMappingComparator(request);
|
||||
RequestMappingInfo key1 = new RequestMappingInfo(null);
|
||||
RequestMappingInfo key2 = new RequestMappingInfo(null, new RequestMethod[] {RequestMethod.GET});
|
||||
|
||||
assertEquals(1, comparator.compare(key1, key2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodsAndParams() {
|
||||
RequestMappingInfo empty = new RequestMappingInfo(null);
|
||||
RequestMappingInfo oneMethod = new RequestMappingInfo(null, new RequestMethod[] {RequestMethod.GET});
|
||||
RequestMappingInfo oneMethodOneParam =
|
||||
new RequestMappingInfo(null, new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo"), null, null, null);
|
||||
List<RequestMappingInfo> list = asList(empty, oneMethod, oneMethodOneParam);
|
||||
Collections.shuffle(list);
|
||||
Collections.sort(list, handlerMapping.getMappingComparator(request));
|
||||
|
||||
assertEquals(oneMethodOneParam, list.get(0));
|
||||
assertEquals(oneMethod, list.get(1));
|
||||
assertEquals(empty, list.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void produces() {
|
||||
RequestMappingInfo html = new RequestMappingInfo(null, null, null, null, null, new ProducesRequestCondition("text/html"));
|
||||
RequestMappingInfo xml = new RequestMappingInfo(null, null, null, null, null, new ProducesRequestCondition("application/xml"));
|
||||
RequestMappingInfo none = new RequestMappingInfo(null);
|
||||
|
||||
request.addHeader("Accept", "application/xml, text/html");
|
||||
Comparator<RequestMappingInfo> comparator = handlerMapping.getMappingComparator(request);
|
||||
|
||||
int result = comparator.compare(html, xml);
|
||||
assertTrue("Invalid comparison result: " + result, result > 0);
|
||||
assertTrue(comparator.compare(xml, html) < 0);
|
||||
assertTrue(comparator.compare(xml, none) < 0);
|
||||
assertTrue(comparator.compare(none, xml) > 0);
|
||||
assertTrue(comparator.compare(html, none) < 0);
|
||||
assertTrue(comparator.compare(none, html) > 0);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "application/xml, text/*");
|
||||
comparator = handlerMapping.getMappingComparator(request);
|
||||
|
||||
assertTrue(comparator.compare(html, xml) > 0);
|
||||
assertTrue(comparator.compare(xml, html) < 0);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "application/pdf");
|
||||
comparator = handlerMapping.getMappingComparator(request);
|
||||
|
||||
assertTrue(comparator.compare(html, xml) == 0);
|
||||
assertTrue(comparator.compare(xml, html) == 0);
|
||||
|
||||
// See SPR-7000
|
||||
request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept", "text/html;q=0.9,application/xml");
|
||||
comparator = handlerMapping.getMappingComparator(request);
|
||||
|
||||
assertTrue(comparator.compare(html, xml) > 0);
|
||||
assertTrue(comparator.compare(xml, html) < 0);
|
||||
}
|
||||
|
||||
private static class TestRequestMappingInfoHandlerMapping extends RequestMappingInfoHandlerMapping {
|
||||
|
||||
@Override
|
||||
protected boolean isHandler(Class<?> beanType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,10 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -85,6 +88,16 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
mapping.setApplicationContext(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMappingPathPatterns() throws Exception {
|
||||
RequestMappingInfo info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo/*", "/foo", "/bar/*", "/bar"), null, null, null, null, null, null);
|
||||
Set<String> paths = mapping.getMappingPathPatterns(info);
|
||||
HashSet<String> expected = new HashSet<String>(Arrays.asList("/foo/*", "/foo", "/bar/*", "/bar"));
|
||||
|
||||
assertEquals(expected, paths);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directMatch() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
@@ -132,7 +145,8 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
public void uriTemplateVariables() {
|
||||
RequestMappingInfo key = new RequestMappingInfo(new String[] {"/{path1}/{path2}"});
|
||||
PatternsRequestCondition patterns = new PatternsRequestCondition("/{path1}/{path2}");
|
||||
RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
|
||||
String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
|
||||
|
||||
@@ -206,7 +220,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
new ParamsRequestCondition(annotation.params()),
|
||||
new HeadersRequestCondition(annotation.headers()),
|
||||
new ConsumesRequestCondition(annotation.consumes(), annotation.headers()),
|
||||
new ProducesRequestCondition(annotation.produces(), annotation.headers()));
|
||||
new ProducesRequestCondition(annotation.produces(), annotation.headers()), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,26 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link RequestMappingInfo} tests.
|
||||
@@ -39,209 +46,276 @@ import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
public class RequestMappingInfoTests {
|
||||
|
||||
@Test
|
||||
public void equals() {
|
||||
RequestMappingInfo key1 = new RequestMappingInfo(new String[] {"/foo"}, GET);
|
||||
RequestMappingInfo key2 = new RequestMappingInfo(new String[] {"/foo"}, GET);
|
||||
|
||||
assertEquals(key1, key2);
|
||||
assertEquals(key1.hashCode(), key2.hashCode());
|
||||
public void createEmpty() {
|
||||
RequestMappingInfo info = new RequestMappingInfo(null, null, null, null, null, null, null);
|
||||
|
||||
assertEquals(0, info.getPatternsCondition().getPatterns().size());
|
||||
assertEquals(0, info.getMethodsCondition().getMethods().size());
|
||||
assertEquals(0, info.getConsumesCondition().getMediaTypes().size());
|
||||
assertEquals(0, info.getProducesCondition().getMediaTypes().size());
|
||||
assertNotNull(info.getParamsCondition());
|
||||
assertNotNull(info.getHeadersCondition());
|
||||
assertNull(info.getCustomCondition());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void equalsPrependSlash() {
|
||||
RequestMappingInfo key1 = new RequestMappingInfo(new String[] {"/foo"}, GET);
|
||||
RequestMappingInfo key2 = new RequestMappingInfo(new String[] {"foo"}, GET);
|
||||
|
||||
assertEquals(key1, key2);
|
||||
assertEquals(key1.hashCode(), key2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combinePatterns() {
|
||||
RequestMappingInfo key1 = createFromPatterns("/t1", "/t2");
|
||||
RequestMappingInfo key2 = createFromPatterns("/m1", "/m2");
|
||||
RequestMappingInfo key3 = createFromPatterns("/t1/m1", "/t1/m2", "/t2/m1", "/t2/m2");
|
||||
assertEquals(key3.getPatternsCondition(), key1.combine(key2).getPatternsCondition());
|
||||
|
||||
key1 = createFromPatterns("/t1");
|
||||
key2 = createFromPatterns();
|
||||
key3 = createFromPatterns("/t1");
|
||||
assertEquals(key3.getPatternsCondition(), key1.combine(key2).getPatternsCondition());
|
||||
|
||||
key1 = createFromPatterns();
|
||||
key2 = createFromPatterns("/m1");
|
||||
key3 = createFromPatterns("/m1");
|
||||
assertEquals(key3.getPatternsCondition(), key1.combine(key2).getPatternsCondition());
|
||||
|
||||
key1 = createFromPatterns();
|
||||
key2 = createFromPatterns();
|
||||
key3 = createFromPatterns("");
|
||||
assertEquals(key3.getPatternsCondition(), key1.combine(key2).getPatternsCondition());
|
||||
|
||||
key1 = createFromPatterns("/t1");
|
||||
key2 = createFromPatterns("");
|
||||
key3 = createFromPatterns("/t1");
|
||||
assertEquals(key3.getPatternsCondition(), key1.combine(key2).getPatternsCondition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchPatternsToRequest() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
RequestMappingInfo match = createFromPatterns("/foo").getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/foo/bar");
|
||||
match = createFromPatterns("/foo/*").getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNotNull("Pattern match", match);
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/foo.html");
|
||||
match = createFromPatterns("/foo").getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNotNull("Implicit match by extension", match);
|
||||
assertEquals("Contains matched pattern", "/foo.*", match.getPatternsCondition().getPatterns().iterator().next());
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/foo/");
|
||||
match = createFromPatterns("/foo").getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNotNull("Implicit match by trailing slash", match);
|
||||
assertEquals("Contains matched pattern", "/foo/", match.getPatternsCondition().getPatterns().iterator().next());
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/foo.html");
|
||||
match = createFromPatterns("/foo.jpg").getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNull("Implicit match ignored if pattern has extension", match);
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/foo.html");
|
||||
match = createFromPatterns("/foo.jpg").getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNull("Implicit match ignored on pattern with trailing slash", match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchRequestMethods() {
|
||||
public void matchPatternsCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
|
||||
RequestMappingInfo key = createFromPatterns("/foo");
|
||||
RequestMappingInfo match = createFromPatterns("/foo").getMatchingRequestMappingInfo(request);
|
||||
RequestMappingInfo info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo*", "/bar"), null, null, null, null, null, null);
|
||||
RequestMappingInfo expected = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo*"), null, null, null, null, null, null);
|
||||
|
||||
assertEquals(expected, info.getMatchingInfo(request));
|
||||
|
||||
assertNotNull("No method matches any method", match);
|
||||
|
||||
key = new RequestMappingInfo(new String[]{"/foo"}, GET);
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNotNull("Exact match", match);
|
||||
|
||||
key = new RequestMappingInfo(new String[]{"/foo"}, POST);
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
|
||||
assertNull("No match", match);
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/**", "/foo*", "/foo"), null, null, null, null, null, null);
|
||||
expected = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo", "/foo*", "/**"), null, null, null, null, null, null);
|
||||
|
||||
assertEquals(expected, info.getMatchingInfo(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchingKeyContent() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
|
||||
RequestMappingInfo key = new RequestMappingInfo(new String[] {"/foo*", "/bar"}, GET, POST);
|
||||
RequestMappingInfo match = key.getMatchingRequestMappingInfo(request);
|
||||
RequestMappingInfo expected = new RequestMappingInfo(new String[] {"/foo*"}, GET);
|
||||
|
||||
assertEquals("Matching RequestKey contains matched patterns and methods only", expected, match);
|
||||
|
||||
key = createFromPatterns("/**", "/foo*", "/foo");
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
expected = createFromPatterns("/foo", "/foo*", "/**");
|
||||
|
||||
assertEquals("Matched patterns are sorted with best match at the top", expected, match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramsCondition() {
|
||||
public void matchParamsCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.setParameter("foo", "bar");
|
||||
|
||||
RequestMappingInfo key =
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo=bar"), null, null, null);
|
||||
RequestMappingInfo match = key.getMatchingRequestMappingInfo(request);
|
||||
new ParamsRequestCondition("foo=bar"), null, null, null, null);
|
||||
RequestMappingInfo match = info.getMatchingInfo(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
key = new RequestMappingInfo(
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo!=bar"), null, null, null);
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
new ParamsRequestCondition("foo!=bar"), null, null, null, null);
|
||||
match = info.getMatchingInfo(request);
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headersCondition() {
|
||||
public void matchHeadersCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.addHeader("foo", "bar");
|
||||
|
||||
RequestMappingInfo key =
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null,
|
||||
new HeadersRequestCondition("foo=bar"), null, null);
|
||||
RequestMappingInfo match = key.getMatchingRequestMappingInfo(request);
|
||||
new HeadersRequestCondition("foo=bar"), null, null, null);
|
||||
RequestMappingInfo match = info.getMatchingInfo(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
key = new RequestMappingInfo(
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null,
|
||||
new HeadersRequestCondition("foo!=bar"), null, null);
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
new HeadersRequestCondition("foo!=bar"), null, null, null);
|
||||
match = info.getMatchingInfo(request);
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consumesCondition() {
|
||||
public void matchConsumesCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.setContentType("text/plain");
|
||||
|
||||
RequestMappingInfo key =
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null,
|
||||
new ConsumesRequestCondition("text/plain"), null);
|
||||
RequestMappingInfo match = key.getMatchingRequestMappingInfo(request);
|
||||
new ConsumesRequestCondition("text/plain"), null, null);
|
||||
RequestMappingInfo match = info.getMatchingInfo(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
key = new RequestMappingInfo(
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null,
|
||||
new ConsumesRequestCondition("application/xml"), null);
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
new ConsumesRequestCondition("application/xml"), null, null);
|
||||
match = info.getMatchingInfo(request);
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void producesCondition() {
|
||||
public void matchProducesCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.addHeader("Accept", "text/plain");
|
||||
|
||||
RequestMappingInfo key =
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null,
|
||||
new ProducesRequestCondition("text/plain"));
|
||||
RequestMappingInfo match = key.getMatchingRequestMappingInfo(request);
|
||||
new ProducesRequestCondition("text/plain"), null);
|
||||
RequestMappingInfo match = info.getMatchingInfo(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
key = new RequestMappingInfo(
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null,
|
||||
new ProducesRequestCondition("application/xml"));
|
||||
match = key.getMatchingRequestMappingInfo(request);
|
||||
new ProducesRequestCondition("application/xml"), null);
|
||||
match = info.getMatchingInfo(request);
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
private RequestMappingInfo createFromPatterns(String... patterns) {
|
||||
return new RequestMappingInfo(patterns);
|
||||
@Test
|
||||
public void matchCustomCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.setParameter("foo", "bar");
|
||||
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null, null,
|
||||
new ParamsRequestCondition("foo=bar"));
|
||||
RequestMappingInfo match = info.getMatchingInfo(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo!=bar"), null, null, null,
|
||||
new ParamsRequestCondition("foo!=bar"));
|
||||
match = info.getMatchingInfo(request);
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTwoHttpMethodsOneParam() {
|
||||
RequestMappingInfo none = new RequestMappingInfo(null, null, null, null, null, null, null);
|
||||
RequestMappingInfo oneMethod =
|
||||
new RequestMappingInfo(null,
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET), null, null, null, null, null);
|
||||
RequestMappingInfo oneMethodOneParam =
|
||||
new RequestMappingInfo(null,
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo"), null, null, null, null);
|
||||
|
||||
Comparator<RequestMappingInfo> comparator = new Comparator<RequestMappingInfo>() {
|
||||
public int compare(RequestMappingInfo info, RequestMappingInfo otherInfo) {
|
||||
return info.compareTo(otherInfo, new MockHttpServletRequest());
|
||||
}
|
||||
};
|
||||
|
||||
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
|
||||
Collections.shuffle(list);
|
||||
Collections.sort(list, comparator);
|
||||
|
||||
assertEquals(oneMethodOneParam, list.get(0));
|
||||
assertEquals(oneMethod, list.get(1));
|
||||
assertEquals(none, list.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals() {
|
||||
|
||||
RequestMappingInfo info1 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
RequestMappingInfo info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertEquals(info1, info2);
|
||||
assertEquals(info1.hashCode(), info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo", "/NOOOOOO"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("/NOOOOOO"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("/NOOOOOO"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/NOOOOOO"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/NOOOOOO"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=NOOOOOO"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user