|
| 1 | +/* |
| 2 | + * Copyright 2016 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.repository.config; |
| 17 | + |
| 18 | +import static org.hamcrest.CoreMatchers.*; |
| 19 | +import static org.junit.Assert.*; |
| 20 | + |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.runner.RunWith; |
| 23 | +import org.mockito.Mock; |
| 24 | +import org.mockito.runners.MockitoJUnitRunner; |
| 25 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 26 | +import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
| 27 | +import org.springframework.context.support.GenericApplicationContext; |
| 28 | +import org.springframework.core.env.StandardEnvironment; |
| 29 | +import org.springframework.core.type.StandardAnnotationMetadata; |
| 30 | +import org.springframework.data.repository.sample.ProductRepository; |
| 31 | + |
| 32 | +/** |
| 33 | + * Unit tests for {@link RepositoryConfigurationDelegate}. |
| 34 | + * |
| 35 | + * @author Oliver Gierke |
| 36 | + * @soundtrack Richard Spaven - Tribute (Whole Other*) |
| 37 | + */ |
| 38 | +@RunWith(MockitoJUnitRunner.class) |
| 39 | +public class RepositoryConfigurationDelegateUnitTests { |
| 40 | + |
| 41 | + @Mock RepositoryConfigurationExtension extension; |
| 42 | + |
| 43 | + /** |
| 44 | + * @see DATACMNS-892 |
| 45 | + */ |
| 46 | + @Test |
| 47 | + public void registersRepositoryBeanNameAsAttribute() { |
| 48 | + |
| 49 | + StandardEnvironment environment = new StandardEnvironment(); |
| 50 | + GenericApplicationContext context = new GenericApplicationContext(); |
| 51 | + RepositoryConfigurationSource configSource = new AnnotationRepositoryConfigurationSource( |
| 52 | + new StandardAnnotationMetadata(TestConfig.class, true), EnableRepositories.class, context, environment); |
| 53 | + |
| 54 | + RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(configSource, context, environment); |
| 55 | + |
| 56 | + for (BeanComponentDefinition definition : delegate.registerRepositoriesIn(context, extension)) { |
| 57 | + |
| 58 | + BeanDefinition beanDefinition = definition.getBeanDefinition(); |
| 59 | + |
| 60 | + assertThat(beanDefinition.getAttribute(RepositoryConfigurationDelegate.FACTORY_BEAN_OBJECT_TYPE).toString(), |
| 61 | + endsWith("Repository")); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @EnableRepositories(basePackageClasses = ProductRepository.class) |
| 66 | + static class TestConfig {} |
| 67 | +} |
0 commit comments