View Javadoc

1   package org.e2etrace.formatter;
2   
3   /*
4    * Copyright 2006 Gunther Popp
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.IOException;
20  import java.io.StringWriter;
21  import java.io.Writer;
22  
23  import org.e2etrace.formatter.AbstractTraceFormatter;
24  import org.e2etrace.formatter.CSVTraceFormatter;
25  import org.e2etrace.trace.ITraceSession;
26  
27  import junit.framework.TestCase;
28  
29  /**
30   * JUnit testcase for {@link org.e2etrace.formatter.CSVTraceFormatter}.
31   * <p>
32   * 
33   * @author Gunther Popp
34   * 
35   */
36  public class CSVTraceFormatterTest extends TestCase {
37  
38    private static String EXPECTED = "id,path,threadname,duration,isolated_duration"
39        + System.getProperty("line.separator") 
40        + "$TestSession,$TestSession,main,195,0"
41        + System.getProperty("line.separator") 
42        + "Root_1,$TestSession|Root_1,main,110,40"
43        + System.getProperty("line.separator")
44        + "Child_1_1,$TestSession|Root_1|Child_1_1,main,70,70"
45        + System.getProperty("line.separator") 
46        + "Root_2,$TestSession|Root_2,main,80,0"
47        + System.getProperty("line.separator")
48        + "Child_2_1,$TestSession|Root_2|Child_2_1,main,80,50"
49        + System.getProperty("line.separator")
50        + "Child_2_2,$TestSession|Root_2|Child_2_1|Child_2_2,main,20,20"
51        + System.getProperty("line.separator")
52        + "Child_2_3,$TestSession|Root_2|Child_2_1|Child_2_3,main,10,10"
53        + System.getProperty("line.separator") 
54        + "Root_3,$TestSession|Root_3,main,5,5"
55        + System.getProperty("line.separator");
56  
57    public static void main(String[] args) {
58      junit.textui.TestRunner.run(CSVTraceFormatterTest.class);
59    }
60  
61    /**
62     * Test case for <code>format</code>
63     * 
64     * @throws IOException Error while generating test output
65     * 
66     */
67    public void testFormat() throws IOException {
68      ITraceSession session;
69      Writer testOutput;
70      AbstractTraceFormatter formatter;
71  
72      session = GenerateTestSession.generate();
73      formatter = new CSVTraceFormatter();
74      testOutput = new StringWriter();
75  
76      formatter.format(session, testOutput);
77  
78      assertEquals("CSV output not equal", EXPECTED, testOutput.toString());
79  
80    }
81  
82  }