@Bean public FreeMarkerConfigurationFactoryBean freeMarkerConfiguration() { FreeMarkerConfigurationFactoryBean freeMarkerFactoryBean = new FreeMarkerConfigurationFactoryBean(); freeMarkerFactoryBean.setTemplateLoaderPaths("classpath:/templates"); freeMarkerFactoryBean.setPreferFileSystemAccess(true); freeMarkerFactoryBean.setDefaultEncoding("UTF-8"); return freeMarkerFactoryBean; }
public void testFreemarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws IOException, TemplateException { 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())); }
@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(); }
@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); }
@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())); }
@Bean @ConditionalOnMissingBean public FreeMarkerConfigurationFactoryBean freeMarkerConfiguration() { FreeMarkerConfigurationFactoryBean freeMarkerFactoryBean = new FreeMarkerConfigurationFactoryBean(); applyProperties(freeMarkerFactoryBean); return freeMarkerFactoryBean; }
public FreemarkerCheckTool(final String templateLoaderPath) throws Exception { final FreeMarkerConfigurationFactoryBean fmCfgFactory = new FreeMarkerConfigurationFactoryBean(); fmCfgFactory.setTemplateLoaderPaths(new String[] { templateLoaderPath, SPRING_FTL_LOADER_PATH }); fmCfgFactory.afterPropertiesSet(); freemarkerConfiguration = fmCfgFactory.getObject(); }
public void testFreemarkerConfigurationFactoryBeanWithConfigLocation() throws TemplateException { FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean(); fcfb.setConfigLocation(new FileSystemResource("myprops.properties")); Properties props = new Properties(); props.setProperty("myprop", "/mydir"); fcfb.setFreemarkerSettings(props); try { fcfb.afterPropertiesSet(); fail("Should have thrown IOException"); } catch (IOException ex) { // expected } }
public void testFreeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception { FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean(); fcfb.setTemplateLoaderPath("file:/mydir"); fcfb.afterPropertiesSet(); Configuration cfg = fcfb.getObject(); assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader); }
@Bean public freemarker.template.Configuration freemarkerConfiguration() { FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean(); factoryBean.setPreferFileSystemAccess(false); factoryBean.setTemplateLoaderPath("classpath:/"); return factoryBean.getObject(); }
@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); }
Configuration freemarkerConfiguration() throws IOException, TemplateException { FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean(); factoryBean.setPreferFileSystemAccess(false); factoryBean.setTemplateLoaderPath("classpath:/"); factoryBean.afterPropertiesSet(); return factoryBean.getObject(); }
@Before public void setup() throws IOException, TemplateException { FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean(); factoryBean.setPreferFileSystemAccess(false); factoryBean.setTemplateLoaderPath("classpath:/"); factoryBean.afterPropertiesSet(); Configuration configuration = factoryBean.getObject(); USER_DATA_BUILDER.setFreemarkerConfiguration(configuration); UserDataBuilderParams params = new UserDataBuilderParams(); params.setCustomData("date >> /tmp/time.txt"); ReflectionTestUtils.setField(USER_DATA_BUILDER, "userDataBuilderParams", params); }
@Bean public FreeMarkerConfigurationFactoryBean freemarkerMailConfiguration() { FreeMarkerConfigurationFactoryBean configuration = new FreeMarkerConfigurationFactoryBean(); configuration.setTemplateLoaderPath("classpath:notification"); return configuration; }
@Bean public FreeMarkerConfigurationFactoryBean freeMarkerConfigurationFactoryBean() { FreeMarkerConfigurationFactoryBean configurationBean = new FreeMarkerConfigurationFactoryBean(); configurationBean.setTemplateLoaderPath("classpath:/print"); return configurationBean; }
@Before public void setUp() throws Exception { initMocks(this); FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean(); factoryBean.setPreferFileSystemAccess(false); factoryBean.setTemplateLoaderPath("classpath:/"); factoryBean.afterPropertiesSet(); Configuration configuration = factoryBean.getObject(); ReflectionTestUtils.setField(cloudFormationTemplateBuilder, "freemarkerConfiguration", configuration); awsCloudFormationTemplate = configuration.getTemplate(templatePath, "UTF-8").toString(); authenticatedContext = authenticatedContext(); existingSubnetCidr = "testSubnet"; 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); Map<InstanceGroupType, String> userData = ImmutableMap.of( InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY" ); Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id"); List<Group> groups = new ArrayList<>(); groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey())); groups.add(new Group(name, InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey())); Network network = new Network(new Subnet("testSubnet")); Map<String, String> parameters = new HashMap<>(); parameters.put("persistentStorage", "persistentStorageTest"); parameters.put("attachedStorageOption", "attachedStorageOptionTest"); Map<String, String> tags = new HashMap<>(); tags.put("testtagkey", "testtagvalue"); defaultTags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key()); defaultTags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key()); defaultTags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key()); defaultTags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key()); defaultTags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key()); defaultTags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key()); defaultTags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key()); cloudStack = new CloudStack(groups, network, image, parameters, tags, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()); }
@Before public void setUp() throws Exception { initMocks(this); FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean(); factoryBean.setPreferFileSystemAccess(false); factoryBean.setTemplateLoaderPath("classpath:/"); factoryBean.afterPropertiesSet(); Configuration configuration = factoryBean.getObject(); ReflectionTestUtils.setField(azureTemplateBuilder, "freemarkerConfiguration", configuration); ReflectionTestUtils.setField(azureTemplateBuilder, "armTemplatePath", templatePath); ReflectionTestUtils.setField(azureTemplateBuilder, "armTemplateParametersPath", "templates/parameters.ftl"); Map<InstanceGroupType, String> userData = ImmutableMap.of( InstanceGroupType.CORE, CORE_CUSTOM_DATA, InstanceGroupType.GATEWAY, GATEWAY_CUSTOM_DATA ); groups = new ArrayList<>(); stackName = "testStack"; 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); Map<String, Object> params = new HashMap<>(); params.put(CloudInstance.SUBNET_ID, "existingSubnet"); InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak"); instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication, params); List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[]{new PortDefinition("22", "22"), new PortDefinition("443", "443")}, "tcp")); security = new Security(rules, null); image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id"); cloudContext = new CloudContext(7899L, "thisisaverylongazureresourcenamewhichneedstobeshortened", "dummy1", "dummy2", "test", Location.location(Region.region("EU"), new AvailabilityZone("availabilityZone"))); azureCredentialView = new AzureCredentialView(cloudCredential("siq-haas")); azureStorageView = new AzureStorageView(azureCredentialView, cloudContext, azureStorage, null); azureSubnetStrategy = AzureSubnetStrategy.getAzureSubnetStrategy(FILL, Collections.singletonList("existingSubnet"), ImmutableMap.of("existingSubnet", 100)); defaultTags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key()); defaultTags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key()); defaultTags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key()); defaultTags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key()); defaultTags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key()); defaultTags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key()); defaultTags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key()); reset(azureUtils); }