|  | 
| 15 | 15 |  */ | 
| 16 | 16 | package org.springframework.data.aot; | 
| 17 | 17 | 
 | 
| 18 |  | -import static org.mockito.Mockito.*; | 
| 19 |  | - | 
| 20 | 18 | import java.util.function.Consumer; | 
| 21 | 19 | 
 | 
| 22 | 20 | import org.assertj.core.api.Assertions; | 
| 23 |  | -import org.junit.jupiter.api.Test; | 
| 24 | 21 | import org.junit.jupiter.params.ParameterizedTest; | 
| 25 | 22 | import org.junit.jupiter.params.provider.CsvSource; | 
| 26 |  | -import org.mockito.Mock; | 
| 27 | 23 | import org.mockito.Mockito; | 
| 28 |  | -import org.mockito.junit.jupiter.MockitoSettings; | 
| 29 |  | - | 
| 30 | 24 | import org.springframework.aot.generate.GenerationContext; | 
| 31 |  | -import org.springframework.aot.test.generate.TestGenerationContext; | 
| 32 |  | -import org.springframework.beans.factory.BeanFactory; | 
| 33 | 25 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | 
| 34 | 26 | import org.springframework.core.env.Environment; | 
| 35 |  | -import org.springframework.data.aot.types.Address; | 
| 36 |  | -import org.springframework.data.aot.types.Customer; | 
| 37 |  | -import org.springframework.data.aot.types.EmptyType1; | 
| 38 | 27 | import org.springframework.mock.env.MockEnvironment; | 
| 39 | 28 | import org.springframework.util.StringUtils; | 
| 40 | 29 | 
 | 
|  | 
| 44 | 33 |  * @author Mark Paluch | 
| 45 | 34 |  * @author Christoph Strobl | 
| 46 | 35 |  */ | 
| 47 |  | -@MockitoSettings(strictness = org.mockito.quality.Strictness.LENIENT) | 
| 48 | 36 | class AotContextUnitTests { | 
| 49 | 37 | 
 | 
| 50 |  | -	@Mock BeanFactory beanFactory; | 
| 51 |  | - | 
| 52 |  | -	@Mock AotMappingContext mappingContext; | 
| 53 |  | - | 
| 54 |  | -	MockEnvironment mockEnvironment = new MockEnvironment(); | 
| 55 |  | - | 
| 56 |  | -	@Test // GH-2595 | 
| 57 |  | -	void shouldContributeAccessorByDefault() { | 
| 58 |  | - | 
| 59 |  | -		contributeAccessor(Address.class); | 
| 60 |  | -		verify(mappingContext).contribute(Address.class); | 
| 61 |  | -	} | 
| 62 |  | - | 
| 63 |  | -	@Test // GH-2595 | 
| 64 |  | -	void shouldConsiderDisabledAccessors() { | 
| 65 |  | - | 
| 66 |  | -		mockEnvironment.setProperty("spring.aot.data.accessors.enabled", "false"); | 
| 67 |  | - | 
| 68 |  | -		contributeAccessor(Address.class); | 
| 69 |  | - | 
| 70 |  | -		verifyNoInteractions(mappingContext); | 
| 71 |  | -	} | 
| 72 |  | - | 
| 73 |  | -	@Test // GH-2595 | 
| 74 |  | -	void shouldApplyExcludeFilters() { | 
| 75 |  | - | 
| 76 |  | -		mockEnvironment.setProperty("spring.aot.data.accessors.exclude", | 
| 77 |  | -				Customer.class.getName() + " , " + EmptyType1.class.getName()); | 
| 78 |  | - | 
| 79 |  | -		contributeAccessor(Address.class, Customer.class, EmptyType1.class); | 
| 80 |  | - | 
| 81 |  | -		verify(mappingContext).contribute(Address.class); | 
| 82 |  | -		verifyNoMoreInteractions(mappingContext); | 
| 83 |  | -	} | 
| 84 |  | - | 
| 85 |  | -	@Test // GH-2595 | 
| 86 |  | -	void shouldApplyIncludeExcludeFilters() { | 
| 87 |  | - | 
| 88 |  | -		mockEnvironment.setProperty("spring.aot.data.accessors.include", Customer.class.getPackageName() + ".Add*"); | 
| 89 |  | -		mockEnvironment.setProperty("spring.aot.data.accessors.exclude", Customer.class.getPackageName() + ".**"); | 
| 90 |  | - | 
| 91 |  | -		contributeAccessor(Address.class, Customer.class, EmptyType1.class); | 
| 92 |  | - | 
| 93 |  | -		verify(mappingContext).contribute(Address.class); | 
| 94 |  | -		verifyNoMoreInteractions(mappingContext); | 
| 95 |  | -	} | 
| 96 |  | - | 
| 97 |  | -	private void contributeAccessor(Class<?>... classes) { | 
| 98 |  | - | 
| 99 |  | -		DefaultAotContext context = new DefaultAotContext(beanFactory, mockEnvironment, mappingContext); | 
| 100 |  | - | 
| 101 |  | -		for (Class<?> aClass : classes) { | 
| 102 |  | -			context.typeConfiguration(aClass, AotTypeConfiguration::contributeAccessors); | 
| 103 |  | -		} | 
| 104 |  | - | 
| 105 |  | -		context.contributeTypeConfigurations(new TestGenerationContext()); | 
| 106 |  | -	} | 
| 107 |  | - | 
| 108 | 38 | 	@ParameterizedTest // GH-3322 | 
| 109 | 39 | 	@CsvSource({ // | 
| 110 | 40 | 			"'spring.aot.repositories.enabled', '', '', '', true", // | 
|  | 
0 commit comments