Example #1
0
 /** Test of openDb method, of class Database. */
 @Test
 public void test1OpenDb() {
   System.out.println("openDb");
   Database instance = new Database();
   instance.setDbName(databaseFilePath);
   Connection result = instance.openDb();
   assertNotNull(result);
 }
Example #2
0
 /** Test of sqlStatementConstructor method, of class Database. */
 @Test
 public void testSqlStatementConstructor() {
   System.out.println("sqlStatementConstructor");
   String expResult = "SELECT date,time FROM sysstats";
   Database.setSqlStatementOperation("SELECT");
   Database.setSqlStatementTable(tableName);
   List columns = new ArrayList<>();
   columns.add("date");
   columns.add("time");
   Database.setSqlStatementColumns(columns);
   String result = Database.sqlStatementConstructor();
   assertEquals(expResult, result);
 }
Example #3
0
 /**
  * Test of insertStat method, of class Database.
  *
  * @throws java.sql.SQLException
  */
 @Test
 public void test3InsertStat() throws SQLException {
   System.out.println("insertStat");
   List<String> message = new ArrayList<>(Arrays.asList("12345", "6789.123"));
   Database instance = new Database();
   instance.setDbName(databaseFilePath);
   Connection conn = instance.openDb();
   instance.setTableName(tableName);
   instance.setDbConnection(conn);
   instance.setStatMessage(message);
   Boolean result = instance.insertStat();
   assertTrue(result);
   // Test reinsertion of duplicates
   result = instance.insertStat();
   assertFalse(result);
 }
Example #4
0
  /** Test of crateTable method, of class Database. */
  @Test
  public void test2CrateTable() {
    System.out.println("crateTable");

    Database instance = new Database();
    instance.setDbName(databaseFilePath);
    Connection conn = instance.openDb();
    instance.setTableName(tableName);
    instance.setTableColumns(tableColumns);
    instance.setDbConnection(conn);
    Boolean result = instance.crateTable();
    assertTrue(result);
  }
Example #5
0
  /**
   * Test of selectStat method, of class Database.
   *
   * @throws java.lang.Exception
   */
  @Test
  public void test4SelectStat() throws Exception {
    System.out.println("selectStat");
    List<String> stats = new ArrayList<>(Arrays.asList("12345", "6789.123"));
    List<String> columns = new ArrayList<>(Arrays.asList("date", "time"));
    List<List<String>> expResult = new ArrayList<>();
    expResult.add(stats);
    Database instance = new Database();
    instance.setDbName(databaseFilePath);
    Connection conn = instance.openDb();
    instance.setDbConnection(conn);
    instance.setTableName(tableName);
    instance.setColumnNames(columns);

    List<List<String>> result = instance.selectStats();
    assertEquals(expResult, result);
  }