Commit afb43c58 by Dave Syer

Actually fix the feign client validation issue

We need to still assert that the FeignClient is valid (no name and value specified together for instance). Added missing tests.
parent 85ef54a9
...@@ -155,8 +155,6 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ...@@ -155,8 +155,6 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
Map<String, Object> attributes = annotationMetadata Map<String, Object> attributes = annotationMetadata
.getAnnotationAttributes( .getAnnotationAttributes(
FeignClient.class.getCanonicalName()); FeignClient.class.getCanonicalName());
// Spring 4.2 didn't do this for us. With 4.3 it's idempotent.
attributes = AnnotationAttributes.fromMap(attributes);
String name = getClientName(attributes); String name = getClientName(attributes);
registerClientConfiguration(registry, name, registerClientConfiguration(registry, name,
...@@ -192,10 +190,9 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ...@@ -192,10 +190,9 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
} }
private void validate(Map<String, Object> attributes) { private void validate(Map<String, Object> attributes) {
if (StringUtils.hasText((String) attributes.get("value"))) { AnnotationAttributes annotation = AnnotationAttributes.fromMap(attributes);
Assert.isTrue(!StringUtils.hasText((String) attributes.get("serviceId")), // This blows up if an aliased property is overspecified
"Either name (serviceId) or value can be specified, but not both"); annotation.getAliasedString("name", FeignClient.class, null);
}
} }
private String getName(Map<String, Object> attributes) { private String getName(Map<String, Object> attributes) {
......
...@@ -40,6 +40,50 @@ public class FeignClientValidationTests { ...@@ -40,6 +40,50 @@ public class FeignClientValidationTests {
public ExpectedException expected = ExpectedException.none(); public ExpectedException expected = ExpectedException.none();
@Test @Test
public void testNameAndValue() {
this.expected.expectMessage("only one is permitted");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
NameAndValueConfiguration.class);
assertNotNull(context.getBean(NameAndValueConfiguration.Client.class));
context.close();
}
@Configuration
@Import(FeignAutoConfiguration.class)
@EnableFeignClients(clients = NameAndValueConfiguration.Client.class)
protected static class NameAndValueConfiguration {
@FeignClient(value = "foo", name = "bar")
interface Client {
@RequestMapping(method = RequestMethod.GET, value = "/")
String get();
}
}
@Test
public void testServiceIdAndValue() {
this.expected.expectMessage("only one is permitted");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
NameAndValueConfiguration.class);
assertNotNull(context.getBean(NameAndServiceIdConfiguration.Client.class));
context.close();
}
@Configuration
@Import(FeignAutoConfiguration.class)
@EnableFeignClients(clients = NameAndServiceIdConfiguration.Client.class)
protected static class NameAndServiceIdConfiguration {
@FeignClient(serviceId = "foo", name = "bar")
interface Client {
@RequestMapping(method = RequestMethod.GET, value = "/")
String get();
}
}
@Test
public void testNotLegalHostname() { public void testNotLegalHostname() {
this.expected.expectMessage("not legal hostname (foo_bar)"); this.expected.expectMessage("not legal hostname (foo_bar)");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
...@@ -115,7 +159,8 @@ public class FeignClientValidationTests { ...@@ -115,7 +159,8 @@ public class FeignClientValidationTests {
return new Dummy(); return new Dummy();
} }
class Dummy { } class Dummy {
}
} }
} }
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