Class XltProperties


  • public abstract class XltProperties
    extends java.lang.Object
    The property keeper. Loads and stores the properties of the entire tool. Single instance implementation.

    The process of looking up a property uses multiple fall-backs. When resolving the value for the key "foo.bar", for instance, the following effective keys are tried, in this order:

    1. the test user name plus simple key, e.g. "TOrder.foo.bar"
    2. the test class name plus simple key, e.g. "posters.loadtest.tests.TOrder.foo.bar"
    3. the simple key, i.e. "foo.bar"
    This multi-step process allows for test-user-specific or test-class-specific overrides of certain settings, while falling back to the globally defined values if such specific settings are absent.
    • Constructor Summary

      Constructors 
      Constructor Description
      XltProperties()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract XltProperties clear()
      Clears all properties but does not do anything else.
      abstract boolean containsKey​(java.lang.String key)
      Checks whether there is a mapping for the specified key in this property list.
      abstract java.util.Properties getCopyOfProperties()
      Returns a copy of all the internally stored properties, with any placeholder resolved.
      abstract java.lang.String getEffectiveKey​(Session session, java.lang.String bareKey)
      Returns the effective key to be used for property lookup via one of the getProperty(...) methods.
      abstract java.lang.String getEffectiveKey​(java.lang.String testCaseClassName, java.lang.String userName, java.lang.String bareKey)
      Behaves like getEffectiveKey(Session, String) but without the session dependency
      static XltProperties getInstance()
      Returns the one and only XltProperties instance.
      abstract java.util.Properties getProperties()
      Returns a reference to the properties.
      abstract java.util.Map<java.lang.String,​java.lang.String> getPropertiesForKey​(java.lang.String domainKey)
      Returns all properties whose name starts with the given domain key.
      abstract java.util.Optional<java.lang.String> getProperty​(Session session, java.lang.String key)
      Searches for the property with the specified key in this property list.
      abstract java.lang.String getProperty​(java.lang.String key)
      Searches for the property with the specified key in this property list.
      abstract boolean getProperty​(java.lang.String key, boolean defaultValue)
      Searches for the property with the specified key in this property list.
      abstract int getProperty​(java.lang.String key, int defaultValue)
      Searches for the property with the specified key in this property list.
      abstract long getProperty​(java.lang.String key, long defaultValue)
      Searches for the property with the specified key in this property list.
      abstract java.lang.String getProperty​(java.lang.String key, java.lang.String defaultValue)
      Searches for the property with the specified key in this property list.
      abstract java.util.LinkedHashMap<java.lang.String,​java.util.Properties> getPropertyBuckets()
      Returns an ordered list of property sources.
      abstract java.lang.String getPropertyRandomValue​(java.lang.String key, java.lang.String defaultValue)
      Returns one value of the given multi-value property.
      abstract long getStartTime()
      Returns the start time of the test in milliseconds since 1970.
      abstract java.lang.String getVersion()
      Returns the product version.
      abstract boolean isDevMode()
      Do we run in dev mode such as Maven or Eclipse or similar?
      abstract boolean isLoadTest()
      Do we run in load test mode?
      abstract void removeProperty​(java.lang.String key)
      Removes the property with the given key from the internal properties store.
      abstract void setProperties​(java.util.Properties newProperties)
      Method for changing the properties during runtime.
      abstract void setProperty​(java.lang.String key, java.lang.String value)
      Sets a property during runtime.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_PROPERTIES

        public static final java.lang.String DEFAULT_PROPERTIES
        Constants to indicate the name of the base properties
        See Also:
        Constant Field Values
      • PROJECT_PROPERTIES

        public static final java.lang.String PROJECT_PROPERTIES
        See Also:
        Constant Field Values
      • DEVELOPMENT_PROPERTIES

        public static final java.lang.String DEVELOPMENT_PROPERTIES
        See Also:
        Constant Field Values
      • SECRET_PROPERTIES

        public static final java.lang.String SECRET_PROPERTIES
        See Also:
        Constant Field Values
      • SYSTEM_PROPERTIES

        public static final java.lang.String SYSTEM_PROPERTIES
        See Also:
        Constant Field Values
    • Constructor Detail

      • XltProperties

        public XltProperties()
    • Method Detail

      • getInstance

        public static XltProperties getInstance()
        Returns the one and only XltProperties instance.
        Returns:
        the XltProperties singleton
      • containsKey

        public abstract boolean containsKey​(java.lang.String key)
        Checks whether there is a mapping for the specified key in this property list.
        Parameters:
        key - the property key
        Returns:
        true if there is a mapping, false otherwise
      • getCopyOfProperties

        public abstract java.util.Properties getCopyOfProperties()
        Returns a copy of all the internally stored properties, with any placeholder resolved.
        Returns:
        the properties
      • getProperties

        public abstract java.util.Properties getProperties()
        Returns a reference to the properties. This is mainly here for speed. Deal with it at your own discretion. You are not supposed to modify these!
        Returns:
        the properties
      • getPropertyBuckets

        public abstract java.util.LinkedHashMap<java.lang.String,​java.util.Properties> getPropertyBuckets()
        Returns an ordered list of property sources. This allows a more tailored access if needed. Don't write to these properties, because XLT will not pay any attention. This is mainly meant when you want to extend the property concept in a test suite for your own pleasure. Please keep in mind that this is all shared across test threads, hence it is read-only which is also in parts enforced.
      • getPropertiesForKey

        public abstract java.util.Map<java.lang.String,​java.lang.String> getPropertiesForKey​(java.lang.String domainKey)
        Returns all properties whose name starts with the given domain key. The domain is stripped from the resulting property names.
        Parameters:
        domainKey - domain for the properties
        Returns:
        a map with all matching properties
      • getProperty

        public abstract java.lang.String getProperty​(java.lang.String key)
        Searches for the property with the specified key in this property list. The method returns null if the property is not found. This method will lookup the session from the context automatically!
        Parameters:
        key - the property key
        Returns:
        the value of the key
      • getProperty

        public abstract java.util.Optional<java.lang.String> getProperty​(Session session,
                                                                         java.lang.String key)
        Searches for the property with the specified key in this property list. The method returns null if the property is not found. In most cases, getProperty(String)} will be sufficient. For testing and more advanced use cases, a session context can be passed in.
        Parameters:
        key - the property key
        session - the session information to use to enhance the lookup
        Returns:
        the value of the key
        Since:
        7.0.0
      • getProperty

        public abstract boolean getProperty​(java.lang.String key,
                                            boolean defaultValue)
        Searches for the property with the specified key in this property list. The method returns the default value argument if the property is not found.
        Parameters:
        key - the property key
        defaultValue - the defaultValue if key not found
        Returns:
        the value of the key as a boolean
      • getProperty

        public abstract int getProperty​(java.lang.String key,
                                        int defaultValue)
        Searches for the property with the specified key in this property list. The method returns the default value argument if the property is not found.
        Parameters:
        key - the property key
        defaultValue - the defaultValue if key not found
        Returns:
        the value of the key as an int
      • getProperty

        public abstract long getProperty​(java.lang.String key,
                                         long defaultValue)
        Searches for the property with the specified key in this property list. The method returns the default value argument if the property is not found.
        Parameters:
        key - the property key
        defaultValue - the defaultValue if key not found
        Returns:
        the value of the key as a long
      • getProperty

        public abstract java.lang.String getProperty​(java.lang.String key,
                                                     java.lang.String defaultValue)
        Searches for the property with the specified key in this property list. The method returns the default value argument if the property is not found. The key is upper-cased before the property will be searched.
        Parameters:
        key - the property key
        defaultValue - the defaultValue if key not found
        Returns:
        the value of the key
      • getPropertyRandomValue

        public abstract java.lang.String getPropertyRandomValue​(java.lang.String key,
                                                                java.lang.String defaultValue)
        Returns one value of the given multi-value property. Multiple values are separated by comma, semicolon, or space. The returned value is chosen randomly from the set of values.
        Parameters:
        key - the name of the property
        defaultValue - the default property value (a multi-value)
        Returns:
        one of the values, chosen randomly
      • getStartTime

        public abstract long getStartTime()
        Returns the start time of the test in milliseconds since 1970.
        Returns:
        the start time of the test in milliseconds
      • getEffectiveKey

        public abstract java.lang.String getEffectiveKey​(Session session,
                                                         java.lang.String bareKey)
        Returns the effective key to be used for property lookup via one of the getProperty(...) methods.

        When looking up a key, "password" for example, the following effective keys are tried, in this order:

        1. the prefix "secret." plus the simple key to ensure precedence of secret properties over public ones
        2. the test user name plus simple key, e.g. "TAuthor.password"
        3. the test class name plus simple key, e.g. "com.xceptance.xlt.samples.tests.TAuthor.password"
        4. the simple key, e.g. "password"
        This method has been opened so that property extensions can use this logic for their own purpose if needed.
        Parameters:
        session - the session to get utility data from
        bareKey - the bare property key, i.e. without any prefixes
        Returns:
        the first key that produces a result
        Since:
        7.0.0
      • getEffectiveKey

        public abstract java.lang.String getEffectiveKey​(java.lang.String testCaseClassName,
                                                         java.lang.String userName,
                                                         java.lang.String bareKey)
        Behaves like getEffectiveKey(Session, String) but without the session dependency
        Parameters:
        testCaseClassName - the classname the property might have been extended with
        userName - the current username which might be in the property name
        bareKey - the key without any prefixes
        Returns:
        Since:
        7.0.0
      • getVersion

        public abstract java.lang.String getVersion()
        Returns the product version.
        Returns:
        the version string, e.g. "1.1.0"
      • removeProperty

        public abstract void removeProperty​(java.lang.String key)
        Removes the property with the given key from the internal properties store.
        Parameters:
        key - the property key
      • setProperties

        public abstract void setProperties​(java.util.Properties newProperties)
        Method for changing the properties during runtime. Can be called multiple times to add additional properties. It does not apply System properties automatically anymore!!! If you need that in your logic, simply run #setProperties(System.getProperties()
        Parameters:
        newProperties - complete new set of properties, will be added to existing properties and overwrites already defined properties with new values. None existing properties will be added.
      • setProperty

        public abstract void setProperty​(java.lang.String key,
                                         java.lang.String value)
        Sets a property during runtime. Overwrites an existing property with the same name. Does not re-apply any java system settings.
        Parameters:
        key - new property key
        value - new property value
      • clear

        public abstract XltProperties clear()
        Clears all properties but does not do anything else. This is a dangerous operation!
        Returns:
        the cleared instance
      • isLoadTest

        public abstract boolean isLoadTest()
        Do we run in load test mode?
        Returns:
        true if this instance is running a load test aka this is executed by an agent
      • isDevMode

        public abstract boolean isDevMode()
        Do we run in dev mode such as Maven or Eclipse or similar?
        Returns:
        true if this instance is running a dev mode, false otherwise