Search in sources :

Example 16 with FreeMarkerConfigurationFactoryBean

use of org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean in project cloudbreak by hortonworks.

the class TestConfig method configurationProvider.

@Bean
public freemarker.template.Configuration configurationProvider() throws IOException, TemplateException {
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    return factoryBean.getObject();
}
Also used : FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) MockBean(org.springframework.boot.test.mock.mockito.MockBean) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 17 with FreeMarkerConfigurationFactoryBean

use of org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean in project cloudbreak by hortonworks.

the class UserDataBuilderTest method setup.

@BeforeEach
void setup() throws IOException, TemplateException {
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    Configuration configuration = factoryBean.getObject();
    underTest.setFreemarkerConfiguration(configuration);
    UserDataBuilderParams params = new UserDataBuilderParams();
    params.setCustomData("date >> /tmp/time.txt");
    ReflectionTestUtils.setField(underTest, "userDataBuilderParams", params);
    environment = new DetailedEnvironmentResponse();
    environment.setCrn("environmentCrn");
}
Also used : FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with FreeMarkerConfigurationFactoryBean

use of org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean in project spring-boot by spring-projects.

the class FreeMarkerNonWebConfiguration method freeMarkerConfiguration.

@Bean
@ConditionalOnMissingBean
FreeMarkerConfigurationFactoryBean freeMarkerConfiguration() {
    FreeMarkerConfigurationFactoryBean freeMarkerFactoryBean = new FreeMarkerConfigurationFactoryBean();
    applyProperties(freeMarkerFactoryBean);
    return freeMarkerFactoryBean;
}
Also used : FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 19 with FreeMarkerConfigurationFactoryBean

use of org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean in project springframework-source-5.1.x by wb02125055.

the class FreeMarkerConfigurerTests method freeMarkerConfigurationFactoryBeanWithResourceLoaderPath.

@Test
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    fcfb.setTemplateLoaderPath("file:/mydir");
    fcfb.afterPropertiesSet();
    Configuration cfg = fcfb.getObject();
    assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}
Also used : FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) SpringTemplateLoader(org.springframework.ui.freemarker.SpringTemplateLoader) Test(org.junit.Test)

Example 20 with FreeMarkerConfigurationFactoryBean

use of org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean in project springframework-source-5.1.x by wb02125055.

the class FreeMarkerConfigurerTests method freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath.

@Test
@SuppressWarnings("rawtypes")
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    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(), instanceOf(Configuration.class));
    Configuration fc = fcfb.getObject();
    Template ft = fc.getTemplate("test");
    assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap()));
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) FileSystemResource(org.springframework.core.io.FileSystemResource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Template(freemarker.template.Template) Test(org.junit.Test)

Aggregations

FreeMarkerConfigurationFactoryBean (org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean)24 Configuration (freemarker.template.Configuration)10 Test (org.junit.Test)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Bean (org.springframework.context.annotation.Bean)6 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 Before (org.junit.Before)5 FileSystemResource (org.springframework.core.io.FileSystemResource)4 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)3 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)3 Security (com.sequenceiq.cloudbreak.cloud.model.Security)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)2 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)2 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)2 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)2 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)2 Template (freemarker.template.Template)2