19
19
import static org .mockito .Mockito .*;
20
20
21
21
import java .lang .annotation .Annotation ;
22
- import java .util .Collection ;
23
22
import java .util .Collections ;
24
23
import java .util .List ;
25
24
import java .util .Set ;
26
- import java .util .function .Consumer ;
27
25
28
26
import org .jmolecules .ddd .annotation .Entity ;
29
- import org .jspecify .annotations .Nullable ;
30
27
import org .junit .jupiter .api .Test ;
31
28
import org .junitpioneer .jupiter .ClearSystemProperty ;
32
29
import org .junitpioneer .jupiter .SetSystemProperty ;
36
33
import org .springframework .aot .generate .DefaultGenerationContext ;
37
34
import org .springframework .aot .generate .GenerationContext ;
38
35
import org .springframework .aot .generate .InMemoryGeneratedFiles ;
39
- import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
40
36
import org .springframework .context .support .AbstractApplicationContext ;
41
37
import org .springframework .context .support .GenericApplicationContext ;
42
38
import org .springframework .core .annotation .MergedAnnotation ;
43
- import org .springframework .core .env .Environment ;
44
- import org .springframework .core .env .StandardEnvironment ;
45
39
import org .springframework .data .annotation .Id ;
46
40
import org .springframework .data .aot .AotContext ;
47
- import org .springframework .data .aot .AotTypeConfiguration ;
48
41
import org .springframework .data .mongodb .repository .support .SimpleMongoRepository ;
49
42
import org .springframework .data .repository .Repository ;
50
- import org .springframework .data .repository .config .AotRepositoryContext ;
43
+ import org .springframework .data .repository .config .AotRepositoryContextSupport ;
51
44
import org .springframework .data .repository .config .AotRepositoryInformation ;
52
45
import org .springframework .data .repository .config .RepositoryConfigurationSource ;
53
46
import org .springframework .data .repository .core .RepositoryInformation ;
@@ -65,10 +58,10 @@ class AotMongoRepositoryPostProcessorUnitTests {
65
58
@ SetSystemProperty (key = AotDetector .AOT_ENABLED , value = "true" )
66
59
void repositoryProcessorShouldEnableAotRepositoriesByDefaultWhenAotIsEnabled () {
67
60
68
- GenerationContext ctx = createGenerationContext ();
69
61
GenericApplicationContext context = new GenericApplicationContext ();
62
+ context .refresh ();
70
63
71
- MongoRepositoryContributor contributor = createContributorWithPersonTypes (context , ctx );
64
+ MongoRepositoryContributor contributor = createContributorWithPersonTypes (context );
72
65
73
66
assertThat (contributor ).isNotNull ();
74
67
}
@@ -77,10 +70,10 @@ void repositoryProcessorShouldEnableAotRepositoriesByDefaultWhenAotIsEnabled() {
77
70
@ ClearSystemProperty (key = AotContext .GENERATED_REPOSITORIES_ENABLED )
78
71
void shouldEnableAotRepositoriesByDefault () {
79
72
80
- GenerationContext ctx = createGenerationContext ();
81
73
GenericApplicationContext context = new GenericApplicationContext ();
74
+ context .refresh ();
82
75
83
- MongoRepositoryContributor contributor = createContributorWithPersonTypes (context , ctx );
76
+ MongoRepositoryContributor contributor = createContributorWithPersonTypes (context );
84
77
85
78
assertThat (contributor ).isNotNull ();
86
79
}
@@ -89,10 +82,10 @@ void shouldEnableAotRepositoriesByDefault() {
89
82
@ SetSystemProperty (key = AotContext .GENERATED_REPOSITORIES_ENABLED , value = "false" )
90
83
void shouldDisableAotRepositoriesWhenGeneratedRepositoriesIsFalse () {
91
84
92
- GenerationContext ctx = createGenerationContext ();
93
85
GenericApplicationContext context = new GenericApplicationContext ();
86
+ context .refresh ();
94
87
95
- MongoRepositoryContributor contributor = createContributorWithPersonTypes (context , ctx );
88
+ MongoRepositoryContributor contributor = createContributorWithPersonTypes (context );
96
89
97
90
assertThat (contributor ).isNull ();
98
91
}
@@ -101,10 +94,10 @@ void shouldDisableAotRepositoriesWhenGeneratedRepositoriesIsFalse() {
101
94
@ SetSystemProperty (key = "spring.aot.mongodb.repositories.enabled" , value = "false" )
102
95
void shouldDisableAotRepositoriesWhenJpaGeneratedRepositoriesIsFalse () {
103
96
104
- GenerationContext ctx = createGenerationContext ();
105
97
GenericApplicationContext context = new GenericApplicationContext ();
98
+ context .refresh ();
106
99
107
- MongoRepositoryContributor contributor = createContributorWithPersonTypes (context , ctx );
100
+ MongoRepositoryContributor contributor = createContributorWithPersonTypes (context );
108
101
109
102
assertThat (contributor ).isNull ();
110
103
}
@@ -113,15 +106,14 @@ private GenerationContext createGenerationContext() {
113
106
return new DefaultGenerationContext (new ClassNameGenerator (ClassName .OBJECT ), new InMemoryGeneratedFiles ());
114
107
}
115
108
116
- private MongoRepositoryContributor createContributorWithPersonTypes (GenericApplicationContext context ,
117
- GenerationContext ctx ) {
109
+ private MongoRepositoryContributor createContributorWithPersonTypes (GenericApplicationContext context ) {
118
110
119
- return new AotMongoRepositoryPostProcessor ().contribute (new DummyAotRepositoryContext (context ) {
111
+ return new AotMongoRepositoryPostProcessor ().contributeAotRepository (new DummyAotRepositoryContext (context ) {
120
112
@ Override
121
113
public Set <Class <?>> getResolvedTypes () {
122
114
return Collections .singleton (Person .class );
123
115
}
124
- }, ctx );
116
+ });
125
117
}
126
118
127
119
@ Entity
@@ -131,22 +123,15 @@ static class Person {
131
123
132
124
interface PersonRepository extends Repository <Person , Long > {}
133
125
134
- static class DummyAotRepositoryContext implements AotRepositoryContext {
126
+ static class DummyAotRepositoryContext extends AotRepositoryContextSupport {
135
127
136
- private final @ Nullable AbstractApplicationContext applicationContext ;
137
-
138
- DummyAotRepositoryContext (@ Nullable AbstractApplicationContext applicationContext ) {
139
- this .applicationContext = applicationContext ;
140
- }
141
-
142
- @ Override
143
- public String getBeanName () {
144
- return "jpaRepository" ;
128
+ DummyAotRepositoryContext (AbstractApplicationContext applicationContext ) {
129
+ super (AotContext .from (applicationContext , applicationContext .getEnvironment ()));
145
130
}
146
131
147
132
@ Override
148
133
public String getModuleName () {
149
- return "JPA " ;
134
+ return "MongoDB " ;
150
135
}
151
136
152
137
@ Override
@@ -180,40 +165,6 @@ public Set<Class<?>> getResolvedTypes() {
180
165
return Set .of ();
181
166
}
182
167
183
- @ Override
184
- public Set <Class <?>> getUserDomainTypes () {
185
- return Set .of ();
186
- }
187
-
188
- @ Override
189
- public ConfigurableListableBeanFactory getBeanFactory () {
190
- return applicationContext != null ? applicationContext .getBeanFactory () : null ;
191
- }
192
-
193
- @ Override
194
- public Environment getEnvironment () {
195
- return applicationContext == null ? new StandardEnvironment () : applicationContext .getEnvironment ();
196
- }
197
-
198
- @ Override
199
- public TypeIntrospector introspectType (String typeName ) {
200
- return null ;
201
- }
202
-
203
- @ Override
204
- public IntrospectedBeanDefinition introspectBeanDefinition (String beanName ) {
205
- return null ;
206
- }
207
-
208
- @ Override
209
- public void typeConfiguration (Class <?> type , Consumer <AotTypeConfiguration > configurationConsumer ) {
210
-
211
- }
212
-
213
- @ Override
214
- public Collection <AotTypeConfiguration > typeConfigurations () {
215
- return List .of ();
216
- }
217
168
}
218
169
219
170
}
0 commit comments