org.kuali.rice.testtools.common
Class PropertiesUtils

java.lang.Object
  extended by org.kuali.rice.testtools.common.PropertiesUtils

public class PropertiesUtils
extends Object

Util Properties methods which have come from refactoring test generation using freemarker, providing overriding of file properties from System Properties as well as setting file properties as System Properties, as well as turning numbered properties to a List.

Author:
Kuali Rice Team (rice.collab@kuali.org)

Constructor Summary
PropertiesUtils()
           
 
Method Summary
 Properties loadProperties(InputStream inputStream)
           Plain load Properties from the given inputStream.
 Properties loadProperties(String location)
           Read Properties from given Loaction
 Properties loadProperties(String fileLocation, String resourceLocation)
          Deprecated. loadProperties(String)
 Properties loadPropertiesWithSystemAndOverrides(String location)
           
 Properties loadPropertiesWithSystemAndOverridesIntoSystem(String location)
           Beware of classloader/timing issues! Sometimes properties get added to the System properties after the point you might expect.
 Properties loadPropertiesWithSystemOverrides(InputStream inputStream)
           Read the properties from an inputStream overridding keys defined as JVM arguments.
 Properties loadPropertiesWithSystemOverrides(String location)
           
 Properties loadPropertiesWithSystemOverridesAndNumberedPropertiesToList(InputStream inputStream)
           Read the properties from an inputStream overridding keys defined as JVM arguments and transforming numbered keys into a list.
 String removeNumber(String numberedKey)
           Given a key that ends in a number, remove the number.
 Properties systemPropertiesAndOverride(Properties props)
           
 Properties systemPropertiesAndOverride(Properties props, String arg)
           In addition to overriding file properties from System Properties, System properties are added to the returned Properties.
 Properties systemPropertiesOverride(Properties props)
           Override the given Properties with JVM argument -Dkey=value.
 Properties systemPropertiesOverride(Properties props, String arg)
           Override the given Properties with JVM argument -Darg.key=value.
 Properties transformNumberedPropertiesToList(Properties props)
           Transform the given Properties keys which end in numbers to a List placed in a Map with the map key being the unumbered part of the Properties key with an s appended to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesUtils

public PropertiesUtils()
Method Detail

loadProperties

public Properties loadProperties(InputStream inputStream)
                          throws IOException

Plain load Properties from the given inputStream.

Parameters:
inputStream - to read properties from
Returns:
Properties read from given Inputstream
Throws:
IOException

loadProperties

public Properties loadProperties(String fileLocation,
                                 String resourceLocation)
                          throws IOException
Deprecated. loadProperties(String)

Read Properties from given Inputstream or Resource Loaction if the InputStream is null.

If a FileNotFoundException is thrown opening the InputStream an attempt will be made to read as a resource.

Parameters:
fileLocation - null means use resourceLocation
resourceLocation - load resource as a stream getClass().getClassLoader().getResourceAsStream(resourceLocation);
Returns:
Properties read from given Inputstream or Resource Loaction if the InputStream is null
Throws:
IOException

loadProperties

public Properties loadProperties(String location)
                          throws IOException

Read Properties from given Loaction

If a FileNotFoundException is thrown opening the InputStream an attempt will be made to read as a resource.

Parameters:
location -
Returns:
Properties read from given Inputstream or Resource Loaction if the InputStream is null
Throws:
IOException

loadPropertiesWithSystemAndOverrides

public Properties loadPropertiesWithSystemAndOverrides(String location)
                                                throws IOException
Throws:
IOException

loadPropertiesWithSystemAndOverridesIntoSystem

public Properties loadPropertiesWithSystemAndOverridesIntoSystem(String location)
                                                          throws IOException

Beware of classloader/timing issues! Sometimes properties get added to the System properties after the point you might expect. Resulting in the System property not really being set for when you expected, such as with settign statics. Looks like WebDriverLegacyITBase has this going on with public.remote.url

Parameters:
location - file or resource to load properties from, file is attempted first
Returns:
Properties
Throws:
IOException

loadPropertiesWithSystemOverrides

public Properties loadPropertiesWithSystemOverrides(String location)
                                             throws IOException
Throws:
IOException

loadPropertiesWithSystemOverrides

public Properties loadPropertiesWithSystemOverrides(InputStream inputStream)
                                             throws IOException

Read the properties from an inputStream overridding keys defined as JVM arguments.

systemPropertiesOverride(java.util.Properties)

Parameters:
inputStream - to read properties from
Returns:
Properties loaded from inputStream and overridden with JVM arguments
Throws:
IOException

loadPropertiesWithSystemOverridesAndNumberedPropertiesToList

public Properties loadPropertiesWithSystemOverridesAndNumberedPropertiesToList(InputStream inputStream)
                                                                        throws IOException

Read the properties from an inputStream overridding keys defined as JVM arguments and transforming numbered keys into a list.

systemPropertiesOverride(java.util.Properties) transformNumberedPropertiesToList(java.util.Properties)

Parameters:
inputStream -
Returns:
Properties loaded from inputStream, overridden with JVM arguments, and keys ending in numbers transformed to a List
Throws:
IOException

removeNumber

public String removeNumber(String numberedKey)

Given a key that ends in a number, remove the number.

Parameters:
numberedKey - in the form of some.key.number
Returns:
some.key part of some.key.number

systemPropertiesAndOverride

public Properties systemPropertiesAndOverride(Properties props)

systemPropertiesOverride

public Properties systemPropertiesOverride(Properties props)

Override the given Properties with JVM argument -Dkey=value.

Parameters:
props - properties to update with System.getProperty overrides.

systemPropertiesAndOverride

public Properties systemPropertiesAndOverride(Properties props,
                                              String arg)

In addition to overriding file properties from System Properties, System properties are added to the returned Properties.

systemPropertiesOverride(java.util.Properties)

Parameters:
props - Properties with System Properties added and Overriding file properties
arg - filter System Properties added to Properties by the Property key starting with arg
Returns:

systemPropertiesOverride

public Properties systemPropertiesOverride(Properties props,
                                           String arg)

Override the given Properties with JVM argument -Darg.key=value.

-Dkey.propertyname= to override the property value for propertyname.

Parameters:
props - properties to update with System.getProperty overrides.
arg - optional value that the property names will be appended to.

transformNumberedPropertiesToList

public Properties transformNumberedPropertiesToList(Properties props)

Transform the given Properties keys which end in numbers to a List placed in a Map with the map key being the unumbered part of the Properties key with an s appended to it.

Parameters:
props - Properties to have keys ending in


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.