View Javadoc

1   /*
2    * The contents of this file are subject to the terms 
3    * of the Common Development and Distribution License 
4    * (the "License").  You may not use this file except 
5    * in compliance with the License.
6    * 
7    * You can obtain a copy of the license at 
8    * http://www.sun.com/cddl/cddl.html. 
9    * See the License for the specific language governing 
10   * permissions and limitations under the License.
11   * 
12   * When distributing Covered Code, include this CDDL 
13   * HEADER in each file and include the License file at 
14   * license.txt.  If applicable, add the following below 
15   * this CDDL HEADER, with the fields enclosed by brackets 
16   * "[]" replaced with your own identifying information: 
17   * Portions Copyright [yyyy] [name of copyright owner]
18   * 
19   * Portions Copyright 2004 eBay, Inc.
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