JDBCMain { static List<JDBCCore> createSources(Properties config) { authToken = config.getProperty("authToken"); if (authToken == null) { log.error("No valid authentication token in server settings"); log.error("Exiting..."); exit(NO_AUTH_EXIT); } String sourceStr = config.getProperty("sources"); if (sourceStr == null || sourceStr.equals("")) { log.error("No sources in server settings"); log.error("Exiting..."); exit(NO_SOURCE_EXIT); } targetVantiqServer = config.getProperty("targetServer"); if (targetVantiqServer == null || targetVantiqServer.equals("")) { log.error("No server URL specified in server settings"); log.error("Exiting..."); exit(NO_SERVER_EXIT); } String[] sourceNames = sourceStr.split(","); sources = new ArrayList<>(); for (String sourceName : sourceNames) { sourceName = sourceName.trim(); JDBCCore source; source = new JDBCCore(sourceName, authToken, targetVantiqServer); sources.add(source); } return sources; }  static void main(String[] args); static void exit(int code);  }
@Test public void testConfigs() { Properties props = new Properties(); try { JDBCMain.createSources(props); fail("Didn't exit when missing authToken and sources"); } catch (ExitException e) { assert e.getMessage().equals("Exit Requested: auth token was not specified."); } try { props.setProperty("authToken", "a token"); JDBCMain.createSources(props); fail("Didn't exit when missing sources"); } catch (ExitException e) { assert e.getMessage().equals("Exit Requested: source(s) not specified."); } try { props.setProperty("sources", "a source"); JDBCMain.createSources(props); fail("Didn't exit when missing server"); } catch (ExitException e) { assert e.getMessage().equals("Exit Requested: target server not specified."); } props.setProperty("sources", "s"); props.setProperty("targetServer", "url"); JDBCMain.createSources(props); assert JDBCMain.targetVantiqServer.equals("url"); JDBCCore s = JDBCMain.sources.get(0); assert s.getSourceName().equals("s"); s.stop(); try { props.remove("authToken"); JDBCMain.createSources(props); fail("Didn't exit when missing authToken"); } catch (ExitException e) { assert e.getMessage().equals("Exit Requested: auth token was not specified."); } String targetServer = "dev.vantiq.com"; props.setProperty("authToken", "a token"); props.setProperty("sources", "s2, s1 "); props.setProperty("targetServer", targetServer); JDBCMain.createSources(props); assert JDBCMain.targetVantiqServer.equals(targetServer); JDBCCore s1 = JDBCMain.sources.get(0); JDBCCore s2 = JDBCMain.sources.get(1); assert s1.getSourceName().equals("s1") || s2.getSourceName().equals("s1"); assert s1.getSourceName().equals("s2") || s2.getSourceName().equals("s2"); s1.stop(); s2.stop(); }