|
1 package hirondelle.web4j.model; |
|
2 |
|
3 import junit.framework.*; |
|
4 //import junit.ui.TestRunner; |
|
5 //import junit.textui.TestRunner; |
|
6 |
|
7 import hirondelle.web4j.util.Consts; |
|
8 import hirondelle.web4j.webmaster.PerformanceSnapshot; |
|
9 |
|
10 /** |
|
11 <a href="http://www.junit.org">JUnit</a> tests for the |
|
12 {@link PerformanceSnapshot} class. |
|
13 |
|
14 <P>Testing the 'end time', and its correct rollover to the next |
|
15 time frame, is left out here. |
|
16 */ |
|
17 public final class TESTPerformanceSnapshot extends TestCase { |
|
18 |
|
19 /** |
|
20 Run the test cases. |
|
21 */ |
|
22 public static void main(String args[]) { |
|
23 String[] testCaseName = { TESTPerformanceSnapshot.class.getName() }; |
|
24 //Select one of several types of interfaces. |
|
25 junit.textui.TestRunner.main(testCaseName); |
|
26 //junit.swingui.TestRunner.main(testCaseName); |
|
27 //junit.ui.TestRunner.main(testCaseName); |
|
28 } |
|
29 |
|
30 /** |
|
31 Canonical form of constructor. |
|
32 */ |
|
33 public TESTPerformanceSnapshot( String aName) { |
|
34 super(aName); |
|
35 } |
|
36 |
|
37 // TEST CASES // |
|
38 |
|
39 public void testCtor(){ |
|
40 assertState(fSnapshot, EXPOSURE_TIME.intValue(), 0, 0, 0, Consts.EMPTY_STRING); |
|
41 } |
|
42 |
|
43 public void testAddResponses() { |
|
44 PerformanceSnapshot snapshot1 = fSnapshot.addResponseTime(1000, URL); |
|
45 assertState(snapshot1, EXPOSURE_TIME.intValue(), 1, 1000, 1000, URL); |
|
46 |
|
47 PerformanceSnapshot snapshot2 = snapshot1.addResponseTime(3000, URL); |
|
48 assertState(snapshot2, EXPOSURE_TIME.intValue(), 2, 3000, 2000, URL); |
|
49 |
|
50 PerformanceSnapshot snapshot3 = snapshot2.addResponseTime(1000, URL); |
|
51 assertState(snapshot3, EXPOSURE_TIME.intValue(), 3, 3000, 1666, URL); |
|
52 |
|
53 PerformanceSnapshot snapshot4 = snapshot3.addResponseTime(6000, MAX_URL); |
|
54 assertState(snapshot4, EXPOSURE_TIME.intValue(), 4, 6000, 2749, MAX_URL); |
|
55 } |
|
56 |
|
57 // FIXTURE // |
|
58 |
|
59 /** |
|
60 Build a fixture of test objects. This method is called anew for |
|
61 each test, such that the tests will always start with the same |
|
62 set of test objects, and the execution of one test will not interfere |
|
63 with the execution of another. |
|
64 */ |
|
65 protected void setUp(){ |
|
66 fSnapshot = new PerformanceSnapshot(EXPOSURE_TIME); |
|
67 } |
|
68 |
|
69 /** |
|
70 Re-set test objects. |
|
71 */ |
|
72 protected void tearDown() { |
|
73 } |
|
74 |
|
75 // PRIVATE // |
|
76 private PerformanceSnapshot fSnapshot; |
|
77 private static final Integer EXPOSURE_TIME = new Integer(10); |
|
78 private static final String URL = "std-url"; |
|
79 private static final String MAX_URL = "max-url"; |
|
80 |
|
81 private void log(Object aThing){ |
|
82 System.out.println(aThing.toString()); |
|
83 } |
|
84 |
|
85 private void assertState( |
|
86 PerformanceSnapshot aSnapshot, |
|
87 int aExposureTime, |
|
88 int aNumRequests, |
|
89 int aMaxResponseTime, |
|
90 int aAvgResponseTime, |
|
91 String aMaxURL |
|
92 ){ |
|
93 //log(aSnapshot); |
|
94 assertTrue(aSnapshot.getExposureTime().intValue() == aExposureTime); |
|
95 assertTrue(aSnapshot.getNumRequests().intValue() == aNumRequests); |
|
96 assertTrue(aSnapshot.getMaxResponseTime().intValue() == aMaxResponseTime); |
|
97 assertTrue(aSnapshot.getAvgResponseTime().intValue() == aAvgResponseTime); |
|
98 assertTrue(aSnapshot.getURLWithMaxResponseTime().equals(aMaxURL)); |
|
99 } |
|
100 } |