CommandLineDriverSettingsModule extends AbstractModule { @VisibleForTesting static Properties parseCredentials(InputStream credentialsStream) { Properties properties = new Properties(); try { properties.load(credentialsStream); } catch (IOException e) { LOG.error("Unable to load authentication file"); throw Throwables.propagate(e); } Preconditions.checkState(properties.containsKey(PRINCIPAL_KEY), "The framework authentication file is missing the key: %s", PRINCIPAL_KEY); Preconditions.checkState(properties.containsKey(SECRET_KEY), "The framework authentication file is missing the key: %s", SECRET_KEY); return properties; }    }
@Test(expected = IllegalStateException.class) public void testMissingPropertiesParsing() { Properties testProperties = new Properties(); testProperties.put(CommandLineDriverSettingsModule.PRINCIPAL_KEY, "aurora-scheduler"); ByteArrayOutputStream propertiesStream = new ByteArrayOutputStream(); try { testProperties.store(propertiesStream, ""); } catch (IOException e) { throw Throwables.propagate(e); } CommandLineDriverSettingsModule.parseCredentials( new ByteArrayInputStream(propertiesStream.toByteArray())); }
@Test public void testPropertiesParsing() { Properties testProperties = new Properties(); testProperties.put(CommandLineDriverSettingsModule.PRINCIPAL_KEY, "aurora-scheduler"); testProperties.put(CommandLineDriverSettingsModule.SECRET_KEY, "secret"); ByteArrayOutputStream propertiesStream = new ByteArrayOutputStream(); try { testProperties.store(propertiesStream, ""); } catch (IOException e) { throw Throwables.propagate(e); } assertEquals( testProperties, CommandLineDriverSettingsModule.parseCredentials( new ByteArrayInputStream(propertiesStream.toByteArray()))); }