List of usage examples for java.util Properties size
@Override public int size()
From source file:org.jasig.cas.client.tomcat.PropertiesCasRealmDelegate.java
/** {@inheritDoc} */ public void readProperties() { CommonUtils.assertNotNull(propertiesFilePath, "PropertiesFilePath not set."); File file = new File(propertiesFilePath); if (!file.isAbsolute()) { file = new File(System.getProperty("catalina.base"), propertiesFilePath); }/*from ww w . ja va2 s . co m*/ CommonUtils.assertTrue(file.exists(), "File not found " + file); CommonUtils.assertTrue(file.canRead(), "Cannot read " + file); log.debug("Loading users/roles from " + file); final Properties properties = new Properties(); try { properties.load(new BufferedInputStream(new FileInputStream(file))); } catch (final IOException e) { throw new IllegalStateException("Error loading users/roles from " + file, e); } this.roleMap = new HashMap<String, Set<String>>(properties.size()); for (final Object key : properties.keySet()) { final String user = (String) key; // Use TreeSet to sort roles final Set<String> roleSet = new HashSet<String>(); final String[] roles = properties.getProperty(user).split(",\\s*"); roleSet.addAll(Arrays.asList(roles)); roleMap.put(user, roleSet); } }
From source file:org.fusesource.cloudmix.testing.samples.ActiveMQMopTest.java
@Test public void testScenarioDeploys() throws Exception { System.out.println("TEST NAME: " + getTestName()); checkProvisioned();//from ww w .j ava 2 s . co m System.out.println("Worked!!!"); List<AgentDetails> agents = getAgentsFor(broker); assertTrue("has some agents", !agents.isEmpty()); for (AgentDetails agent : agents) { System.out.println("Broker agent: " + agent.getHostname()); } System.out.println("Configuration Properties = {"); Properties properties = getConfigurationProperties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { System.out.println(" " + entry.getKey() + " " + entry.getValue()); } System.out.println("}"); assertEquals("Number of configuration properties", 1, properties.size()); String brokerUrl = properties.getProperty("broker.url"); assertNotNull("should have broker.url configuration property", brokerUrl); System.out.println("BrokerURL: " + brokerUrl); // show the processes List<? extends ProcessClient> producerProcesses = getProcessClientsFor(producer); assertEquals("size of producer processes", 1, producerProcesses.size()); ProcessClient processClient = producerProcesses.get(0); assertNotNull("Should have a processClient for a producer", processClient); System.out.println("ProcessClient: " + processClient); // now lets get the log so far! String log = null; for (int i = 0; i < 20; i++) { if (i > 0) { Thread.sleep(5000); LOG.info("Reattempting to get the log"); } try { log = processClient.directoryResource("output.log").get(String.class); if (log != null) { break; } } catch (UniformInterfaceException e) { LOG.warn("Failed to find log " + e); } } assertNotNull("Should not have a null log!", log); System.out.println("Process Log >>>>"); System.out.println(log); Thread.sleep(10000); }
From source file:org.springframework.batch.core.jsr.configuration.xml.JsrBeanDefinitionDocumentReaderTests.java
@Test public void testGetJobProperties() { Document document = getDocument("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml"); @SuppressWarnings("resource") JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(); JsrBeanDefinitionDocumentReader documentReader = new JsrBeanDefinitionDocumentReader(applicationContext); documentReader.initProperties(document.getDocumentElement()); Properties documentJobProperties = documentReader.getJobProperties(); assertNotNull(documentJobProperties); assertTrue("Wrong number of job properties", documentJobProperties.size() == 3); assertEquals("jobProperty1Value", documentJobProperties.getProperty("jobProperty1")); assertEquals("jobProperty1Value", documentJobProperties.getProperty("jobProperty2")); assertEquals("", documentJobProperties.getProperty("jobProperty3")); }
From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurerTest.java
@Test public void testAddPropertiesFromFile() throws Exception { Path sakuliPropFile = Paths.get(getClass().getResource("/JUnit-sakuli.properties").toURI()); assertTrue(Files.exists(sakuliPropFile)); Properties props = new Properties(); testling.addPropertiesFromFile(props, sakuliPropFile.toAbsolutePath().toString(), true); assertTrue(props.size() > 0); assertEquals(props.getProperty(ActionProperties.TAKE_SCREENSHOTS), "true", "assert of property " + ActionProperties.TAKE_SCREENSHOTS); }
From source file:org.springframework.batch.core.jsr.configuration.xml.JsrBeanDefinitionDocumentReaderTests.java
@Test public void testJobPropertyResolution() { Properties jobParameters = new Properties(); jobParameters.setProperty("file.name", "myfile.txt"); @SuppressWarnings("resource") JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(jobParameters); applicationContext.setValidating(false); applicationContext.load(new ClassPathResource("jsrBaseContext.xml"), new ClassPathResource("/META-INF/batch.xml"), new ClassPathResource("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml")); applicationContext.refresh();/*from ww w . j a v a 2 s. c o m*/ Document document = getDocument("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml"); JsrBeanDefinitionDocumentReader documentReader = new JsrBeanDefinitionDocumentReader(applicationContext); documentReader.initProperties(document.getDocumentElement()); Properties resolvedProperties = documentReader.getJobProperties(); assertNotNull(resolvedProperties); assertTrue("Wrong number of job properties", resolvedProperties.size() == 3); assertEquals("jobProperty1Value", resolvedProperties.getProperty("jobProperty1")); assertEquals("jobProperty1Value", resolvedProperties.getProperty("jobProperty2")); assertEquals("myfile.txt", resolvedProperties.getProperty("jobProperty3")); }
From source file:org.springframework.batch.core.jsr.configuration.xml.JsrBeanDefinitionDocumentReaderTests.java
@Test public void testJobParametersResolution() { Properties jobParameters = new Properties(); jobParameters.setProperty("jobParameter1", "myfile.txt"); jobParameters.setProperty("jobParameter2", "#{jobProperties['jobProperty2']}"); jobParameters.setProperty("jobParameter3", "#{jobParameters['jobParameter1']}"); @SuppressWarnings("resource") JsrXmlApplicationContext applicationContext = new JsrXmlApplicationContext(jobParameters); applicationContext.setValidating(false); applicationContext.load(new ClassPathResource("jsrBaseContext.xml"), new ClassPathResource("/META-INF/batch.xml"), new ClassPathResource("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml")); applicationContext.refresh();/*from ww w . j a va2 s .com*/ Document document = getDocument("/META-INF/batch-jobs/jsrPropertyPreparseTestJob.xml"); JsrBeanDefinitionDocumentReader documentReader = new JsrBeanDefinitionDocumentReader(applicationContext); documentReader.initProperties(document.getDocumentElement()); Properties resolvedParameters = documentReader.getJobParameters(); assertNotNull(resolvedParameters); assertTrue("Wrong number of job parameters", resolvedParameters.size() == 3); assertEquals("myfile.txt", resolvedParameters.getProperty("jobParameter1")); assertEquals("jobProperty1Value", resolvedParameters.getProperty("jobParameter2")); assertEquals("myfile.txt", resolvedParameters.getProperty("jobParameter3")); }
From source file:com.properned.model.MultiLanguageProperties.java
public void save() throws IOException { logger.info("Save the multi language properties instance"); Set<Locale> setLocale = mapPropertiesFileByLocale.keySet(); for (Locale locale : setLocale) { PropertiesFile propertiesFile = mapPropertiesFileByLocale.get(locale); Properties properties = mapPropertiesByLocale.get(locale); if (properties == null) { continue; }// www . ja va 2s . co m logger.info("For the locale '" + locale + "', there is " + properties.size() + " properties to save"); OutputStream fileOutputStream = null; try { fileOutputStream = new BufferedOutputStream(new FileOutputStream(propertiesFile)); properties.store(fileOutputStream, ""); } finally { IOUtils.closeQuietly(fileOutputStream); } } this.setIsDirty(false); }
From source file:com.googlecode.flyway.commandline.MainMediumTest.java
@Test public void loadConfigurationFile() throws Exception { Properties properties = new Properties(); properties.put("existing", "still there!"); properties.put("override", "loses :-("); String filename = new ClassPathResource("test.properties").getFile().getPath(); String[] args = new String[] { "-configFile=" + filename, "-configFileEncoding=UTF-8" }; Main.loadConfigurationFile(properties, args); assertEquals(4, properties.size()); assertEquals("still there!", properties.getProperty("existing")); assertEquals("rbbit 123", properties.getProperty("roger")); assertEquals("wins :-)", properties.getProperty("override")); }
From source file:com.twinsoft.convertigo.engine.EnginePropertiesManager.java
public static String getPropertiesAsString(String title, Properties propertiesToGet) { if (propertiesToGet == null) { if (properties == null) { throw new IllegalStateException("Not initialized EnginePropertiesManager"); }//from w w w . j a v a2s.com propertiesToGet = properties; } List<String> vProperties = new ArrayList<String>(propertiesToGet.size()); for (Object propKey : propertiesToGet.keySet()) { String propValue = propertiesToGet.getProperty((String) propKey); vProperties.add(propKey + "=" + propValue); } Collections.sort(vProperties); String msg = title + "\n"; for (String line : vProperties) { msg += line + "\n"; } return msg; }
From source file:org.fabrican.extension.variable.provider.VariableProviderProxy.java
public Properties getVariables(FabricEngineInfo engineInfo, StackInfo stackInfo, ComponentInfo componentInfo) { MapContext jc = new MapContext(); jc.set("engineInfo", engineInfo); jc.set("stackInfo", stackInfo); jc.set("componentInfo", componentInfo); String p = evaluate(getPrimaryKey(), jc); String s = evaluate(getSecondaryKey(), jc); ;//from w ww . j a va 2 s .c o m if (getServerURL() == null) { throw new IllegalArgumentException("serverURL is not set"); } String u = getServerURL(); try { u += "?primary=" + (p == null ? "" : URLEncoder.encode(p.trim(), "utf-8")); u += "&secondary=" + (s == null ? "" : URLEncoder.encode(s.trim(), "utf-8")); } catch (UnsupportedEncodingException e) { // we always have "UTF-8" but anyway throw new RuntimeException("utf-8 not supported", e); } InputStream is = null; try { URL url = new URL(u); URLConnection c = url.openConnection(); is = c.getInputStream(); JSONTokener tokener = new JSONTokener(new InputStreamReader(is, "utf-8")); JSONObject jObj = new JSONObject(tokener); Properties r = new Properties(); @SuppressWarnings("unchecked") Iterator<String> keys = jObj.keys(); while (keys.hasNext()) { String k = keys.next(); r.put(k, jObj.getString(k)); } String msg = "no variables"; if (r.size() > 0) { msg = r.toString(); } ContainerUtils.getLogger(this).fine( "Provided " + msg + " to Engine " + engineInfo.getUsername() + "-" + engineInfo.getInstance()); return r; } catch (IOException ioe) { throw new RuntimeException("failed to connection to web server", ioe); } catch (JSONException je) { throw new RuntimeException("failed to parse response from web server", je); } finally { try { if (is != null) { is.close(); } } catch (Exception e) { } } }