Integrate suggested support for creating MVC URLs

The key contract is MvcUrls. An instance is automatically created with
the Spring MVC namespace and the MVC Java config but can also be easily
created in any configuration.

Some example tests can be found in DefaultMvcUrlsTests.

Issue: SPR-10665, SPR-8826
This commit is contained in:
Rossen Stoyanchev
2013-10-20 10:01:54 -04:00
parent 4fd27b12fc
commit bafc73f147
33 changed files with 1313 additions and 2088 deletions

View File

@@ -1,72 +0,0 @@
/*
* Copyright 2002-2013 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.core;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* Unit tests for {@link AnnotationAttribute}.
*
* @author Oliver Gierke
*/
public class AnnotationAttributeUnitTests {
AnnotationAttribute valueAttribute = new AnnotationAttribute(MyAnnotation.class);
AnnotationAttribute nonValueAttribute = new AnnotationAttribute(MyAnnotation.class,
"nonValue");
@Test
public void readsAttributesFromType() {
assertThat(valueAttribute.findValueOn(Sample.class), is((Object) "foo"));
assertThat(nonValueAttribute.findValueOn(Sample.class), is((Object) "bar"));
}
@Test
public void findsAttributesFromSubType() {
assertThat(valueAttribute.findValueOn(SampleSub.class), is((Object) "foo"));
}
@Test
public void doesNotGetValueFromSubTyp() {
assertThat(valueAttribute.getValueFrom(SampleSub.class), is(nullValue()));
}
@Retention(RetentionPolicy.RUNTIME)
public static @interface MyAnnotation {
String value() default "";
String nonValue() default "";
}
@MyAnnotation(value = "foo", nonValue = "bar")
static class Sample {
}
static class SampleSub extends Sample {
}
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright 2013 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.core;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* Unit tests for {@link MethodParameters}.
*
* @author Oliver Gierke
*/
public class MethodParametersUnitTests {
@Test
public void prefersAnnotatedParameterOverDiscovered() throws Exception {
Method method = Sample.class.getMethod("method", String.class, String.class);
MethodParameters parameters = new MethodParameters(method,
new AnnotationAttribute(Qualifier.class));
assertThat(parameters.getParameter("param"), is(notNullValue()));
assertThat(parameters.getParameter("foo"), is(notNullValue()));
assertThat(parameters.getParameter("another"), is(nullValue()));
}
@Retention(RetentionPolicy.RUNTIME)
public static @interface Qualifier {
String value() default "";
}
static class Sample {
public void method(String param, @Qualifier("foo") String another) {
}
}
}