1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.dao;
22
23 import java.util.Random;
24
25 import com.ebay.carad.os.vitalsigns.util.ITimeConstants;
26
27 /***
28 * Factory capable of adding certain sets of data to a TestDataDAO for the purposes
29 * of unit testing.
30 *
31 * TODO : fix up logging in this class
32 *
33 * @author Jeremy Thomerson
34 * @version $Id$
35 */
36 public class TestDataDaoFactory {
37
38 public static TestDataDao getTestDaoWithData() {
39 TestDataDao dao = new TestDataDao();
40 addIncreasingLine(dao, 1);
41 return dao;
42 }
43
44 public static void addIncreasingLine(TestDataDao dao, int reportID) {
45 long time = System.currentTimeMillis();
46 int cnt = 0;
47 long lengthOfLine = (400 * ITimeConstants.DAY);
48 long millisBetweenPoints = (2 * ITimeConstants.HOUR);
49 int expectedCount = (int) (lengthOfLine / millisBetweenPoints);
50 long stop = (System.currentTimeMillis() - lengthOfLine);
51 while (time > stop) {
52 float data = (float) (1 - ((double) cnt / (double) expectedCount));
53
54 dao.storeData(time, data, new Integer(reportID));
55 time = time - millisBetweenPoints;
56 cnt++;
57 }
58
59 System.out.println("expected count of: " + expectedCount + ", real count: " + cnt);
60 }
61
62 public static void addAlternatingLine(TestDataDao dao, int reportID) {
63 long time = System.currentTimeMillis();
64 int cnt = 0;
65 long lengthOfLine = (400 * ITimeConstants.DAY);
66 long millisBetweenPoints = (2 * ITimeConstants.HOUR);
67 int expectedCount = (int) (lengthOfLine / millisBetweenPoints);
68 long stop = (System.currentTimeMillis() - lengthOfLine);
69 int currentValue = 1;
70 Random rand = new Random();
71 int iterationsLeftBeforeSwitch = rand.nextInt(24);
72 boolean goingUp = rand.nextBoolean();
73 while (time > stop) {
74 float data = currentValue;
75 currentValue = goingUp ? ++currentValue : --currentValue;
76 if (--iterationsLeftBeforeSwitch < 1) {
77 goingUp = !goingUp;
78 iterationsLeftBeforeSwitch = rand.nextInt(24);
79 }
80
81 dao.storeData(time, data, new Integer(reportID));
82 time = time - millisBetweenPoints;
83 cnt++;
84 }
85
86 System.out.println("expected count of: " + expectedCount + ", real count: " + cnt);
87 }
88
89 public static void main(String[] args) {
90 getTestDaoWithData();
91 }
92
93 }
94