View Javadoc

1   // Copyright (C) 2000 Paco Gomez
2   // Copyright (C) 2000 - 2007 Philip Aston
3   // All rights reserved.
4   //
5   // This file is part of The Grinder software distribution. Refer to
6   // the file LICENSE which is part of The Grinder distribution for
7   // licensing details. The Grinder distribution is available on the
8   // Internet at http://grinder.sourceforge.net/
9   //
10  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
14  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
21  // OF THE POSSIBILITY OF SUCH DAMAGE.
22  
23  package net.grinder.statistics;
24  
25  import junit.framework.TestCase;
26  
27  
28  /**
29   * Unit test case for <code>StatisticExpressionFactoryImplementation</code>.
30   *
31   * @author Philip Aston
32   * @see StatisticsSet
33   */
34  public class TestExpressionView extends TestCase {
35  
36    public TestExpressionView(String name) {
37      super(name);
38    }
39  
40    public void testConstruction() throws Exception {
41      final StatisticExpressionFactory statisticExpressionFactory =
42        StatisticsServicesImplementation.getInstance()
43        .getStatisticExpressionFactory();
44  
45      final ExpressionView view =
46        statisticExpressionFactory.createExpressionView(
47          "My view", "(+ userLong0 userLong1)", false);
48  
49      assertEquals("My view", view.getDisplayName());
50      assertTrue(view.getExpression() != null);
51  
52      final ExpressionView view2 =
53        statisticExpressionFactory
54          .createExpressionView("My view2", statisticExpressionFactory.createExpression(
55             "userLong0"));
56  
57      assertEquals("My view2", view2.getDisplayName());
58      assertTrue(view.getExpression() != null);
59    }
60  
61    public void testEquality() throws Exception {
62      final StatisticExpressionFactory statisticExpressionFactory =
63        StatisticsServicesImplementation.getInstance()
64        .getStatisticExpressionFactory();
65  
66      final ExpressionView[] views = {
67        statisticExpressionFactory.createExpressionView("My view", "(+ userLong0 userLong1)", false),
68        statisticExpressionFactory.createExpressionView("My view", "(+ userLong0 userLong1)", false),
69        statisticExpressionFactory.createExpressionView("My view", "(+ userLong0 userLong2)", false),
70        statisticExpressionFactory.createExpressionView("My View", "(+ userLong0 userLong1)", false),
71      };
72  
73      assertEquals(views[0], views[0]);
74      assertEquals(views[0], views[1]);
75      assertEquals(views[1], views[0]);
76      assertTrue(!views[0].equals(views[2]));
77      assertTrue(!views[1].equals(views[3]));
78  
79      assertTrue(!views[0].equals(new Object()));
80    }
81  
82    public void testToString() throws Exception {
83      final String displayName = "My view";
84      final String expressionString = "(+ userLong0 userLong1)";
85  
86      final StatisticExpressionFactory statisticExpressionFactory =
87        StatisticsServicesImplementation.getInstance()
88        .getStatisticExpressionFactory();
89  
90      final ExpressionView expressionView =
91        statisticExpressionFactory
92        .createExpressionView(displayName, expressionString, false);
93  
94      final String string = expressionView.toString();
95  
96      assertTrue(string.indexOf(displayName) >= 0);
97      assertTrue(string.indexOf(expressionString) >= 0);
98  
99      final ExpressionView view2 =
100       statisticExpressionFactory
101         .createExpressionView("My view2",
102           statisticExpressionFactory.createExpression("userLong0"));
103 
104     final String string2 = view2.toString();
105     assertTrue(string2.indexOf(displayName) >= 0);
106   }
107 }