1   /*
2    * Created on 12-Apr-2005
3    */
4   package org.saxbenchmark;
5   
6   import java.io.FileWriter;
7   import java.util.Properties;
8   
9   import junit.framework.TestCase;
10  
11  import org.apache.velocity.app.VelocityEngine;
12  
13  /***
14   * @author JMcCrindle
15   */
16  public class VelocityResultsWriterTest extends TestCase {
17  
18      /*
19       * @see TestCase#setUp()
20       */
21      protected void setUp() throws Exception {
22          super.setUp();
23      }
24  
25      /*
26       * @see TestCase#tearDown()
27       */
28      protected void tearDown() throws Exception {
29          super.tearDown();
30      }
31  
32      /***
33       * Constructor for VelocityResultsWriterTest.
34       * @param name
35       */
36      public VelocityResultsWriterTest(String name) {
37          super(name);
38      }
39  
40      public void testCreateReleaseNotes() throws Throwable {
41  //        <prop key="resource.loader">class</prop>
42  //        <prop key="class.resource.loader.class">
43  //            org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
44  //        </prop>
45          VelocityEngine engine = new VelocityEngine();
46          Properties properties = new Properties();
47          properties.setProperty("resource.loader", "class");
48          properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
49          engine.init(properties);
50          
51          VelocityResultsWriter service = new VelocityResultsWriter();
52          service.setVelocityEngine(engine);
53          service.setTemplateFile("org/saxbenchmark/results.vm");
54          FileWriter writer = new FileWriter("./output/results.xml");
55          SaxBenchmark bench = new SaxBenchmark();
56          DefaultBenchmarkFactory benchmarkFactory = new DefaultBenchmarkFactory();
57          benchmarkFactory.setReaderSupplier(new DefaultReaderSupplier());
58          benchmarkFactory.setSourceFactorySupplier(new FolderSourceFactorySupplier("./src/data"));
59          benchmarkFactory.setCount(1);
60          bench.setBenchmarkFactory(benchmarkFactory);
61          bench.setWriterFactory(new DefaultWriterFactory("./output"));
62  
63          BenchmarkResults results = bench.run();
64          service.writeResults(results, writer);
65          writer.flush();
66          writer.close();
67      }
68  
69  }