|
| 1 | +/* |
| 2 | + * Copyright 2012-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.boot.autoconfigure.groovy.template; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; |
| 22 | +import org.springframework.core.io.DefaultResourceLoader; |
| 23 | +import org.springframework.core.io.ResourceLoader; |
| 24 | +import org.springframework.mock.env.MockEnvironment; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | + |
| 28 | +/** |
| 29 | + * Tests for {@link GroovyTemplateAvailabilityProvider}. |
| 30 | + * |
| 31 | + * @author Andy Wilkinson |
| 32 | + */ |
| 33 | +public class GroovyTemplateAvailabilityProviderTests { |
| 34 | + |
| 35 | + private final TemplateAvailabilityProvider provider = new GroovyTemplateAvailabilityProvider(); |
| 36 | + |
| 37 | + private final ResourceLoader resourceLoader = new DefaultResourceLoader(); |
| 38 | + |
| 39 | + private final MockEnvironment environment = new MockEnvironment(); |
| 40 | + |
| 41 | + @Test |
| 42 | + public void availabilityOfTemplateInDefaultLocation() { |
| 43 | + assertThat(this.provider.isTemplateAvailable("home", this.environment, |
| 44 | + getClass().getClassLoader(), this.resourceLoader)).isTrue(); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void availabilityOfTemplateThatDoesNotExist() { |
| 49 | + assertThat(this.provider.isTemplateAvailable("whatever", this.environment, |
| 50 | + getClass().getClassLoader(), this.resourceLoader)).isFalse(); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void availabilityOfTemplateWithCustomLoaderPath() { |
| 55 | + this.environment.setProperty("spring.groovy.template.resource-loader-path", |
| 56 | + "classpath:/custom-templates/"); |
| 57 | + assertThat(this.provider.isTemplateAvailable("custom", this.environment, |
| 58 | + getClass().getClassLoader(), this.resourceLoader)).isTrue(); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void availabilityOfTemplateWithCustomPrefix() { |
| 63 | + this.environment.setProperty("spring.groovy.template.prefix", "prefix/"); |
| 64 | + assertThat(this.provider.isTemplateAvailable("prefixed", this.environment, |
| 65 | + getClass().getClassLoader(), this.resourceLoader)).isTrue(); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void availabilityOfTemplateWithCustomSuffix() { |
| 70 | + this.environment.setProperty("spring.groovy.template.suffix", ".groovytemplate"); |
| 71 | + assertThat(this.provider.isTemplateAvailable("suffixed", this.environment, |
| 72 | + getClass().getClassLoader(), this.resourceLoader)).isTrue(); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments