|
| 1 | +/* |
| 2 | + * Copyright 2012-2020 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; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.AfterAll; |
| 20 | +import org.junit.jupiter.api.BeforeAll; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 23 | + |
| 24 | +import org.springframework.beans.factory.BeanDefinitionStoreException; |
| 25 | +import org.springframework.boot.testsupport.classpath.ModifiedClassPathExtension; |
| 26 | +import org.springframework.context.support.StaticApplicationContext; |
| 27 | + |
| 28 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 29 | + |
| 30 | +@ExtendWith(ModifiedClassPathExtension.class) |
| 31 | +class IgnoringXmlBeanDefinitionLoaderTests { |
| 32 | + |
| 33 | + @BeforeAll |
| 34 | + static void ignoreXml() { |
| 35 | + System.setProperty("spring.xml.ignore", "true"); |
| 36 | + } |
| 37 | + |
| 38 | + @AfterAll |
| 39 | + static void enableXml() { |
| 40 | + System.clearProperty("spring.xml.ignore"); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void whenXmlSupportIsDisabledXmlSourcesAreRejected() { |
| 45 | + assertThatExceptionOfType(BeanDefinitionStoreException.class) |
| 46 | + .isThrownBy(() -> new BeanDefinitionLoader(new StaticApplicationContext(), |
| 47 | + "classpath:org/springframework/boot/sample-beans.xml").load()) |
| 48 | + .withMessage("Cannot load XML bean definitions when XML support is disabled"); |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments