private boolean setupSQL() { if (config.getSQLValue().equalsIgnoreCase("MySQL")) { dataop = new MySQLOptions( config.getHostname(), config.getPort(), config.getDatabase(), config.getUsername(), config.getPassword()); } else if (config.getSQLValue().equalsIgnoreCase("SQLite")) { dataop = new SQLiteOptions(new File(getDataFolder() + "/coupon_data.db")); } else if (!config.getSQLValue().equalsIgnoreCase("MySQL") && !config.getSQLValue().equalsIgnoreCase("SQLite")) { sendErr("The SQLType has the unknown value of: " + config.getSQLValue()); return false; } sql = new SQL(this, dataop); try { sql.open(); sql.createTable( "CREATE TABLE IF NOT EXISTS couponcodes (name VARCHAR(24), ctype VARCHAR(10), usetimes INT(10), usedplayers TEXT(1024), ids VARCHAR(255), money INT(10), groupname VARCHAR(20), timeuse INT(100), xp INT(10))"); cm = new CouponManager(this, sql); } catch (SQLException e) { e.printStackTrace(); return false; } return true; }
@Test public void shouldReturnACustomConfigInstanceIfAlreadyExists() { Application app = new Application(database); Config result = app.getConfig(); result.setHostname("custom"); result.setPort(2030); result.setCheckInterval(30); app.update(result); database.getSession().flush(); database.getSession().clear(); result = app.getConfig(); assertThat(result.getHostname(), is(equalTo("custom"))); assertThat(result.getPort(), is(equalTo(2030))); assertThat(result.getCheckInterval(), is(equalTo(30))); }
@Test public void shouldReturnTheBasicConfigInstanceIfNoneFound() { Config result = new Application(database).getConfig(); assertThat(result.getHostname(), is(equalTo("localhost"))); assertThat(result.getPort(), is(equalTo(9091))); }