DATAVK-86 - Improved auto-template-registration infrastructure.

KeyValueRepositoryConfigurationExtension now need to report the default value for the KeyValueTemplate reference. We now only register a default template if the reference has not been customized. Changed the default reference value for Maps to mapKeyValueTemplate to allow individual defaults per store.

Removed obsolete RepositoryNamespaceHandler.

Original pull request: #1.
This commit is contained in:
Oliver Gierke
2014-12-01 16:35:28 +01:00
parent ff1338a99c
commit 5a14d7bc12
6 changed files with 96 additions and 73 deletions

View File

@@ -0,0 +1,69 @@
/*
* 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.
*/
package org.springframework.data.map.repository.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
/**
* Integration tests for {@link MapRepositoryConfigurationExtension}.
*
* @author Oliver Gierke
*/
public class MapRepositoriesConfigurationExtensionIntegrationTests {
/**
* @see DATAKV-86
*/
@Test
public void registersDefaultTemplateIfReferenceNotCustomized() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
assertThat(Arrays.asList(context.getBeanDefinitionNames()), hasItem("mapKeyValueTemplate"));
context.close();
}
/**
* @see DATAKV-86
*/
@Test
public void doesNotRegisterDefaulttemplateIfReferenceIsCustomized() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
ConfigWithCustomTemplateReference.class);
assertThat(Arrays.asList(context.getBeanDefinitionNames()), not(hasItem("mapKeyValueTemplate")));
context.close();
}
@Configuration
@EnableMapRepositories
static class Config {}
@Configuration
@EnableMapRepositories(keyValueTemplateRef = "foo")
static class ConfigWithCustomTemplateReference {}
}

View File

@@ -80,6 +80,5 @@ public class MapRepositoryRegistrarWithFullDefaultingIntegrationTests {
static interface PersonRepository extends CrudRepository<Person, String> {
List<Person> findByFirstname(String firstname);
}
}