1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package com.ebay.carad.os.vitalsigns;
23
24 import com.ebay.carad.os.vitalsigns.util.ITimeConstants;
25
26 import junit.framework.TestCase;
27
28 /***
29 * @author Jeremy Thomerson
30 * @version $Id$
31 */
32 public class DashboardReportTest extends TestCase {
33
34 private static class TestDataRetriever implements IDataRetriever {
35 private int mInvocationCount = 0;
36 public Float getData(IDashboardAgent agent) {
37 mInvocationCount++;
38 return IDataRetriever.ZERO;
39 }
40 public int getInvocationCount() {
41 return mInvocationCount;
42 }
43 public Object clone() throws CloneNotSupportedException {
44 return super.clone();
45 }
46 }
47 public void testRunFrequency() throws Exception {
48 IDashboardAgent agent = new DashboardAgent();
49 TestDataRetriever dr = new TestDataRetriever();
50
51 DashboardReport rep = new DashboardReport();
52 rep.setFrequencyInMinutes(397);
53
54 rep.setDataRetriever(dr);
55
56 assertEquals(0, dr.getInvocationCount());
57 rep.run(agent, System.currentTimeMillis());
58 assertEquals(1, dr.getInvocationCount());
59
60 rep.run(agent, System.currentTimeMillis());
61
62
63
64 assertEquals(1, dr.getInvocationCount());
65
66 long time = ((rep.getFrequencyInMinutes() + 13) * ITimeConstants.MINUTE);
67 rep.run(agent, System.currentTimeMillis() + time);
68 assertEquals(2, dr.getInvocationCount());
69 rep.run(agent, System.currentTimeMillis() + time);
70
71 assertEquals(2, dr.getInvocationCount());
72 }
73
74 }