|
| 1 | +/* |
| 2 | + * Copyright 2021 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.r2dbc.repository.support; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.*; |
| 19 | +import static org.mockito.Mockito.*; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import org.springframework.beans.factory.ListableBeanFactory; |
| 24 | +import org.springframework.data.r2dbc.core.R2dbcEntityTemplate; |
| 25 | +import org.springframework.data.r2dbc.dialect.H2Dialect; |
| 26 | +import org.springframework.data.r2dbc.repository.R2dbcRepository; |
| 27 | +import org.springframework.data.repository.query.ReactiveExtensionAwareQueryMethodEvaluationContextProvider; |
| 28 | +import org.springframework.r2dbc.core.DatabaseClient; |
| 29 | +import org.springframework.test.util.ReflectionTestUtils; |
| 30 | + |
| 31 | +/** |
| 32 | + * Unit tests for {@link R2dbcRepositoryFactoryBean}. |
| 33 | + * |
| 34 | + * @author Mark Paluch |
| 35 | + */ |
| 36 | +class R2dbcRepositoryFactoryBeanUnitTests { |
| 37 | + |
| 38 | + @Test // #658 |
| 39 | + void shouldConfigureReactiveExtensionAwareQueryMethodEvaluationContextProvider() { |
| 40 | + |
| 41 | + R2dbcRepositoryFactoryBean<PersonRepository, Person, String> factoryBean = new R2dbcRepositoryFactoryBean<>( |
| 42 | + PersonRepository.class); |
| 43 | + factoryBean.setBeanFactory(mock(ListableBeanFactory.class)); |
| 44 | + R2dbcEntityTemplate operations = new R2dbcEntityTemplate(mock(DatabaseClient.class), H2Dialect.INSTANCE); |
| 45 | + factoryBean.setEntityOperations(operations); |
| 46 | + factoryBean.setLazyInit(true); |
| 47 | + factoryBean.afterPropertiesSet(); |
| 48 | + |
| 49 | + Object factory = ReflectionTestUtils.getField(factoryBean, "factory"); |
| 50 | + Object evaluationContextProvider = ReflectionTestUtils.getField(factory, "evaluationContextProvider"); |
| 51 | + |
| 52 | + assertThat(evaluationContextProvider).isInstanceOf(ReactiveExtensionAwareQueryMethodEvaluationContextProvider.class) |
| 53 | + .isNotEqualTo(ReactiveExtensionAwareQueryMethodEvaluationContextProvider.DEFAULT); |
| 54 | + } |
| 55 | + |
| 56 | + static class Person {} |
| 57 | + |
| 58 | + interface PersonRepository extends R2dbcRepository<Person, String> |
| 59 | + |
| 60 | + {} |
| 61 | +} |
0 commit comments