Search in sources :

Example 11 with FreeMarkerConfigurationFactoryBean

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

the class FreeMarkerConfigurerTests method freeMarkerConfigurationFactoryBeanWithConfigLocation.

@Test(expected = IOException.class)
public void freeMarkerConfigurationFactoryBeanWithConfigLocation() throws Exception {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    fcfb.setFreemarkerSettings(props);
    fcfb.afterPropertiesSet();
}
Also used : FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with FreeMarkerConfigurationFactoryBean

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

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)

Example 13 with FreeMarkerConfigurationFactoryBean

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

the class EmailSenderHostServiceTypeTest method freemarkerConfiguration.

Configuration freemarkerConfiguration() 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)

Example 14 with FreeMarkerConfigurationFactoryBean

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

the class HeatTemplateBuilderTest method setup.

@Before
public void setup() throws IOException, TemplateException {
    initMocks(this);
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    Configuration configuration = factoryBean.getObject();
    ReflectionTestUtils.setField(heatTemplateBuilder, "freemarkerConfiguration", configuration);
    ReflectionTestUtils.setField(heatTemplateBuilder, "openStackHeatTemplatePath", templatePath);
    stackName = "testStack";
    groups = new ArrayList<>(1);
    String name = "master";
    List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
    InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    Security security = new Security(rules, null);
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    Map<String, String> tags = new HashMap<>();
    tags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
    tags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
    tags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
    tags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
    tags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
    tags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
    tags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
    when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(tags);
    image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "url", "default", null);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Matchers.containsString(org.hamcrest.Matchers.containsString) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Example 15 with FreeMarkerConfigurationFactoryBean

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

the class AzureNetworkTemplateBuilderTest method before.

@Before
public void before() throws IOException, TemplateException {
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    ReflectionTestUtils.setField(underTest, "freemarkerConfiguration", factoryBean.getObject());
    ReflectionTestUtils.setField(underTest, "armTemplatePath", "templates/arm-network.ftl");
}
Also used : FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Before(org.junit.Before)

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