Example usage for java.util Properties size

List of usage examples for java.util Properties size

Introduction

In this page you can find the example usage for java.util Properties size.

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:gov.pnnl.goss.gridappsd.GridAppsDataSourcesComponentTests.java

@Test
/**/*from  ww w .j  a v a2  s  .c  o  m*/
 *    Succeeds when the proper number of properties are set on the updated call, and datasourcebuilder.create is called, and the correct registered datasource name is added
 */
public void registryUpdatedWhen_dataSourcesStarted() {
    ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);
    Properties datasourceProperties = new Properties();
    GridAppsDataSourcesImpl dataSources = new GridAppsDataSourcesImpl(logger, datasourceBuilder,
            datasourceRegistry, datasourceProperties);
    Hashtable<String, String> props = new Hashtable<String, String>();
    String datasourceName = "pnnl.goss.sql.datasource.gridappsd";
    props.put("name", datasourceName);
    props.put(DataSourceBuilder.DATASOURCE_USER, "gridappsduser");
    props.put(DataSourceBuilder.DATASOURCE_PASSWORD, "gridappsdpw");
    props.put(DataSourceBuilder.DATASOURCE_URL, "mysql://lalala");
    props.put("driver", "com.mysql.jdbc.Driver");
    dataSources.updated(props);

    assertEquals(5, datasourceProperties.size());
    dataSources.start();

    //verify datasourceBuilder.create(datasourceName, datasourceProperties);
    try {
        Mockito.verify(datasourceBuilder).create(argCaptor.capture(), Mockito.any());
        assertEquals(datasourceName, argCaptor.getValue());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        assert (false);
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }

    //verify registeredDatasources.add(datasourceName);
    List<String> registeredDatasources = dataSources.getRegisteredDatasources();
    assertEquals(1, registeredDatasources.size());

}

From source file:gov.pnnl.goss.gridappsd.GridAppsDataSourcesComponentTests.java

@Test
/**/*from  w w  w.java2 s  .c  om*/
 *    Succeeds when the registry is empty after the service has been stopped
 */
public void registryClearedWhen_dataSourcesStopped() {
    ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);
    Properties datasourceProperties = new Properties();
    GridAppsDataSourcesImpl dataSources = new GridAppsDataSourcesImpl(logger, datasourceBuilder,
            datasourceRegistry, datasourceProperties);
    Hashtable<String, String> props = new Hashtable<String, String>();
    String datasourceName = "pnnl.goss.sql.datasource.gridappsd";
    props.put("name", datasourceName);
    props.put(DataSourceBuilder.DATASOURCE_USER, "gridappsduser");
    props.put(DataSourceBuilder.DATASOURCE_PASSWORD, "gridappsdpw");
    props.put(DataSourceBuilder.DATASOURCE_URL, "mysql://lalala");
    props.put("driver", "com.mysql.jdbc.Driver");
    dataSources.updated(props);

    assertEquals(5, datasourceProperties.size());
    dataSources.start();

    //verify datasourceBuilder.create(datasourceName, datasourceProperties);
    try {
        Mockito.verify(datasourceBuilder).create(argCaptor.capture(), Mockito.any());
        assertEquals(datasourceName, argCaptor.getValue());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        assert (false);
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }

    //verify registeredDatasources.add(datasourceName);
    List<String> registeredDatasources = dataSources.getRegisteredDatasources();
    assertEquals(1, registeredDatasources.size());

    dataSources.stop();

    assertEquals(0, dataSources.getRegisteredDatasources().size());

}

From source file:org.fuin.utils4j.Utils4JTest.java

/**
 * @testng.test//from www . j av  a 2 s  . c om
 */
public final void testLoadPropertiesClassString() {
    final Properties props = Utils4J.loadProperties(Utils4JTest.class, "test.properties");
    Assert.assertEquals(3, props.size());
    Assert.assertEquals("1", props.get("one"));
    Assert.assertEquals("2", props.get("two"));
    Assert.assertEquals("3", props.get("three"));
}

From source file:org.fuin.utils4j.Utils4JTest.java

