|
| 1 | +/* |
| 2 | + * Copyright 2002-2017 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 | + * http://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.context.annotation; |
| 18 | + |
| 19 | +import org.junit.Ignore; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import org.springframework.core.type.AnnotatedTypeMetadata; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author Andy Wilkinson |
| 26 | + * @author Juergen Hoeller |
| 27 | + */ |
| 28 | +public class Spr16217Tests { |
| 29 | + |
| 30 | + @Test |
| 31 | + @Ignore("TODO") |
| 32 | + public void baseConfigurationIsIncludedWhenFirstSuperclassReferenceIsSkippedInRegisterBeanPhase() { |
| 33 | + try (AnnotationConfigApplicationContext context = |
| 34 | + new AnnotationConfigApplicationContext(RegisterBeanPhaseImportingConfiguration.class)) { |
| 35 | + context.getBean("someBean"); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void baseConfigurationIsIncludedWhenFirstSuperclassReferenceIsSkippedInParseConfigurationPhase() { |
| 41 | + try (AnnotationConfigApplicationContext context = |
| 42 | + new AnnotationConfigApplicationContext(ParseConfigurationPhaseImportingConfiguration.class)) { |
| 43 | + context.getBean("someBean"); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void baseConfigurationIsIncludedOnceWhenBothConfigurationClassesAreActive() { |
| 49 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); |
| 50 | + context.setAllowBeanDefinitionOverriding(false); |
| 51 | + context.register(UnconditionalImportingConfiguration.class); |
| 52 | + context.refresh(); |
| 53 | + try { |
| 54 | + context.getBean("someBean"); |
| 55 | + } |
| 56 | + finally { |
| 57 | + context.close(); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + public static class RegisterBeanPhaseCondition implements ConfigurationCondition { |
| 63 | + |
| 64 | + @Override |
| 65 | + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { |
| 66 | + return false; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public ConfigurationPhase getConfigurationPhase() { |
| 71 | + return ConfigurationPhase.REGISTER_BEAN; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | + public static class ParseConfigurationPhaseCondition implements ConfigurationCondition { |
| 77 | + |
| 78 | + @Override |
| 79 | + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public ConfigurationPhase getConfigurationPhase() { |
| 85 | + return ConfigurationPhase.PARSE_CONFIGURATION; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + @Import({RegisterBeanPhaseConditionConfiguration.class, BarConfiguration.class}) |
| 91 | + public static class RegisterBeanPhaseImportingConfiguration { |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + @Import({ParseConfigurationPhaseConditionConfiguration.class, BarConfiguration.class}) |
| 96 | + public static class ParseConfigurationPhaseImportingConfiguration { |
| 97 | + } |
| 98 | + |
| 99 | + |
| 100 | + @Import({UnconditionalConfiguration.class, BarConfiguration.class}) |
| 101 | + public static class UnconditionalImportingConfiguration { |
| 102 | + } |
| 103 | + |
| 104 | + |
| 105 | + public static class BaseConfiguration { |
| 106 | + |
| 107 | + @Bean |
| 108 | + public String someBean() { |
| 109 | + return "foo"; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + |
| 114 | + @Conditional(RegisterBeanPhaseCondition.class) |
| 115 | + public static class RegisterBeanPhaseConditionConfiguration extends BaseConfiguration { |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + @Conditional(ParseConfigurationPhaseCondition.class) |
| 120 | + public static class ParseConfigurationPhaseConditionConfiguration extends BaseConfiguration { |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | + public static class UnconditionalConfiguration extends BaseConfiguration { |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + public static class BarConfiguration extends BaseConfiguration { |
| 129 | + } |
| 130 | + |
| 131 | +} |
0 commit comments