DATACMNS-1754 - Polishing.
Revert bean name change so all nested repository interface components (repository bean, fragment bean, legacy custom implementation bean) remain prefixed with their enclosing type name. Adopt tests. Add test for RepositoryBeanDefinitionRegistrar. Extend documentation. Original pull request: #460.
This commit is contained in:
@@ -131,33 +131,24 @@ class CdiRepositoryBeanUnitTests {
|
||||
@Test // DATACMNS-322
|
||||
void createsPassivationId() {
|
||||
|
||||
CdiRepositoryBean<SampleRepository> bean = new DummyCdiRepositoryBean<>( //
|
||||
SINGLE_ANNOTATION, //
|
||||
SampleRepository.class, //
|
||||
beanManager //
|
||||
CdiRepositoryBean<SampleRepository> bean = new DummyCdiRepositoryBean<>(SINGLE_ANNOTATION, SampleRepository.class,
|
||||
beanManager
|
||||
);
|
||||
|
||||
assertThat(bean.getId()).isEqualTo(PASSIVATION_ID);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-764
|
||||
@Test // DATACMNS-764, DATACMNS-1754
|
||||
void passesCorrectBeanNameToTheImplementationDetector() {
|
||||
|
||||
CustomRepositoryImplementationDetector detector = mock(CustomRepositoryImplementationDetector.class);
|
||||
|
||||
CdiRepositoryBean<SampleRepository> bean = new CdiRepositoryBean<SampleRepository>( //
|
||||
SINGLE_ANNOTATION, //
|
||||
SampleRepository.class, //
|
||||
beanManager, //
|
||||
Optional.of(detector) //
|
||||
) {
|
||||
CdiRepositoryBean<SampleRepository> bean = new CdiRepositoryBean<SampleRepository>(SINGLE_ANNOTATION,
|
||||
SampleRepository.class, beanManager, Optional.of(detector)) {
|
||||
|
||||
@Override
|
||||
protected SampleRepository create( //
|
||||
CreationalContext<SampleRepository> creationalContext, //
|
||||
Class<SampleRepository> repositoryType, //
|
||||
Optional<Object> customImplementation //
|
||||
) {
|
||||
protected SampleRepository create(CreationalContext<SampleRepository> creationalContext,
|
||||
Class<SampleRepository> repositoryType, Optional<Object> customImplementation) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -171,7 +162,7 @@ class CdiRepositoryBeanUnitTests {
|
||||
|
||||
ImplementationLookupConfiguration configuration = captor.getValue();
|
||||
|
||||
assertThat(configuration.getImplementationBeanName()).isEqualTo("sampleRepositoryImpl");
|
||||
assertThat(configuration.getImplementationBeanName()).isEqualTo("cdiRepositoryBeanUnitTests.SampleRepositoryImpl");
|
||||
assertThat(configuration.getImplementationClassName()).isEqualTo("SampleRepositoryImpl");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2020 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
package org.springframework.data.repository.cdi;
|
||||
|
||||
/**
|
||||
* @author Kyrylo Merzlikin
|
||||
*/
|
||||
public class NestedFragmentInterfaceImpl implements RepositoryFragments.NestedFragmentInterface {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "NestedFragmentImpl";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2020 the original author or authors.
|
||||
* Copyright 2020 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.
|
||||
@@ -24,4 +24,12 @@ public interface RepositoryFragments {
|
||||
|
||||
String getKey();
|
||||
}
|
||||
|
||||
class NestedFragmentInterfaceImpl implements NestedFragmentInterface {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "NestedFragmentImpl";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,8 @@ class RepositoryFragmentsIntegrationTests {
|
||||
void shouldFindImplementationForNestedRepositoryFragment() {
|
||||
|
||||
ComposedRepository repository = getBean(ComposedRepository.class);
|
||||
NestedFragmentInterfaceImpl fragment = getBean(NestedFragmentInterfaceImpl.class);
|
||||
RepositoryFragments.NestedFragmentInterfaceImpl fragment = getBean(
|
||||
RepositoryFragments.NestedFragmentInterfaceImpl.class);
|
||||
|
||||
assertThat(repository.getKey()).isEqualTo("NestedFragmentImpl");
|
||||
assertThat(fragment.getKey()).isEqualTo("NestedFragmentImpl");
|
||||
|
||||
@@ -46,7 +46,7 @@ class DefaultImplementationLookupConfigurationUnitTests {
|
||||
|
||||
DefaultImplementationLookupConfiguration lookupConfiguration = new DefaultImplementationLookupConfiguration(idcMock,
|
||||
"com.acme.Repositories$NestedRepository");
|
||||
assertThat(lookupConfiguration.getImplementationBeanName()).isEqualTo("nestedRepositoryImpl");
|
||||
assertThat(lookupConfiguration.getImplementationBeanName()).isEqualTo("repositories.NestedRepositoryImpl");
|
||||
assertThat(lookupConfiguration.getImplementationClassName()).isEqualTo("NestedRepositoryImpl");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.mapping.Person;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.config.basepackage.FragmentImpl;
|
||||
import org.springframework.data.repository.core.support.DummyRepositoryFactoryBean;
|
||||
|
||||
@@ -76,6 +78,18 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
assertNoBeanDefinitionRegisteredFor("profileRepository");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1754
|
||||
void registersBeanDefinitionForNestedRepositories() {
|
||||
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(NestedRepositoriesConfiguration.class);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
|
||||
assertBeanDefinitionRegisteredFor("repositoryBeanDefinitionRegistrarSupportUnitTests.MyNestedRepository");
|
||||
assertBeanDefinitionRegisteredFor("repositoryBeanDefinitionRegistrarSupportUnitTests.NestedFragmentImpl");
|
||||
assertBeanDefinitionRegisteredFor("repositoryBeanDefinitionRegistrarSupportUnitTests.MyNestedRepositoryImpl");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1147
|
||||
void registersBeanDefinitionWithoutFragmentImplementations() {
|
||||
|
||||
@@ -183,4 +197,28 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
|
||||
@EnableRepositories(basePackageClasses = FragmentImpl.class)
|
||||
static class LimitsImplementationBasePackages {}
|
||||
|
||||
@EnableRepositories(basePackageClasses = MyNestedRepository.class, considerNestedRepositories = true,
|
||||
excludeFilters = {
|
||||
@Filter(type = FilterType.ASSIGNABLE_TYPE,
|
||||
value = RepositoryConfigurationExtensionSupportUnitTests.ReactiveRepository.class),
|
||||
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = MyOtherRepository.class) })
|
||||
static class NestedRepositoriesConfiguration {}
|
||||
|
||||
interface MyNestedRepository extends Repository<Person, Long>, NestedFragment {
|
||||
|
||||
}
|
||||
|
||||
interface NestedFragment {
|
||||
|
||||
}
|
||||
|
||||
static class NestedFragmentImpl implements NestedFragment {
|
||||
|
||||
}
|
||||
|
||||
static class MyNestedRepositoryImpl {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user