001 package org.hackystat.telemetry.service.resource.chart; 002 003 import static org.junit.Assert.assertEquals; 004 005 import java.util.List; 006 import javax.xml.datatype.XMLGregorianCalendar; 007 import org.hackystat.dailyprojectdata.resource.issue.TestIssueDataParser; 008 import org.hackystat.sensorbase.client.SensorBaseClient; 009 import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorDatas; 010 import org.hackystat.telemetry.service.client.TelemetryClient; 011 import org.hackystat.telemetry.service.resource.chart.jaxb.TelemetryChartData; 012 import org.hackystat.telemetry.service.resource.chart.jaxb.TelemetryPoint; 013 import org.hackystat.telemetry.service.resource.chart.jaxb.TelemetryStream; 014 import org.hackystat.telemetry.service.test.TelemetryTestHelper; 015 import org.hackystat.utilities.tstamp.Tstamp; 016 import org.junit.Test; 017 import org.junit.Before; 018 019 /** 020 * Tests the Issue Chart processing. 021 * @author Shaoxuan Zhang, Philip Johnson 022 */ 023 public class TestIssueChartRestApi extends TelemetryTestHelper { 024 025 /** The user for this test case. */ 026 private static final String NEW = "New"; 027 private static final String STARTED = "Started"; 028 private static final String ACCEPTED = "Accepted"; 029 private static final String FIXED = "Fixed"; 030 private static final String DEFECT = "Defect"; 031 private static final String TASK = "Task"; 032 private static final String ENHANCEMENT = "Enhancement"; 033 private static final String MEDIUM = "Medium"; 034 private static final String HIGH = "High"; 035 private static final String CRITICAL = "Critical"; 036 037 private static final String dataOwner = "testDataOwner@hackystat.org"; 038 private static final String testUser1 = "tester1@hackystat.org"; 039 private static final String testUser2 = "tester2@hackystat.org"; 040 041 private static final String defaultProject = "Default"; 042 private static final String day = "Day"; 043 044 private static final String[] testData1T1 = {"21", DEFECT, ACCEPTED, MEDIUM, "", testUser1, 045 "2008-09-07T11:00:00"}; 046 private static final String[] testData1T2 = {"21", ENHANCEMENT, FIXED, MEDIUM, "8.4", testUser1, 047 "2008-09-07T11:00:00"}; 048 049 private static final String[] testData2T1 = {"23", ENHANCEMENT, FIXED, MEDIUM, "", testUser1, 050 "2009-07-20T00:24:06"}; 051 private static final String[] testData2T2 = {"23", ENHANCEMENT, ACCEPTED, HIGH, "", testUser2, 052 "2009-07-20T00:24:06"}; 053 054 private static final String[] testData3T1 = {"14", ENHANCEMENT, NEW, HIGH, "", testUser2, 055 "2009-06-20T14:35:32"}; 056 057 private static final String[] testData4T1 = {"25", DEFECT, STARTED, CRITICAL, "8.4", testUser1, 058 "2009-07-21T20:00:00"}; 059 060 private static final String[] testData5T1 = {"18", TASK, FIXED, HIGH, "", testUser2, 061 "2009-07-21T18:00:00"}; 062 063 private static final String testTimeString1 = "2009-07-20T00:00:00"; 064 private static final String testTimeString2 = "2009-07-22T10:00:00"; 065 /** The telemetry client. */ 066 private TelemetryClient telemetryClient; 067 068 /** 069 * Creates Commits on server for use in Telemetry processing. 070 * @throws Exception If problems occur. 071 */ 072 @Before 073 public void generateData() throws Exception { 074 // [1] First, create a batch of sensor data. 075 SensorDatas batchData = new SensorDatas(); 076 XMLGregorianCalendar testTime1 = Tstamp.makeTimestamp(testTimeString1); 077 XMLGregorianCalendar testTime2 = Tstamp.makeTimestamp(testTimeString2); 078 // First, create a batch of Issue sensor data. 079 batchData.getSensorData().add(TestIssueDataParser.makeIssueSensorData(dataOwner, 080 new String[][]{testData1T1, testData1T2}, 081 new XMLGregorianCalendar[]{testTime1, testTime2})); 082 batchData.getSensorData().add(TestIssueDataParser.makeIssueSensorData(dataOwner, 083 new String[][]{testData2T1, testData2T2}, 084 new XMLGregorianCalendar[]{testTime1, testTime2})); 085 batchData.getSensorData().add(TestIssueDataParser.makeIssueSensorData(dataOwner, 086 new String[][]{testData3T1}, new XMLGregorianCalendar[]{testTime1})); 087 batchData.getSensorData().add(TestIssueDataParser.makeIssueSensorData(dataOwner, 088 new String[][]{testData4T1}, new XMLGregorianCalendar[]{testTime2})); 089 batchData.getSensorData().add(TestIssueDataParser.makeIssueSensorData(dataOwner, 090 new String[][]{testData5T1}, new XMLGregorianCalendar[]{testTime2})); 091 092 // Connect to the sensorbase and register the user. 093 SensorBaseClient.registerUser(getSensorBaseHostName(), dataOwner); 094 SensorBaseClient client = new SensorBaseClient(getSensorBaseHostName(), dataOwner, dataOwner); 095 client.authenticate(); 096 // Send the sensor data to the SensorBase. 097 client.putSensorDataBatch(batchData); 098 099 // Now connect to the Telemetry server. 100 this.telemetryClient = new TelemetryClient(getTelemetryHostName(), dataOwner, dataOwner); 101 telemetryClient.authenticate(); 102 } 103 104 105 /** 106 * Tests the chart. 107 * @throws Exception If problems occur. 108 */ 109 @Test public void testIssueChartAllCount() throws Exception { 110 String params = "*,all"; 111 TelemetryChartData chart = telemetryClient.getChart("Issue", dataOwner, defaultProject, day, 112 Tstamp.makeTimestamp(testTimeString1), Tstamp.makeTimestamp(testTimeString2), params); 113 // See if this chart contains 1 stream. 114 List<TelemetryStream> streams = chart.getTelemetryStream(); 115 assertEquals("Checking only 1 stream returned", 1, streams.size()); 116 // Get the data points in the single returned stream. 117 List<TelemetryPoint> points = streams.get(0).getTelemetryPoint(); 118 assertEquals("Checking for 3 points", 3, points.size()); 119 assertEquals("Checking point 1 is 3", "3", points.get(0).getValue()); 120 assertEquals("Checking point 2 is 5", "5", points.get(1).getValue()); 121 assertEquals("Checking point 3 is 5", "5", points.get(2).getValue()); 122 } 123 124 /** 125 * Tests the chart. 126 * @throws Exception If problems occur. 127 */ 128 @Test public void testIssueChartOpenCount() throws Exception { 129 String params = "*,open"; 130 TelemetryChartData chart = telemetryClient.getChart("Issue", dataOwner, defaultProject, day, 131 Tstamp.makeTimestamp(testTimeString1), Tstamp.makeTimestamp(testTimeString2), params); 132 // See if this chart contains 1 stream. 133 List<TelemetryStream> streams = chart.getTelemetryStream(); 134 assertEquals("Checking only 1 stream returned", 1, streams.size()); 135 // Get the data points in the single returned stream. 136 List<TelemetryPoint> points = streams.get(0).getTelemetryPoint(); 137 assertEquals("Checking for 3 points", 3, points.size()); 138 assertEquals("Checking point 1 is 2", "2", points.get(0).getValue()); 139 assertEquals("Checking point 2 is 2", "2", points.get(1).getValue()); 140 assertEquals("Checking point 3 is 3", "3", points.get(2).getValue()); 141 } 142 143 }