/**
 * @testng.test//from www. j  a  v  a2 s. c  o m
 */
public final void testLoadPropertiesURL() throws MalformedURLException {
    final Properties props = Utils4J.loadProperties(TEST_PROPERTIES_FILE.toURI().toURL());
    Assert.assertEquals(3, props.size());
    Assert.assertEquals("1", props.get("one"));
    Assert.assertEquals("2", props.get("two"));
    Assert.assertEquals("3", props.get("three"));
}

From source file:org.apache.slider.common.tools.SliderUtils.java

/**
 * Convert a properties instance to a string map.
 * @param properties source property object
 * @return a string map/*from w w  w . j  av  a  2 s  .c  o m*/
 */
public static Map<String, String> toMap(Properties properties) {
    Map<String, String> out = new HashMap<String, String>(properties.size());
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        out.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return out;
}

From source file:gov.pnnl.goss.gridappsd.GridAppsDataSourcesComponentTests.java

@Test
/**/*from   w w  w . j a v  a2  s  .c  o m*/
 *    Succeeds when the proper number of properties are set on the updated call, and datasourcebuilder.create is called, and the correct registered datasource name is added
 */
public void registryKeysExistWhen_dataSourcesStarted() {
    ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);

    try {
        //When datasourceBuilder.create is called add a face datasource object to the datasourceRegistry (similar to what the actual implementation would do)
        Answer answer = new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                String dsName = args[0].toString();
                datasourceRegistry.add(dsName, datasourceObject);
                return null;
            }
        };
        Mockito.doAnswer(answer).when(datasourceBuilder).create(argCaptor.capture(), Mockito.any());
    } catch (Exception e) {
        e.printStackTrace();
    }

    Properties datasourceProperties = new Properties();
    GridAppsDataSourcesImpl dataSources = new GridAppsDataSourcesImpl(logger, datasourceBuilder,
            datasourceRegistry, datasourceProperties);
    Hashtable<String, String> props = new Hashtable<String, String>();
    String datasourceName = "pnnl.goss.sql.datasource.gridappsd";
    props.put("name", datasourceName);
    props.put(DataSourceBuilder.DATASOURCE_USER, "gridappsduser");
    props.put(DataSourceBuilder.DATASOURCE_PASSWORD, "gridappsdpw");
    props.put(DataSourceBuilder.DATASOURCE_URL, "mysql://lalala");
    props.put("driver", "com.mysql.jdbc.Driver");
    dataSources.updated(props);

    assertEquals(5, datasourceProperties.size());
    dataSources.start();

    //verify datasourceBuilder.create(datasourceName, datasourceProperties);
    try {
        Mockito.verify(datasourceBuilder).create(argCaptor.capture(), Mockito.any());
        assertEquals(datasourceName, argCaptor.getValue());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        assert (false);
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }

    //verify registeredDatasources.add(datasourceName);
    List<String> registeredDatasources = dataSources.getRegisteredDatasources();
    assertEquals(1, registeredDatasources.size());

    //  test get data source keys
    Collection<String> dsKeys = dataSources.getDataSourceKeys();
    assertEquals(datasourceName, dsKeys.toArray()[0]);

    // test get data source by key
    DataSourcePooledJdbc obj = dataSources.getDataSourceByKey(datasourceName);
    assertEquals(datasourceObject, obj);

    // test get connection by key
    dataSources.getConnectionByKey(datasourceName);
    try {
        Mockito.verify(datasourceObject).getConnection();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    //verify datasourceregistry size
    assertEquals(1, datasourceRegistry.getAvailable().size());

}

From source file:com.cisco.dvbu.ps.common.util.PropertyManager.java

/**
 * get the property value with the specified key from the specified properties resource name. If the key is not found in this property resource a null value is returned.
 * /*from w  w w .ja  v a 2s . c  o  m*/
 * @param resourceName - the name of the properties file that contains the property
 * @param key - the property key
 * @return the property value for the provided key, or null if not found in the resource
 */
