|
2 | 2 |
|
3 | 3 | import formflow.library.config.FormFlowConfigurationProperties;
|
4 | 4 | import formflow.library.config.FlowConfiguration;
|
| 5 | + |
5 | 6 | import java.util.List;
|
| 7 | + |
6 | 8 | import org.mockito.Mockito;
|
7 | 9 | import org.springframework.beans.factory.annotation.Autowired;
|
| 10 | +import org.springframework.beans.factory.annotation.Value; |
8 | 11 | import org.springframework.boot.test.context.TestConfiguration;
|
9 | 12 | import org.springframework.context.annotation.Bean;
|
10 | 13 | import org.springframework.context.annotation.Primary;
|
|
15 | 18 | @TestConfiguration
|
16 | 19 | public class SpyInterceptorConfig implements WebMvcConfigurer {
|
17 | 20 |
|
18 |
| - @Autowired |
19 |
| - private List<FlowConfiguration> flowConfigurations; |
20 |
| - |
21 |
| - @Autowired |
22 |
| - private FormFlowConfigurationProperties formFlowConfigurationProperties; |
23 |
| - |
24 |
| - @Bean |
25 |
| - @Primary |
26 |
| - public LocaleChangeInterceptor localeChangeInterceptor() { |
27 |
| - return Mockito.spy(new LocaleChangeInterceptor()); |
28 |
| - } |
29 |
| - |
30 |
| - @Bean |
31 |
| - @Primary // Ensure this bean takes precedence over the real one |
32 |
| - public SessionContinuityInterceptor dataRequiredInterceptor() { |
33 |
| - return Mockito.spy(new SessionContinuityInterceptor(flowConfigurations)); |
34 |
| - } |
35 |
| - |
36 |
| - @Bean |
37 |
| - @Primary |
38 |
| - public DisabledFlowInterceptor disabledFlowInterceptor() { |
39 |
| - return Mockito.spy(new DisabledFlowInterceptor(formFlowConfigurationProperties)); |
40 |
| - } |
41 |
| - |
42 |
| - @Override |
43 |
| - public void addInterceptors(InterceptorRegistry registry) { |
44 |
| - registry.addInterceptor(localeChangeInterceptor()); |
45 |
| - registry.addInterceptor(dataRequiredInterceptor()); |
46 |
| - registry.addInterceptor(disabledFlowInterceptor()); |
47 |
| - } |
| 21 | + @Autowired |
| 22 | + private List<FlowConfiguration> flowConfigurations; |
| 23 | + |
| 24 | + @Autowired |
| 25 | + private FormFlowConfigurationProperties formFlowConfigurationProperties; |
| 26 | + |
| 27 | + @Value("${form-flow.session-continuity-interceptor.redirect-url:/}") |
| 28 | + private String redirectUrl; |
| 29 | + |
| 30 | + @Bean |
| 31 | + @Primary |
| 32 | + public LocaleChangeInterceptor localeChangeInterceptor() { |
| 33 | + return Mockito.spy(new LocaleChangeInterceptor()); |
| 34 | + } |
| 35 | + |
| 36 | + @Bean |
| 37 | + @Primary // Ensure this bean takes precedence over the real one |
| 38 | + public SessionContinuityInterceptor dataRequiredInterceptor() { |
| 39 | + return Mockito.spy(new SessionContinuityInterceptor(flowConfigurations, redirectUrl)); |
| 40 | + } |
| 41 | + |
| 42 | + @Bean |
| 43 | + @Primary |
| 44 | + public DisabledFlowInterceptor disabledFlowInterceptor() { |
| 45 | + return Mockito.spy(new DisabledFlowInterceptor(formFlowConfigurationProperties)); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void addInterceptors(InterceptorRegistry registry) { |
| 50 | + registry.addInterceptor(localeChangeInterceptor()); |
| 51 | + registry.addInterceptor(dataRequiredInterceptor()); |
| 52 | + registry.addInterceptor(disabledFlowInterceptor()); |
| 53 | + } |
48 | 54 | }
|
0 commit comments