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,
Map<String, Object> attributes = annotationMetadata
.getAnnotationAttributes(
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);
registerClientConfiguration(registry, name,
......@@ -192,10 +190,9 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
}
private void validate(Map<String, Object> attributes) {
if (StringUtils.hasText((String) attributes.get("value"))) {
Assert.isTrue(!StringUtils.hasText((String) attributes.get("serviceId")),
"Either name (serviceId) or value can be specified, but not both");
}
AnnotationAttributes annotation = AnnotationAttributes.fromMap(attributes);
// This blows up if an aliased property is overspecified
annotation.getAliasedString("name", FeignClient.class, null);
}
private String getName(Map<String, Object> attributes) {
......
......@@ -40,6 +40,50 @@ public class FeignClientValidationTests {
public ExpectedException expected = ExpectedException.none();
@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() {
this.expected.expectMessage("not legal hostname (foo_bar)");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
......@@ -115,7 +159,8 @@ public class FeignClientValidationTests {
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