001    package org.hackystat.sensorbase.resource.db;
002    
003    import static org.junit.Assert.assertTrue;
004    
005    import org.hackystat.sensorbase.client.SensorBaseClient;
006    import org.hackystat.sensorbase.test.SensorBaseRestApiHelper;
007    import org.junit.Test;
008    
009    /**
010     * Tests the RowCount API.
011     * Note that if you implement an alternative database backend that does not have a table named
012     * SensorData, then you will need to provide a System parameter called TestRowCountRestApi.tableName
013     * that will be used instead in order to get this test case to pass. 
014     * 
015     * @author Philip Johnson
016     */
017    public class TestRowCountRestApi extends SensorBaseRestApiHelper {
018      
019      private String tableNameKey = "TestRowCountRestApi.tableName";
020    
021      /**
022       * Test that GET {host}/db/table/SensorData/rowcount runs a non-zero value. 
023       * 
024       * @throws Exception If problems occur.
025       */
026      @Test
027      public void testRowCountRestApi() throws Exception {
028        String tableName = "SensorData";
029        if (System.getProperties().containsKey(tableNameKey)) {
030          tableName = System.getProperty(tableNameKey);
031        }
032        SensorBaseClient client = new SensorBaseClient(getHostName(), adminEmail, adminPassword);
033        client.authenticate();
034        int rowCount = client.rowCount(tableName);
035        assertTrue("Testing row count", (rowCount >= 0));
036      }
037    }