DATACMNS-456 - Introduced getAttribute(String) on RepositoryConfigurationSupport.

RepositoryConfigurationSupport now has a getAttribute(String) method to lookup String attributes on XML elements and annotations. The XML implementation converts the given attribute name in a lower-case, dashed representation for the lookup.

RepositoryConfigurationExtensionSupport now ha a generic postProcess(…) method to allow implementations that only need to work with String attributes unify their customizations into that single method.
This commit is contained in:
Oliver Gierke
2014-03-01 12:18:44 +01:00
parent 6408e16faf
commit 2a8f4ddf93
7 changed files with 93 additions and 15 deletions

View File

@@ -52,6 +52,9 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
environment);
}
/**
* @see DATACMNS-47
*/
@Test
public void findsBasePackagesForClasses() {
@@ -59,6 +62,9 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
assertThat(basePackages, hasItem(AnnotationRepositoryConfigurationSourceUnitTests.class.getPackage().getName()));
}
/**
* @see DATACMNS-47
*/
@Test
public void evaluatesExcludeFiltersCorrectly() {
@@ -69,26 +75,28 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
assertThat(candidate.getBeanClassName(), is(MyRepository.class.getName()));
}
/**
* @see DATACMNS-47
*/
@Test
public void defaultsToPackageOfAnnotatedClass() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(DefaultConfiguration.class);
AnnotationRepositoryConfigurationSource source = new AnnotationRepositoryConfigurationSource(metadata,
EnableRepositories.class, resourceLoader, environment);
AnnotationRepositoryConfigurationSource source = getConfigSource(DefaultConfiguration.class);
Iterable<String> packages = source.getBasePackages();
assertThat(packages, hasItem(DefaultConfiguration.class.getPackage().getName()));
assertThat(source.shouldConsiderNestedRepositories(), is(false));
}
/**
* @see DATACMNS-47
*/
@Test
public void returnsConfiguredBasePackage() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(DefaultConfigurationWithBasePackage.class);
AnnotationRepositoryConfigurationSource source = new AnnotationRepositoryConfigurationSource(metadata,
EnableRepositories.class, resourceLoader, environment);
AnnotationRepositoryConfigurationSource source = getConfigSource(DefaultConfigurationWithBasePackage.class);
Iterable<String> packages = source.getBasePackages();
assertThat(packages, hasItem("foo"));
}
@@ -98,19 +106,32 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
@Test
public void returnsConsiderNestedRepositories() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(DefaultConfigurationWithNestedRepositories.class);
AnnotationRepositoryConfigurationSource source = new AnnotationRepositoryConfigurationSource(metadata,
EnableRepositories.class, resourceLoader, environment);
AnnotationRepositoryConfigurationSource source = getConfigSource(DefaultConfigurationWithNestedRepositories.class);
assertThat(source.shouldConsiderNestedRepositories(), is(true));
}
/**
* @see DATACMNS-456
*/
@Test
public void findsStringAttributeByName() {
RepositoryConfigurationSource source = getConfigSource(DefaultConfigurationWithBasePackage.class);
assertThat(source.getAttribute("namedQueriesLocation"), is("bar"));
}
private AnnotationRepositoryConfigurationSource getConfigSource(Class<?> type) {
AnnotationMetadata metadata = new StandardAnnotationMetadata(type);
return new AnnotationRepositoryConfigurationSource(metadata, EnableRepositories.class, resourceLoader, environment);
}
public static class Person {}
@EnableRepositories
static class DefaultConfiguration {}
@EnableRepositories(basePackages = "foo")
@EnableRepositories(basePackages = "foo", namedQueriesLocation = "bar")
static class DefaultConfigurationWithBasePackage {}
@EnableRepositories(considerNestedRepositories = true)