Revert "Fix double @RequestMapping with empty value (#245)"

This reverts commit 0afb60a72a.

# Conflicts:
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java
#	spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java
This commit is contained in:
Olga Maciaszek-Sharma
2020-07-30 16:18:25 +02:00
parent d3da7e16e8
commit 14929cbfee
3 changed files with 10 additions and 98 deletions

View File

@@ -231,12 +231,6 @@
<artifactId>spring-cloud-loadbalancer</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>

View File

@@ -173,14 +173,15 @@ public class SpringMvcContract extends Contract.BaseContract
if (clz.getInterfaces().length == 0) {
RequestMapping classAnnotation = findMergedAnnotation(clz,
RequestMapping.class);
if (classAnnotation != null && classAnnotation.value().length > 0) {
if (classAnnotation != null) {
// Prepend path from class annotation if specified
String pathValue = emptyToNull(classAnnotation.value()[0]);
if (pathValue != null) {
if (classAnnotation.value().length > 0) {
String pathValue = emptyToNull(classAnnotation.value()[0]);
pathValue = resolve(pathValue);
if (!pathValue.equals("/")) {
data.template().uri(pathValue);
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
data.template().uri(pathValue);
}
}
}
@@ -240,9 +241,11 @@ public class SpringMvcContract extends Contract.BaseContract
String pathValue = emptyToNull(methodMapping.value()[0]);
if (pathValue != null) {
pathValue = resolve(pathValue);
if (!pathValue.equals("/")) {
data.template().uri(pathValue, true);
// Append path from @RequestMapping if value is present on method
if (!pathValue.startsWith("/") && !data.template().path().endsWith("/")) {
pathValue = "/" + pathValue;
}
data.template().uri(pathValue, true);
}
}

View File

@@ -31,11 +31,8 @@ import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import feign.MethodMetadata;
import feign.Param;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.cloud.openfeign.CollectionFormat;
import org.springframework.cloud.openfeign.SpringQueryMap;
@@ -75,7 +72,6 @@ import static org.junit.Assume.assumeTrue;
* @author Artyom Romanenko
* @author Olga Maciaszek-Sharma
*/
@RunWith(JUnitParamsRunner.class)
public class SpringMvcContractTests {
private static final Class<?> EXECUTABLE_TYPE;
@@ -602,53 +598,6 @@ public class SpringMvcContractTests {
"{Accept}");
}
private Class[] doubleMappingClassesProvider() {
return new Class[] { TestTemplate_RequestMapping_Empty_Class.class,
TestTemplate_RequestMapping_Empty_Method.class };
}
@Test
@Parameters(method = "doubleMappingClassesProvider")
public void testDoubleRequestMapping_root(Class clazz) throws NoSuchMethodException {
Method method = clazz.getDeclaredMethod("root");
MethodMetadata data = contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertThat(data.template().url()).isEqualTo("/");
}
@Test
@Parameters(method = "doubleMappingClassesProvider")
public void testDoubleRequestMapping_rootReverse(Class clazz)
throws NoSuchMethodException {
Method method = clazz.getDeclaredMethod("rootReverse");
MethodMetadata data = contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertThat(data.template().url()).isEqualTo("/");
}
@Test
@Parameters(method = "doubleMappingClassesProvider")
public void testDoubleRequestMapping_sub(Class clazz) throws NoSuchMethodException {
Method method = clazz.getDeclaredMethod("sub");
MethodMetadata data = contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertThat(data.template().url()).isEqualTo("/sub");
}
@Test
@Parameters(method = "doubleMappingClassesProvider")
public void testDoubleRequestMapping_subEmpty(Class clazz)
throws NoSuchMethodException {
Method method = clazz.getDeclaredMethod("subEmpty");
MethodMetadata data = contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertThat(data.template().url()).isEqualTo("/subEmpty");
}
@Test
public void testMultipleRequestPartAnnotations() throws NoSuchMethodException {
Method method = TestTemplate_RequestPart.class.getDeclaredMethod(
@@ -841,40 +790,6 @@ public class SpringMvcContractTests {
}
@RequestMapping("")
public interface TestTemplate_RequestMapping_Empty_Class {
@RequestMapping("/")
String root();
@RequestMapping("")
String rootReverse();
@RequestMapping("/sub")
String sub();
@RequestMapping("subEmpty")
String subEmpty();
}
@RequestMapping("/")
public interface TestTemplate_RequestMapping_Empty_Method {
@RequestMapping("")
String root();
@RequestMapping("/")
String rootReverse();
@RequestMapping("/sub")
String sub();
@RequestMapping("subEmpty")
String subEmpty();
}
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE,
setterVisibility = NONE)
public class TestObject {