|
| 1 | +/* |
| 2 | + * Copyright 2012-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 | + |
| 17 | +package org.springframework.boot.test.autoconfigure.data.jdbc; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.springframework.core.type.classreading.MetadataReader; |
| 21 | +import org.springframework.core.type.classreading.MetadataReaderFactory; |
| 22 | +import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; |
| 23 | +import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | + |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for {@link DataJdbcTypeExcludeFilter}. |
| 31 | + * |
| 32 | + * @author Ravi Undupitiya |
| 33 | + */ |
| 34 | +public class DataJdbcTypeExcludeFilterTests { |
| 35 | + |
| 36 | + private MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(); |
| 37 | + |
| 38 | + @Test |
| 39 | + void matchNotUsingDefaultFilters() throws Exception { |
| 40 | + DataJdbcTypeExcludeFilter filter = new DataJdbcTypeExcludeFilter(NotUsingDefaultFilters.class); |
| 41 | + assertThat(excludes(filter, AbstractJdbcConfiguration.class)).isTrue(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void matchUsingDefaultFilters() throws Exception { |
| 46 | + DataJdbcTypeExcludeFilter filter = new DataJdbcTypeExcludeFilter(UsingDefaultFilters.class); |
| 47 | + assertThat(excludes(filter, AbstractJdbcConfiguration.class)).isFalse(); |
| 48 | + } |
| 49 | + |
| 50 | + private boolean excludes(DataJdbcTypeExcludeFilter filter, Class<?> type) throws IOException { |
| 51 | + MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(type.getName()); |
| 52 | + return filter.match(metadataReader, this.metadataReaderFactory); |
| 53 | + } |
| 54 | + |
| 55 | + @DataJdbcTest |
| 56 | + static class UsingDefaultFilters { |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + @DataJdbcTest(useDefaultFilters = false) |
| 61 | + static class NotUsingDefaultFilters { |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments