CalabashNodeConfiguration { public static CalabashNodeConfiguration readFromURI(URI driverConfigFileURI) throws CalabashConfigurationException { if (driverConfigFileURI == null) { throw new InvalidParameterException("Calabash-Driver Configuration-URI is missing."); } if (driverConfigFileURI.getHost() == null || driverConfigFileURI.getPath() == null) { throw new InvalidParameterException("Calabash-Driver Configuration-URI is invalid."); } String driverConfiguration; try { HttpClient client = getDefaultHttpClient(); HttpGet request = new HttpGet(driverConfigFileURI); HttpResponse response = client.execute(request); driverConfiguration = IOUtils.toString(response.getEntity().getContent()); } catch (IOException e1) { logger.error("Error occured while reading config from URI:", e1); throw new CalabashConfigurationException( "Error reading file content. Did you have specified the right URI?", e1); } catch (KeyManagementException e) { logger.error("Error occured while creating httpclient:", e); throw new CalabashConfigurationException("Error occured while creating httpclient", e); } catch (NoSuchAlgorithmException e) { logger.error("Error occured while creating httpclient:", e); throw new CalabashConfigurationException("Error occured while creating httpclient", e); } try { return new CalabashNodeConfiguration(new JSONObject(driverConfiguration)); } catch (JSONException e) { logger.error("Error occured while parsing config file: ", e); throw new CalabashConfigurationException("Error occured during parsing json file from URI: '" + driverConfigFileURI + "'. Pls make sure you are using a valid JSON file!", e); } } protected  CalabashNodeConfiguration(); protected  CalabashNodeConfiguration(JSONObject config); static CalabashNodeConfiguration readFromFile(File driverConfigurationFile); static CalabashNodeConfiguration readFromURI(URI driverConfigFileURI); List<CalabashCapabilities> getCapabilities(); String getProxy(); String getDriverHost(); int getDriverMaxSession(); int getDriverPort(); String getMobileAppPath(); String getMobileTestAppPath(); String getHubHost(); int getHubPort(); boolean isInstallApksEnabled(); boolean isCleanSavedUserDataEnabled(); boolean isDriverRegistrationEnabled(); static final String CAPABILITIES; static final String CONFIGURATION; }
@Test public void testReadConfigByURI() throws Exception { CalabashWebNodeConfigStub stub = new CalabashWebNodeConfigStub(); Thread.sleep(3000); CalabashNodeConfiguration config = CalabashNodeConfiguration.readFromURI(new URI(CONFIG_FILE_URL)); assertNodeConfig(config); stub.stop(); }
@Test(expectedExceptions = {InvalidParameterException.class}) public void testReadConfigByURIInvalidURI() throws Exception { CalabashNodeConfiguration.readFromURI(new URI("")); }
@Test(expectedExceptions = {InvalidParameterException.class}) public void testReadConfigByURINullInput() throws Exception { CalabashNodeConfiguration.readFromURI(null); }