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.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.apache.log4j.Logger;
29
30 import com.ebay.carad.os.vitalsigns.DataPoint;
31 import com.ebay.carad.os.vitalsigns.IDashboardReport;
32 import com.ebay.carad.os.vitalsigns.IReportingListenerContainer;
33 import com.ebay.carad.os.vitalsigns.ReportingException;
34
35 /***
36 * IDataDAO implementation for use in unit tests.
37 *
38 * @author Jeremy Thomerson
39 * @version $Id$
40 */
41 public class TestDataDao implements IDataDAO {
42
43 private static final Logger LOGGER = Logger.getLogger(TestDataDao.class);
44 private final Map mData = new HashMap();
45
46 public void storeReportData(float data, IReportingListenerContainer agent, IDashboardReport report) throws ReportingException {
47 storeData(System.currentTimeMillis(), data, new Integer(report.getID()));
48 }
49
50 public void storeData(long logTime, float data, Integer reportID) {
51 DataPoint dataPoint = new DataPoint(logTime, data);
52 List points = (List) mData.get(reportID);
53 if (points == null) {
54 points = new ArrayList();
55 mData.put(reportID, points);
56 }
57 points.add(dataPoint);
58 }
59
60 public DataPoint[] getData(IDashboardReport report) throws ReportingException {
61 List points = (List) mData.get(new Integer(report.getID()));
62 if (points == null) {
63 LOGGER.warn("no data points for report: " + report.getID() + " [IDs: " + mData.keySet() + "]");
64 } else {
65 LOGGER.info(points.size() + " data points for report: " + report.getID());
66 }
67 return (DataPoint[]) (points == null ? EMPTY_DATA_POINT_ARRAY : points.toArray(new DataPoint[points.size()]));
68 }
69
70 }
71