コード例 #1
0
  public void testVelocityConfigurerWithCsvPathAndNonFileAccess()
      throws IOException, VelocityException {
    VelocityConfigurer vc = new VelocityConfigurer();
    vc.setResourceLoaderPath("file:/mydir,file:/yourdir");
    vc.setResourceLoader(
        new ResourceLoader() {
          @Override
          public Resource getResource(String location) {
            if ("file:/yourdir/test".equals(location)) {
              return new DescriptiveResource("");
            }
            return new ByteArrayResource("test".getBytes(), "test");
          }

          @Override
          public ClassLoader getClassLoader() {
            return getClass().getClassLoader();
          }
        });
    vc.setPreferFileSystemAccess(false);
    vc.afterPropertiesSet();
    assertThat(vc.createVelocityEngine(), instanceOf(VelocityEngine.class));
    VelocityEngine ve = vc.createVelocityEngine();
    assertEquals("test", VelocityEngineUtils.mergeTemplateIntoString(ve, "test", new HashMap()));
  }
コード例 #2
0
 public void testVelocityConfigurer() throws IOException, VelocityException {
   VelocityConfigurer vc = new VelocityConfigurer();
   vc.setResourceLoaderPath("file:/mydir");
   vc.afterPropertiesSet();
   assertThat(vc.createVelocityEngine(), instanceOf(VelocityEngine.class));
   VelocityEngine ve = vc.createVelocityEngine();
   assertEquals(
       new File("/mydir").getAbsolutePath(),
       ve.getProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH));
 }