|
| 1 | +/* |
| 2 | + * Copyright 2019 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 | + * https://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.assertj.core.api.Assertions.*; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 22 | +import org.springframework.context.annotation.ComponentScan.Filter; |
| 23 | +import org.springframework.context.annotation.Configuration; |
| 24 | +import org.springframework.context.annotation.FilterType; |
| 25 | +import org.springframework.context.annotation.Primary; |
| 26 | +import org.springframework.data.repository.CrudRepository; |
| 27 | + |
| 28 | +/** |
| 29 | + * Integration tests for DATACMNS-1591. |
| 30 | + * |
| 31 | + * @author Oliver Drotbohm |
| 32 | + */ |
| 33 | +public class PrimaryRepositoryIntegrationTests { |
| 34 | + |
| 35 | + @Test // DATACMNS-1591 |
| 36 | + public void returnsPrimaryInstance() { |
| 37 | + |
| 38 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); |
| 39 | + |
| 40 | + // Two beans available but FirstRepository is the primary one |
| 41 | + assertThatCode(() -> context.getBean(FirstRepository.class)).doesNotThrowAnyException(); |
| 42 | + } |
| 43 | + |
| 44 | + @Configuration |
| 45 | + @EnableRepositories(considerNestedRepositories = true, // |
| 46 | + includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = Marker.class)) |
| 47 | + static class Config {} |
| 48 | + |
| 49 | + interface Marker {} |
| 50 | + |
| 51 | + @Primary |
| 52 | + interface FirstRepository<T> extends CrudRepository<T, Long>, Marker {} |
| 53 | + |
| 54 | + interface SecondRepository extends FirstRepository<Object>, Marker {} |
| 55 | +} |
0 commit comments