|
| 1 | +/* |
| 2 | + * Copyright 2012-2018 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.boot.autoconfigure.web; |
| 18 | + |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 23 | +import org.springframework.boot.test.util.EnvironmentTestUtils; |
| 24 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 25 | +import org.springframework.context.annotation.Configuration; |
| 26 | + |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; |
| 28 | + |
| 29 | +/** |
| 30 | + * Binding tests for {@link ResourceProperties}. |
| 31 | + * |
| 32 | + * @author Stephane Nicoll |
| 33 | + */ |
| 34 | +public class ResourcePropertiesBindingTests { |
| 35 | + |
| 36 | + private AnnotationConfigApplicationContext context; |
| 37 | + |
| 38 | + @After |
| 39 | + public void close() { |
| 40 | + if (this.context != null) { |
| 41 | + this.context.close(); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void staticLocationsExpandArray() { |
| 47 | + ResourceProperties properties = load( |
| 48 | + "spring.resources.static-locations[0]=classpath:/one/", |
| 49 | + "spring.resources.static-locations[1]=classpath:/two", |
| 50 | + "spring.resources.static-locations[2]=classpath:/three/", |
| 51 | + "spring.resources.static-locations[3]=classpath:/four", |
| 52 | + "spring.resources.static-locations[4]=classpath:/five/", |
| 53 | + "spring.resources.static-locations[5]=classpath:/six"); |
| 54 | + assertThat(properties.getStaticLocations()).contains("classpath:/one/", |
| 55 | + "classpath:/two/", "classpath:/three/", "classpath:/four/", |
| 56 | + "classpath:/five/", "classpath:/six/"); |
| 57 | + } |
| 58 | + |
| 59 | + private ResourceProperties load(String... environment) { |
| 60 | + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
| 61 | + EnvironmentTestUtils.addEnvironment(ctx, environment); |
| 62 | + ctx.register(TestConfiguration.class); |
| 63 | + ctx.refresh(); |
| 64 | + this.context = ctx; |
| 65 | + return this.context.getBean(ResourceProperties.class); |
| 66 | + } |
| 67 | + |
| 68 | + @Configuration |
| 69 | + @EnableConfigurationProperties(ResourceProperties.class) |
| 70 | + static class TestConfiguration { |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments