use of cn.taketoday.core.io.ResourceLoader in project today-infrastructure by TAKETODAY.
the class FreeMarkerConfigurationFactoryBeanTests method freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath.
@Test
@SuppressWarnings("rawtypes")
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
fcfb.setTemplateLoaderPath("file:/mydir");
Properties settings = new Properties();
settings.setProperty("localized_lookup", "false");
fcfb.setFreemarkerSettings(settings);
fcfb.setResourceLoader(new ResourceLoader() {
@Override
public Resource getResource(String location) {
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
throw new IllegalArgumentException(location);
}
return new ByteArrayResource("test".getBytes(), "test");
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
});
fcfb.afterPropertiesSet();
assertThat(fcfb.getObject()).isInstanceOf(Configuration.class);
Configuration fc = fcfb.getObject();
Template ft = fc.getTemplate("test");
assertThat(FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())).isEqualTo("test");
}
use of cn.taketoday.core.io.ResourceLoader in project today-infrastructure by TAKETODAY.
the class FreeMarkerConfigurerTests method freeMarkerConfigurerWithNonFileResourceLoaderPath.
@Test
@SuppressWarnings("rawtypes")
public void freeMarkerConfigurerWithNonFileResourceLoaderPath() throws Exception {
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
Properties settings = new Properties();
settings.setProperty("localized_lookup", "false");
freeMarkerConfigurer.setFreemarkerSettings(settings);
freeMarkerConfigurer.setResourceLoader(new ResourceLoader() {
@Override
public Resource getResource(String location) {
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
throw new IllegalArgumentException(location);
}
return new ByteArrayResource("test".getBytes(), "test");
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
});
freeMarkerConfigurer.afterPropertiesSet();
assertThat(freeMarkerConfigurer.getConfiguration()).isInstanceOf(Configuration.class);
Configuration fc = freeMarkerConfigurer.getConfiguration();
Template ft = fc.getTemplate("test");
assertThat(FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())).isEqualTo("test");
}
use of cn.taketoday.core.io.ResourceLoader in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentPostProcessorTests method postProcessEnvironmentWhenCustomLoaderUsesSpecifiedLoaderInstance.
@Test
void postProcessEnvironmentWhenCustomLoaderUsesSpecifiedLoaderInstance() {
ResourceLoader resourceLoader = mock(ResourceLoader.class);
this.application.setResourceLoader(resourceLoader);
willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any());
this.postProcessor.postProcessEnvironment(this.environment, this.application);
then(this.postProcessor).should().getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any());
then(this.configDataEnvironment).should().processAndApply();
assertThat(this.resourceLoaderCaptor.getValue()).isSameAs(resourceLoader);
}
use of cn.taketoday.core.io.ResourceLoader in project today-infrastructure by TAKETODAY.
the class ApplicationTests method customResourceLoaderFromConstructor.
@Test
void customResourceLoaderFromConstructor() {
ResourceLoader resourceLoader = new DefaultResourceLoader();
TestApplication application = new TestApplication(resourceLoader, ExampleWebConfig.class);
this.context = application.run();
then(application.getLoader()).should().setResourceLoader(resourceLoader);
}
use of cn.taketoday.core.io.ResourceLoader in project today-infrastructure by TAKETODAY.
the class ApplicationTests method customResourceLoader.
@Test
void customResourceLoader() {
TestApplication application = new TestApplication(ExampleConfig.class);
application.setApplicationType(ApplicationType.NONE_WEB);
ResourceLoader resourceLoader = new DefaultResourceLoader();
application.setResourceLoader(resourceLoader);
this.context = application.run();
then(application.getLoader()).should().setResourceLoader(resourceLoader);
}
Aggregations