DATACMNS-502 - Prevent IndexOutOfBoundException in AnnotationRepositoryConfigurationSource.
If a configuration class resides in the default package and no base package is defined in the @Enable…Repositories annotation we previously failed in extracting the package from the class name (as there is none). We now use Spring's ClassUtils that correctly handles this case and returns an empty String for the default package.
This commit is contained in:
26
src/test/java/TypeInDefaultPackage.java
Normal file
26
src/test/java/TypeInDefaultPackage.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.springframework.data.repository.config.EnableRepositories;
|
||||
|
||||
/**
|
||||
* Dummy type to be able to reference the default package.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@EnableRepositories
|
||||
public class TypeInDefaultPackage {
|
||||
|
||||
}
|
||||
@@ -120,6 +120,20 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
assertThat(source.getAttribute("namedQueriesLocation"), is("bar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-502
|
||||
*/
|
||||
@Test
|
||||
public void returnsEmptyStringForBasePackage() throws Exception {
|
||||
|
||||
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(getClass().getClassLoader().loadClass(
|
||||
"TypeInDefaultPackage"));
|
||||
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
|
||||
EnableRepositories.class, resourceLoader, environment);
|
||||
|
||||
assertThat(configurationSource.getBasePackages(), hasItem(""));
|
||||
}
|
||||
|
||||
private AnnotationRepositoryConfigurationSource getConfigSource(Class<?> type) {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(type);
|
||||
|
||||
Reference in New Issue
Block a user