DATACMNS-1439 - Use Java Beans decapitalization for default repository implementation bean names.

We now use Java Beans Introspector during default bean name derivation from class names. Previously, we used String.decapitalize(…) which decapitalizes always the first character. Java Beans do not decapitalize upper case sequences so a class name com.acme.UDPRepository translates to a bean name with UDPRepository instead of uDPRepository.

Original pull request: #325.
This commit is contained in:
Mark Paluch
2018-12-07 11:18:46 +01:00
committed by Oliver Drotbohm
parent fe1ccd50be
commit 9fe35a24c9
6 changed files with 162 additions and 6 deletions

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2018 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.
*/
package org.springframework.data.repository.config;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
/**
* Unit tests for {@link DefaultImplementationLookupConfigurationUnitTests}.
*
* @author Mark Paluch
*/
public class DefaultImplementationLookupConfigurationUnitTests {
@Test // DATACMNS-1439
public void shouldConsiderBeanNameDecapitalization() {
ImplementationDetectionConfiguration idcMock = mock(ImplementationDetectionConfiguration.class);
when(idcMock.getImplementationPostfix()).thenReturn("Impl");
assertThat(getImplementationBeanName(idcMock, "com.acme.UDPRepository")).isEqualTo("UDPRepositoryImpl");
assertThat(getImplementationBeanName(idcMock, "com.acme.UdpRepository")).isEqualTo("udpRepositoryImpl");
}
private static String getImplementationBeanName(ImplementationDetectionConfiguration idcMock, String interfaceName) {
DefaultImplementationLookupConfiguration configuration = new DefaultImplementationLookupConfiguration(idcMock,
interfaceName);
return configuration.getImplementationBeanName();
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2018 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.
*/
package org.springframework.data.repository.config;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.data.util.Streamable;
/**
* Unit tests for {@link ImplementationDetectionConfiguration}.
*
* @author Mark Paluch
*/
public class ImplementationDetectionConfigurationUnitTests {
@Test // DATACMNS-1439
public void shouldConsiderBeanNameDecapitalization() {
assertThat(getBeanName("com.acme.UDPRepository")).isEqualTo("UDPRepository");
assertThat(getBeanName("com.acme.UdpRepository")).isEqualTo("udpRepository");
}
private static String getBeanName(String className) {
MockImplementationDetectionConfiguration configuration = new MockImplementationDetectionConfiguration();
return configuration.generateBeanName(BeanDefinitionBuilder.rootBeanDefinition(className).getBeanDefinition());
}
private static class MockImplementationDetectionConfiguration implements ImplementationDetectionConfiguration {
@Override
public String getImplementationPostfix() {
return null;
}
@Override
public Streamable<String> getBasePackages() {
return null;
}
@Override
public Streamable<TypeFilter> getExcludeFilters() {
return null;
}
@Override
public MetadataReaderFactory getMetadataReaderFactory() {
return null;
}
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2018 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.
*/
package org.springframework.data.repository.config;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
/**
* Unit tests for {@link RepositoryFragmentConfiguration}.
*
* @author Mark Paluch
*/
public class RepositoryFragmentConfigurationUnitTests {
@Test // DATACMNS-1439
public void shouldConsiderBeanNameDecapitalization() {
assertThat(getImplementationBeanName("com.acme.UDPRepository")).isEqualTo("UDPRepository");
assertThat(getImplementationBeanName("com.acme.UdpRepository")).isEqualTo("udpRepository");
}
private static String getImplementationBeanName(String className) {
return new RepositoryFragmentConfiguration("interface", className).getImplementationBeanName();
}
}