001    package org.hackystat.telemetry.service.resource.chart;
002    
003    import static org.junit.Assert.assertEquals;
004    import static org.junit.Assert.assertTrue;
005    
006    import java.util.List;
007    
008    import org.hackystat.sensorbase.client.SensorBaseClient;
009    import org.hackystat.telemetry.service.resource.chart.jaxb.ParameterDefinition;
010    import org.hackystat.telemetry.service.resource.chart.jaxb.TelemetryChartIndex;
011    import org.hackystat.telemetry.service.resource.chart.jaxb.Type;
012    import org.hackystat.telemetry.service.client.TelemetryClient;
013    import org.hackystat.telemetry.service.resource.chart.jaxb.TelemetryChartDefinition;
014    import org.hackystat.telemetry.service.test.TelemetryTestHelper;
015    import org.junit.Test;
016    import org.junit.Before;
017    
018    /**
019     * Tests the definition and index parts of the Chart REST API.
020     * @author Philip Johnson
021     */
022    public class TestChartRestApi extends TelemetryTestHelper {
023      
024      /** The user for this test case. */
025      private String user = "TestChart@hackystat.org";
026      
027      /** The telemetry client. */
028      private TelemetryClient telemetryClient;
029      
030      /**
031       * Creates DevEvents on server for use in Telemetry processing. 
032       * @throws Exception If problems occur. 
033       */
034      @Before
035      public void setupClient() throws Exception {
036        // Ensure that user is registered.
037        SensorBaseClient.registerUser(this.getSensorBaseHostName(), user);
038        this.telemetryClient = new TelemetryClient(getTelemetryHostName(), user, user);
039        telemetryClient.authenticate();
040      }
041      
042      /**
043       * Tests the ChartIndex interface. 
044       * @throws Exception If problems occur. 
045       */
046      @Test public void testChartIndex() throws Exception {
047        TelemetryChartIndex index = telemetryClient.getChartIndex();
048        assertTrue("Got at least one defined chart", index.getTelemetryChartRef().size() > 1);
049      }
050      
051      /**
052       * Tests the Chart Definition interface. 
053       * @throws Exception If problems occur. 
054       */
055      @Test public void testChartDefinition() throws Exception {
056        String chartName = "DevTime";
057        TelemetryChartDefinition chartDef = telemetryClient.getChartDefinition(chartName);
058        assertTrue("Got the DevTime chart", chartDef.getName().equals(chartName));
059        List<ParameterDefinition> parameters = chartDef.getParameterDefinition();
060        assertEquals("Got two parameter definitions", 2, parameters.size());
061        ParameterDefinition param = parameters.get(0);
062        assertEquals("Getting the member param", "member", param.getName());
063        Type type = param.getType();
064        assertEquals("Checking the type", "Text", type.getName());
065        assertEquals("Checking the default", "*", type.getDefault());
066        assertEquals("Checking the value list", 0, type.getValue().size());
067      }
068    }