CommanderPropertiesHandler { public final CommanderConfig loadProperties() throws CommanderException { Properties properties = new Properties(); CommanderConfig config = new CommanderConfig(); InputStream fis = null; try { fis = new FileInputStream(tmpPropFile); properties.load(fis); } catch (FileNotFoundException e) { throw new CommanderException( "Could not find configuration file: " + tmpPropFile, e); } catch (IOException e) { throw new CommanderException( "Could not open configuration file: " + tmpPropFile, e); } SfdcConfig sourceSfdcConfig = new SfdcConfig(); String tmpSystemName = properties .getProperty(CommanderConfig.SF_SYSTEMNAME); validateSystemName(tmpSystemName); sourceSfdcConfig.setSystemName(tmpSystemName); sourceSfdcConfig.setUsername( properties.getProperty(CommanderConfig.SF_USERNAME)); sourceSfdcConfig.setPassword( properties.getProperty(CommanderConfig.SF_PASSWORD)); String tmpServerUrl = properties .getProperty(CommanderConfig.SF_SERVERURL); validateUrl(tmpServerUrl); sourceSfdcConfig.setLoginUrl(tmpServerUrl); config.setSourceSfdcConfig(sourceSfdcConfig); SvnConfig svnConfig = new SvnConfig(); svnConfig.setSvnRepository( properties.getProperty(CommanderConfig.SVN_REPOSITORY)); svnConfig.setSvnUser(properties.getProperty(CommanderConfig.SVN_USER)); svnConfig.setSvnPassword( properties.getProperty(CommanderConfig.SVN_PASSWORD)); config.setSvnConfig(svnConfig); config.setRenderPath( properties.getProperty(CommanderConfig.RENDER_PATH)); config.setBackupPath( properties.getProperty(CommanderConfig.BACKUP_PATH)); config.setXlsPath(properties.getProperty(CommanderConfig.XLS_PATH)); SfdcConfig targetSfdcConfig = new SfdcConfig(); String tmpTargetSystem = properties .getProperty(CommanderConfig.SF_TARGET_SYSTEMNAME); validateSystemName(tmpTargetSystem); targetSfdcConfig.setSystemName(tmpTargetSystem); targetSfdcConfig.setUsername( properties.getProperty(CommanderConfig.SF_TARGET_USERNAME)); targetSfdcConfig.setPassword( properties.getProperty(CommanderConfig.SF_TARGET_PASSWORD)); String tmpTargetServerUrl = properties .getProperty(CommanderConfig.SF_TARGET_SERVERURL); validateUrl(tmpTargetServerUrl); targetSfdcConfig.setLoginUrl(tmpTargetServerUrl); config.setTargetSfdcConfig(targetSfdcConfig); config.setHttpProxyHost( properties.getProperty(CommanderConfig.HTTP_PROXY_HOST)); config.setHttpProxyPort( properties.getProperty(CommanderConfig.HTTP_PROXY_PORT)); if (!config.getHttpProxyHost().equals("")) { System.setProperty(CommanderConfig.HTTP_PROXY_HOST, config.getHttpProxyHost()); } if (!config.getHttpProxyPort().equals("")) { System.setProperty(CommanderConfig.HTTP_PROXY_PORT, config.getHttpProxyPort()); } return config; } CommanderPropertiesHandler(final String aPropFile); final CommanderConfig loadProperties();  }
@Test public void loadPropertiesTest() throws CommanderException { CommanderPropertiesHandler propHandler = new CommanderPropertiesHandler( "src/test/resources/Test.properties"); CommanderConfig config = propHandler.loadProperties(); Assert.assertEquals("MyDevelopmentOrg", config.getSourceSfdcConfig().getSystemName()); Assert.assertEquals("user@devAccount.com", config.getSourceSfdcConfig().getUsername()); Assert.assertEquals("MyPasswordAndSecurityToken", config.getSourceSfdcConfig().getPassword()); Assert.assertEquals("https: config.getSourceSfdcConfig().getLoginUrl()); Assert.assertEquals("TestProxyHost", config.getHttpProxyHost()); Assert.assertEquals("8080", config.getHttpProxyPort()); Assert.assertEquals("https: config.getSvnConfig().getSvnRepository()); Assert.assertEquals("svnUsername", config.getSvnConfig().getSvnUser()); Assert.assertEquals("svnPassword", config.getSvnConfig().getSvnPassword()); Assert.assertEquals("c:/html/", config.getRenderPath()); Assert.assertEquals("c:/xls/", config.getXlsPath()); Assert.assertEquals("c:/sfdcBackup/", config.getBackupPath()); Assert.assertEquals("MyTargetOrg", config.getTargetSfdcConfig().getSystemName()); Assert.assertEquals("user@testAccount.com", config.getTargetSfdcConfig().getUsername()); Assert.assertEquals("TargetPasswordAndSecurityToken", config.getTargetSfdcConfig().getPassword()); Assert.assertEquals("https: config.getTargetSfdcConfig().getLoginUrl()); }
@Test public void loadPropertiesTest2() throws CommanderException { CommanderPropertiesHandler propHandler = new CommanderPropertiesHandler( "src/test/resources/NotExisting.properties"); thrown.expect(CommanderException.class); CommanderConfig config = propHandler.loadProperties(); }