@Test public void testFilePropertiesCacheWithTwoDifferentFiles() throws IOException { final String connName = "unitconnurl"; Map<ForceConnectionProperty, String> props = ForceConnectorUtils.loadConnectorPropsFromName(connName); final String secondConnName = "unitconnuserinfo"; Map<ForceConnectionProperty, String> secondProps = ForceConnectorUtils.loadConnectorPropsFromName(secondConnName); Assert.assertEquals(ForceConnectorUtils.PROPERTIES_CACHE.size(), 2); Assert.assertEquals(ForceConnectorUtils.PROPERTIES_CACHE.get(connName), props); Assert.assertNotSame(ForceConnectorUtils.PROPERTIES_CACHE.get(connName), secondProps); Assert.assertEquals(ForceConnectorUtils.PROPERTIES_CACHE.get(secondConnName), secondProps); Assert.assertNotSame(ForceConnectorUtils.PROPERTIES_CACHE.get(secondConnName), props); }
public static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName) throws IOException { if (connectionName == null) return null; if (PROPERTIES_CACHE.containsKey(connectionName)) { LOGGER.info("Connection : loading " + connectionName + " from cache"); return PROPERTIES_CACHE.get(connectionName); } String connectionUrl; String envVarName = "FORCE_" + connectionName.toUpperCase() + "_URL"; if ((connectionUrl = System.getenv(envVarName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from environment variable: " + envVarName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } String sysPropName = "force." + connectionName + ".url"; if ((connectionUrl = System.getProperty(sysPropName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from Java system property: " + sysPropName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } URL propsFileUrl; if ((propsFileUrl = ForceConnectorUtils.class.getResource("/" + connectionName + ".properties")) != null) { LOGGER.info("Connection : Creating " + connectionName + " from classpath properties file: " + propsFileUrl); return cache(connectionName, loadConnectorPropsFromFile(propsFileUrl)); } if (cliforceConnFile.canRead()) { InputStream is = null; Properties cliforceConnUrls = new Properties(); try { is = new FileInputStream(cliforceConnFile); cliforceConnUrls.load(is); } finally { if (is != null) is.close(); } if (cliforceConnUrls.containsKey(connectionName)) { LOGGER.info("Connection : Creating " + connectionName + " from cliforce connections file: " + cliforceConnFile); return cache(connectionName, loadConnectorPropsFromUrl(cliforceConnUrls.getProperty(connectionName))); } } return null; }
ForceConnectorUtils { public static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName) throws IOException { if (connectionName == null) return null; if (PROPERTIES_CACHE.containsKey(connectionName)) { LOGGER.info("Connection : loading " + connectionName + " from cache"); return PROPERTIES_CACHE.get(connectionName); } String connectionUrl; String envVarName = "FORCE_" + connectionName.toUpperCase() + "_URL"; if ((connectionUrl = System.getenv(envVarName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from environment variable: " + envVarName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } String sysPropName = "force." + connectionName + ".url"; if ((connectionUrl = System.getProperty(sysPropName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from Java system property: " + sysPropName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } URL propsFileUrl; if ((propsFileUrl = ForceConnectorUtils.class.getResource("/" + connectionName + ".properties")) != null) { LOGGER.info("Connection : Creating " + connectionName + " from classpath properties file: " + propsFileUrl); return cache(connectionName, loadConnectorPropsFromFile(propsFileUrl)); } if (cliforceConnFile.canRead()) { InputStream is = null; Properties cliforceConnUrls = new Properties(); try { is = new FileInputStream(cliforceConnFile); cliforceConnUrls.load(is); } finally { if (is != null) is.close(); } if (cliforceConnUrls.containsKey(connectionName)) { LOGGER.info("Connection : Creating " + connectionName + " from cliforce connections file: " + cliforceConnFile); return cache(connectionName, loadConnectorPropsFromUrl(cliforceConnUrls.getProperty(connectionName))); } } return null; } }
ForceConnectorUtils { public static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName) throws IOException { if (connectionName == null) return null; if (PROPERTIES_CACHE.containsKey(connectionName)) { LOGGER.info("Connection : loading " + connectionName + " from cache"); return PROPERTIES_CACHE.get(connectionName); } String connectionUrl; String envVarName = "FORCE_" + connectionName.toUpperCase() + "_URL"; if ((connectionUrl = System.getenv(envVarName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from environment variable: " + envVarName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } String sysPropName = "force." + connectionName + ".url"; if ((connectionUrl = System.getProperty(sysPropName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from Java system property: " + sysPropName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } URL propsFileUrl; if ((propsFileUrl = ForceConnectorUtils.class.getResource("/" + connectionName + ".properties")) != null) { LOGGER.info("Connection : Creating " + connectionName + " from classpath properties file: " + propsFileUrl); return cache(connectionName, loadConnectorPropsFromFile(propsFileUrl)); } if (cliforceConnFile.canRead()) { InputStream is = null; Properties cliforceConnUrls = new Properties(); try { is = new FileInputStream(cliforceConnFile); cliforceConnUrls.load(is); } finally { if (is != null) is.close(); } if (cliforceConnUrls.containsKey(connectionName)) { LOGGER.info("Connection : Creating " + connectionName + " from cliforce connections file: " + cliforceConnFile); return cache(connectionName, loadConnectorPropsFromUrl(cliforceConnUrls.getProperty(connectionName))); } } return null; } private  ForceConnectorUtils(); }
ForceConnectorUtils { public static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName) throws IOException { if (connectionName == null) return null; if (PROPERTIES_CACHE.containsKey(connectionName)) { LOGGER.info("Connection : loading " + connectionName + " from cache"); return PROPERTIES_CACHE.get(connectionName); } String connectionUrl; String envVarName = "FORCE_" + connectionName.toUpperCase() + "_URL"; if ((connectionUrl = System.getenv(envVarName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from environment variable: " + envVarName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } String sysPropName = "force." + connectionName + ".url"; if ((connectionUrl = System.getProperty(sysPropName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from Java system property: " + sysPropName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } URL propsFileUrl; if ((propsFileUrl = ForceConnectorUtils.class.getResource("/" + connectionName + ".properties")) != null) { LOGGER.info("Connection : Creating " + connectionName + " from classpath properties file: " + propsFileUrl); return cache(connectionName, loadConnectorPropsFromFile(propsFileUrl)); } if (cliforceConnFile.canRead()) { InputStream is = null; Properties cliforceConnUrls = new Properties(); try { is = new FileInputStream(cliforceConnFile); cliforceConnUrls.load(is); } finally { if (is != null) is.close(); } if (cliforceConnUrls.containsKey(connectionName)) { LOGGER.info("Connection : Creating " + connectionName + " from cliforce connections file: " + cliforceConnFile); return cache(connectionName, loadConnectorPropsFromUrl(cliforceConnUrls.getProperty(connectionName))); } } return null; } private  ForceConnectorUtils(); static String buildForceApiEndpoint(String endpoint); static boolean isInjectable(String var); static String extractValue(String var); static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName); static Map<ForceConnectionProperty, String> loadConnectorPropsFromUrl(String connectionUrl); static void clearCache(); }
ForceConnectorUtils { public static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName) throws IOException { if (connectionName == null) return null; if (PROPERTIES_CACHE.containsKey(connectionName)) { LOGGER.info("Connection : loading " + connectionName + " from cache"); return PROPERTIES_CACHE.get(connectionName); } String connectionUrl; String envVarName = "FORCE_" + connectionName.toUpperCase() + "_URL"; if ((connectionUrl = System.getenv(envVarName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from environment variable: " + envVarName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } String sysPropName = "force." + connectionName + ".url"; if ((connectionUrl = System.getProperty(sysPropName)) != null) { LOGGER.info("Connection : Creating " + connectionName + " from Java system property: " + sysPropName); return cache(connectionName, loadConnectorPropsFromUrl(connectionUrl)); } URL propsFileUrl; if ((propsFileUrl = ForceConnectorUtils.class.getResource("/" + connectionName + ".properties")) != null) { LOGGER.info("Connection : Creating " + connectionName + " from classpath properties file: " + propsFileUrl); return cache(connectionName, loadConnectorPropsFromFile(propsFileUrl)); } if (cliforceConnFile.canRead()) { InputStream is = null; Properties cliforceConnUrls = new Properties(); try { is = new FileInputStream(cliforceConnFile); cliforceConnUrls.load(is); } finally { if (is != null) is.close(); } if (cliforceConnUrls.containsKey(connectionName)) { LOGGER.info("Connection : Creating " + connectionName + " from cliforce connections file: " + cliforceConnFile); return cache(connectionName, loadConnectorPropsFromUrl(cliforceConnUrls.getProperty(connectionName))); } } return null; } private  ForceConnectorUtils(); static String buildForceApiEndpoint(String endpoint); static boolean isInjectable(String var); static String extractValue(String var); static Map<ForceConnectionProperty, String> loadConnectorPropsFromName(String connectionName); static Map<ForceConnectionProperty, String> loadConnectorPropsFromUrl(String connectionUrl); static void clearCache();  }