Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
c5950df6
Commit
c5950df6
authored
Oct 08, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish
parent
d4330967
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
38 deletions
+23
-38
SpringMvcContract.java
...mework/cloud/netflix/feign/support/SpringMvcContract.java
+1
-1
SpringMvcContractTest.java
...rk/cloud/netflix/feign/support/SpringMvcContractTest.java
+22
-37
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/support/SpringMvcContract.java
View file @
c5950df6
...
...
@@ -42,7 +42,7 @@ public class SpringMvcContract extends Contract.BaseContract {
private
static
final
String
CONTENT_TYPE
=
"Content-Type"
;
@Override
p
rotected
MethodMetadata
parseAndValidateMetadata
(
Class
<?>
targetType
,
Method
method
)
{
p
ublic
MethodMetadata
parseAndValidateMetadata
(
Class
<?>
targetType
,
Method
method
)
{
MethodMetadata
md
=
super
.
parseAndValidateMetadata
(
targetType
,
method
);
RequestMapping
classAnnotation
=
targetType
.
getAnnotation
(
RequestMapping
.
class
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/support/SpringMvcContractTest.java
View file @
c5950df6
package
org
.
springframework
.
cloud
.
netflix
.
feign
.
support
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
feign.MethodMetadata
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.lang.reflect.Method
;
import
lombok.AllArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
lombok.ToString
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.http.MediaType
;
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
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
feign.MethodMetadata
;
/**
* @author chadjaros
...
...
@@ -32,9 +38,7 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotationOnMethod_Simple
()
throws
Exception
{
Method
method
=
TestTemplate_Simple
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
);
Annotation
annotation
=
method
.
getAnnotation
(
RequestMapping
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
MethodMetadata
data
=
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/test/{id}"
,
data
.
template
().
url
());
assertEquals
(
"GET"
,
data
.
template
().
method
());
...
...
@@ -44,9 +48,7 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotations_Simple
()
throws
Exception
{
Method
method
=
TestTemplate_Simple
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
);
Annotation
annotation
=
method
.
getAnnotation
(
RequestMapping
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
MethodMetadata
data
=
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/test/{id}"
,
data
.
template
().
url
());
assertEquals
(
"GET"
,
data
.
template
().
method
());
...
...
@@ -58,9 +60,7 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotationsOnMethod_Advanced
()
throws
Exception
{
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
,
String
.
class
,
Integer
.
class
);
Annotation
annotation
=
method
.
getAnnotation
(
RequestMapping
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
MethodMetadata
data
=
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/advanced/test/{id}"
,
data
.
template
().
url
());
assertEquals
(
"PUT"
,
data
.
template
().
method
());
...
...
@@ -70,9 +70,7 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotationsOnMethod_Advanced_UnknownAnnotation
()
throws
Exception
{
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
,
String
.
class
,
Integer
.
class
);
Annotation
annotation
=
method
.
getAnnotation
(
ExceptionHandler
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
// Don't throw an exception and this passes
}
...
...
@@ -80,9 +78,7 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotations_Advanced
()
throws
Exception
{
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
,
String
.
class
,
Integer
.
class
);
Annotation
annotation
=
method
.
getAnnotation
(
RequestMapping
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
MethodMetadata
data
=
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/advanced/test/{id}"
,
data
.
template
().
url
());
assertEquals
(
"PUT"
,
data
.
template
().
method
());
...
...
@@ -99,9 +95,7 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotations_Advanced2
()
throws
Exception
{
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTest"
);
Annotation
annotation
=
method
.
getAnnotation
(
RequestMapping
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
MethodMetadata
data
=
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/advanced"
,
data
.
template
().
url
());
assertEquals
(
"GET"
,
data
.
template
().
method
());
...
...
@@ -111,23 +105,14 @@ public class SpringMvcContractTest {
@Test
public
void
testProcessAnnotations_Advanced3
()
throws
Exception
{
Method
method
=
TestTemplate_Simple
.
class
.
getDeclaredMethod
(
"getTest"
);
Annotation
annotation
=
method
.
getAnnotation
(
RequestMapping
.
class
);
MethodMetadata
data
=
contract
.
parseAndValidatateMetadata
(
method
);
MethodMetadata
data
=
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
""
,
data
.
template
().
url
());
assertEquals
(
"GET"
,
data
.
template
().
method
());
assertEquals
(
MediaType
.
APPLICATION_JSON_VALUE
,
data
.
template
().
headers
().
get
(
"Accept"
).
iterator
().
next
());
}
private
MethodMetadata
newMethodMetadata
()
throws
Exception
{
// Reflect because constructor is package private :(
Constructor
constructor
=
MethodMetadata
.
class
.
getDeclaredConstructor
();
constructor
.
setAccessible
(
true
);
return
(
MethodMetadata
)
constructor
.
newInstance
();
}
public
static
interface
TestTemplate_Simple
{
public
interface
TestTemplate_Simple
{
@RequestMapping
(
value
=
"/test/{id}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
ResponseEntity
<
TestObject
>
getTest
(
@PathVariable
(
"id"
)
String
id
);
...
...
@@ -137,7 +122,7 @@ public class SpringMvcContractTest {
@JsonAutoDetect
@RequestMapping
(
"/advanced"
)
public
static
interface
TestTemplate_Advanced
{
public
interface
TestTemplate_Advanced
{
@ExceptionHandler
@RequestMapping
(
value
=
"/test/{id}"
,
method
=
RequestMethod
.
PUT
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment