Introduced @Description annotation for populating BeanDefinition.getDescription()
Issue: SPR-10583
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,6 @@ import org.springframework.util.Assert;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.context.annotation.MetadataUtils.*;
|
||||
|
||||
/**
|
||||
* Tests that an ImportAware @Configuration classes gets injected with the
|
||||
@@ -59,7 +58,7 @@ public class ImportAwareTests {
|
||||
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
|
||||
assertThat("import metadata was not injected", importMetadata, notNullValue());
|
||||
assertThat(importMetadata.getClassName(), is(ImportingConfig.class.getName()));
|
||||
AnnotationAttributes importAttribs = attributesFor(importMetadata, Import.class);
|
||||
AnnotationAttributes importAttribs = AnnotationConfigUtils.attributesFor(importMetadata, Import.class);
|
||||
Class<?>[] importedClasses = importAttribs.getClassArray("value");
|
||||
assertThat(importedClasses[0].getName(), is(ImportedConfig.class.getName()));
|
||||
}
|
||||
@@ -76,7 +75,7 @@ public class ImportAwareTests {
|
||||
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
|
||||
assertThat("import metadata was not injected", importMetadata, notNullValue());
|
||||
assertThat(importMetadata.getClassName(), is(IndirectlyImportingConfig.class.getName()));
|
||||
AnnotationAttributes enableAttribs = attributesFor(importMetadata, EnableImportedConfig.class);
|
||||
AnnotationAttributes enableAttribs = AnnotationConfigUtils.attributesFor(importMetadata, EnableImportedConfig.class);
|
||||
String foo = enableAttribs.getString("foo");
|
||||
assertThat(foo, is("xyz"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,22 +16,23 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.role.ComponentWithRole;
|
||||
import org.springframework.context.annotation.role.ComponentWithoutRole;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the use of the @Role annotation on @Bean methods and
|
||||
* @Component classes.
|
||||
* Tests the use of the @Role and @Description annotation on @Bean methods and @Component classes.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public class RoleAnnotationTests {
|
||||
public class RoleAndDescriptionAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void onBeanMethod() {
|
||||
@@ -40,8 +41,37 @@ public class RoleAnnotationTests {
|
||||
ctx.refresh();
|
||||
assertThat("Expected bean to have ROLE_APPLICATION",
|
||||
ctx.getBeanDefinition("foo").getRole(), is(BeanDefinition.ROLE_APPLICATION));
|
||||
assertThat(ctx.getBeanDefinition("foo").getDescription(), is((Object) null));
|
||||
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
|
||||
ctx.getBeanDefinition("bar").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
|
||||
assertThat(ctx.getBeanDefinition("bar").getDescription(), is("A Bean method with a role"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onComponentClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ComponentWithoutRole.class, ComponentWithRole.class);
|
||||
ctx.refresh();
|
||||
assertThat("Expected bean to have ROLE_APPLICATION",
|
||||
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
|
||||
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
|
||||
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
|
||||
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void viaComponentScanning() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.role");
|
||||
ctx.refresh();
|
||||
assertThat("Expected bean to have ROLE_APPLICATION",
|
||||
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
|
||||
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
|
||||
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
|
||||
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,32 +84,10 @@ public class RoleAnnotationTests {
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Description("A Bean method with a role")
|
||||
public String bar() {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void onComponentClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ComponentWithoutRole.class, ComponentWithRole.class);
|
||||
ctx.refresh();
|
||||
assertThat("Expected bean to have ROLE_APPLICATION",
|
||||
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
|
||||
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
|
||||
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void viaComponentScanning() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.role");
|
||||
ctx.refresh();
|
||||
assertThat("Expected bean to have ROLE_APPLICATION",
|
||||
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
|
||||
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
|
||||
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.springframework.context.annotation.role;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Description;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("componentWithRole")
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Description("A Component with a role")
|
||||
public class ComponentWithRole {
|
||||
}
|
||||
Reference in New Issue
Block a user