Commit c5950df6 by Spencer Gibb

polish

parent d4330967
...@@ -42,7 +42,7 @@ public class SpringMvcContract extends Contract.BaseContract { ...@@ -42,7 +42,7 @@ public class SpringMvcContract extends Contract.BaseContract {
private static final String CONTENT_TYPE = "Content-Type"; private static final String CONTENT_TYPE = "Content-Type";
@Override @Override
protected MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) { public MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) {
MethodMetadata md = super.parseAndValidateMetadata(targetType, method); MethodMetadata md = super.parseAndValidateMetadata(targetType, method);
RequestMapping classAnnotation = targetType.getAnnotation(RequestMapping.class); RequestMapping classAnnotation = targetType.getAnnotation(RequestMapping.class);
......
package org.springframework.cloud.netflix.feign.support; package org.springframework.cloud.netflix.feign.support;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import static org.junit.Assert.assertEquals;
import feign.MethodMetadata;
import java.lang.reflect.Method;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.annotation.Annotation; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import static org.junit.Assert.assertEquals; import feign.MethodMetadata;
/** /**
* @author chadjaros * @author chadjaros
...@@ -32,9 +38,7 @@ public class SpringMvcContractTest { ...@@ -32,9 +38,7 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotationOnMethod_Simple() throws Exception { public void testProcessAnnotationOnMethod_Simple() throws Exception {
Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest", String.class); Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest", String.class);
Annotation annotation = method.getAnnotation(RequestMapping.class); MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
assertEquals("/test/{id}", data.template().url()); assertEquals("/test/{id}", data.template().url());
assertEquals("GET", data.template().method()); assertEquals("GET", data.template().method());
...@@ -44,9 +48,7 @@ public class SpringMvcContractTest { ...@@ -44,9 +48,7 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotations_Simple() throws Exception { public void testProcessAnnotations_Simple() throws Exception {
Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest", String.class); Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest", String.class);
Annotation annotation = method.getAnnotation(RequestMapping.class); MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
assertEquals("/test/{id}", data.template().url()); assertEquals("/test/{id}", data.template().url());
assertEquals("GET", data.template().method()); assertEquals("GET", data.template().method());
...@@ -58,9 +60,7 @@ public class SpringMvcContractTest { ...@@ -58,9 +60,7 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotationsOnMethod_Advanced() throws Exception { public void testProcessAnnotationsOnMethod_Advanced() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, Integer.class); Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, Integer.class);
Annotation annotation = method.getAnnotation(RequestMapping.class); MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
assertEquals("/advanced/test/{id}", data.template().url()); assertEquals("/advanced/test/{id}", data.template().url());
assertEquals("PUT", data.template().method()); assertEquals("PUT", data.template().method());
...@@ -70,9 +70,7 @@ public class SpringMvcContractTest { ...@@ -70,9 +70,7 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotationsOnMethod_Advanced_UnknownAnnotation() throws Exception { public void testProcessAnnotationsOnMethod_Advanced_UnknownAnnotation() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, Integer.class); Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, Integer.class);
Annotation annotation = method.getAnnotation(ExceptionHandler.class); contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
// Don't throw an exception and this passes // Don't throw an exception and this passes
} }
...@@ -80,9 +78,7 @@ public class SpringMvcContractTest { ...@@ -80,9 +78,7 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotations_Advanced() throws Exception { public void testProcessAnnotations_Advanced() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, Integer.class); Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, Integer.class);
Annotation annotation = method.getAnnotation(RequestMapping.class); MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
assertEquals("/advanced/test/{id}", data.template().url()); assertEquals("/advanced/test/{id}", data.template().url());
assertEquals("PUT", data.template().method()); assertEquals("PUT", data.template().method());
...@@ -99,9 +95,7 @@ public class SpringMvcContractTest { ...@@ -99,9 +95,7 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotations_Advanced2() throws Exception { public void testProcessAnnotations_Advanced2() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest"); Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest");
Annotation annotation = method.getAnnotation(RequestMapping.class); MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
assertEquals("/advanced", data.template().url()); assertEquals("/advanced", data.template().url());
assertEquals("GET", data.template().method()); assertEquals("GET", data.template().method());
...@@ -111,23 +105,14 @@ public class SpringMvcContractTest { ...@@ -111,23 +105,14 @@ public class SpringMvcContractTest {
@Test @Test
public void testProcessAnnotations_Advanced3() throws Exception { public void testProcessAnnotations_Advanced3() throws Exception {
Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest"); Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest");
Annotation annotation = method.getAnnotation(RequestMapping.class); MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
MethodMetadata data = contract.parseAndValidatateMetadata(method);
assertEquals("", data.template().url()); assertEquals("", data.template().url());
assertEquals("GET", data.template().method()); assertEquals("GET", data.template().method());
assertEquals(MediaType.APPLICATION_JSON_VALUE, data.template().headers().get("Accept").iterator().next()); assertEquals(MediaType.APPLICATION_JSON_VALUE, data.template().headers().get("Accept").iterator().next());
} }
private MethodMetadata newMethodMetadata() throws Exception { public interface TestTemplate_Simple {
// Reflect because constructor is package private :(
Constructor constructor = MethodMetadata.class.getDeclaredConstructor();
constructor.setAccessible(true);
return (MethodMetadata)constructor.newInstance();
}
public static interface TestTemplate_Simple {
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/test/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<TestObject> getTest(@PathVariable("id") String id); ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
...@@ -137,7 +122,7 @@ public class SpringMvcContractTest { ...@@ -137,7 +122,7 @@ public class SpringMvcContractTest {
@JsonAutoDetect @JsonAutoDetect
@RequestMapping("/advanced") @RequestMapping("/advanced")
public static interface TestTemplate_Advanced { public interface TestTemplate_Advanced {
@ExceptionHandler @ExceptionHandler
@RequestMapping(value = "/test/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/test/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment