DataSourceFactory { public static DataSource getDataSource(CmdArguments cmdArguments) throws FastLdrException { String sqlType = System.getProperty(DB_TYPE); if (sqlType == null || sqlType.equalsIgnoreCase("ORACLE")) { return new OracleDataSource(cmdArguments).getDataSource(); } else if (sqlType.equals("UNIVERSAL")) { return new UniversalDataSource().getDataSource(); } else { throw new FastLdrException("Unknown database type:" + sqlType); } }  static DataSource getDataSource(CmdArguments cmdArguments); static final String DB_TYPE; }
@Test public void testGetDataSourceOracle() throws FastLdrException, ParseException { System.setProperty(DataSourceFactory.DB_TYPE, "Oracle"); CmdArguments cmdArguments = new CmdArguments(); cmdArguments.setUserID(new UserID("uid/pwd@host/instance")); DataSourceFactory.getDataSource(cmdArguments); }
@Test(expected = FastLdrException.class) public void testGetDataSourceH2() throws FastLdrException, ParseException { System.setProperty(DataSourceFactory.DB_TYPE, "H2"); CmdArguments cmdArguments = new CmdArguments(); cmdArguments.setUserID(new UserID("uid/pwd@host/instance")); DataSourceFactory.getDataSource(cmdArguments); }
@Test(expected = FastLdrException.class) public void testGetDataSourceUnknown() throws FastLdrException { System.setProperty(DataSourceFactory.DB_TYPE, "MySQL"); DataSourceFactory.getDataSource(new CmdArguments()); }