@SuppressWarnings("unchecked")
public String getProperty(String resourceName, String key) {
    Properties properties = (Properties) allProperties.get(resourceName);
    if (properties == null) {
        synchronized (PropertyManager.class) {
            properties = (Properties) allProperties.get(resourceName);
            if (properties == null) {
                properties = loadProperties(resourceName);
                if (properties != null) {
                    allProperties.put(resourceName, properties);
                }
            }
        }
    }

    if (properties == null || properties.size() == 0) {
        return null;
    }
    return properties.getProperty(key);
}

From source file:org.acmsl.commons.ConfigurationManager.java

/**
 * Retrieves the configuration settings.
 * @param propertiesFileName the properties' file name.
 * @param properties the properties.//w w  w . j a va  2s .  co m
 * @return the properties.
 */
@NotNull
protected final Properties getProperties(@NotNull final String propertiesFileName,
        @Nullable final Properties properties) {
    @NotNull
    final Properties result;

    if (properties == null) {
        result = new Properties();
        immutableSetProperties(result);
    } else {
        result = properties;
    }

    if (result.size() == 0) {
        loadProperties(result, propertiesFileName);
    }

    return result;
}

From source file:com.cisco.dvbu.ps.common.util.PropertyManager.java

/**
 * Returns a boolean true if the value passed into the method is contained 
 * within the value of the designated property key.   
 * If not found then return false./*  w  ww  .  j a v a2s  . c o m*/
 * If the property is not found then return false.
 *
 *Usage:  This method should be called by all modules that need to assess whether an
 *  attribute that is to be updated or output during generatexML is contained within
 *  the "Module Non-Updateable Attribute" property.  If not contained then the attribute
 *  can be generated or updated.  If it is contained then do not update it nor generate it
 *  in the XML.  An example property would be as follows:
 *    DataSourceModule_NonUpdateableAttributes=url,autoAddChildren,anyCharWildCard
 * @param resourceName - the name of the properties file that contains the property
 * @param key - the property key
 * @param value
 * @return boolean
 */
public boolean containsPropertyValue(String resourceName, String key, String value) {
    Properties properties = (Properties) allProperties.get(resourceName);
    if (properties == null) {
        synchronized (PropertyManager.class) {
            properties = (Properties) allProperties.get(resourceName);
            if (properties == null) {
                properties = loadProperties(resourceName);
                if (properties != null) {
                    allProperties.put(resourceName, properties);
                }
            }
        }
    }

    if (properties == null || properties.size() == 0) {
        return false;
    } else {
        String property = properties.getProperty(key);
        if (property == null || property.length() == 0) {
            return false;
        }
        if (property.contains(value)) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:org.mule.ibeans.config.PropertiesConfigurationBuilder.java

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    Properties props = new Properties();

    //Check for application properties first
    URL url = ClassUtils.getResource(IBEANS_PROPERTIES, getClass());
    if (url != null) {
        InputStream in = null;/*from  w w w.  ja v  a  2s .c om*/
        try {
            in = url.openStream();
            props.load(in);
        } catch (IOException e) {
            IOUtils.closeQuietly(in);
        }
    } else {
        logger.info("No application properties found at: " + IBEANS_PROPERTIES);
    }

    String propsLocation = System.getProperty(IBEANS_PROPERTIES_LOCATION, null);

    if (propsLocation != null) {
        File f = new File(propsLocation);
        loadProperties(f, props);
    }

    if (isLoadFromUserHome()) {
        File f = new File(System.getProperty("user.home") + File.separator + ".ibeans.properties");
        loadProperties(f, props);
    }

    if (props.size() > 0) {
        //TOOD We should create a new registry for properties to make it easier to hide application properties
        //if we ever expose the registry over a remote API i.e. REST
        //TransientRegistry reg = new TransientRegistry("ibeans-app.properties", muleContext);
        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            muleContext.getRegistry().registerObject(entry.getKey().toString(), entry.getValue());
        }
        //muleContext.addRegistry(reg);
    } else {
        logger.info("No properties found to load by the PropertiesConfigurationBuilder");
    }
}