Interface DataDictionary

  • All Known Subinterfaces:
    DataTable
    All Known Implementing Classes:
    EggplantVirtualUser, EggplantVirtualUserScript, SeleniumVirtualUser, SeleniumVirtualUserScript, VirtualUser, VirtualUserScript, WebBrowserScript, WebBrowserVirtualUser

    public interface DataDictionary
    The DataDictionary interface is implemented by all Eggplant Performance VirtualUserScript classes and the DataTable interface.

    A Data Dictionary is a collection of key/value pairs where key is a keyword used to extract a value. Every VirtualUser in a running test has a Data Dictionary. Suppose a Data Dictionary contains a key "counter" whose value is 22. To extract the value from the dictionary use the following code:

    int count = getInt("counter"); // count is now set to 22

    or

    String count = getString("counter"); // count is now set to "22"

    A DataDictionary can be populated from a Data Dictionary File. This is a text file containing lines of text in the form key=value.

    e.g.

    
     host = 192.168.2.7
     port = 1245
     user = Jane Smith
     password = myPassword
     
    eggPlant Performance Studio enables you to associate Data Dictionary files with a test and multiple VU Groups. The key/value pairs in the files are loaded into each VU's data dictionary when the test is initialized. Studio also allows you to add values using the inline-data form of a test's Data properties. You may also add values within your script code using the add(DataDictionary) or set(String, Object) methods described in this reference. The methods and properties described in this reference can all be accessed directly from within the code of any script class because the base script class, VirtualUserScript inherits DataDictionary.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(DataDictionary d)
      Merges the specified DataDictionary into this DataDictionary.
      <T> T get​(java.lang.String key)
      Returns a reference to an Object held in the dictionary.
      <T> T get​(java.lang.String key, T defaultValue)
      Returns an Object value held in the dictionary, or the defaultValue if the key cannot be found.
      boolean getBoolean​(java.lang.String key)
      Returns a boolean value held in the dictionary.
      boolean getBoolean​(java.lang.String key, boolean defaultValue)
      Returns a boolean value held in the dictionary, or the defaultValue if the key cannot be found.
      double getDouble​(java.lang.String key)
      Returns a double value held in the dictionary.
      double getDouble​(java.lang.String key, double defaultValue)
      Returns a double value held in the dictionary, or the defaultValue if the key cannot be found.
      float getFloat​(java.lang.String key)
      Returns a float value held in the dictionary.
      float getFloat​(java.lang.String key, float defaultValue)
      Returns a float value held in the dictionary, or the defaultValue if the key cannot be found.
      int getInt​(java.lang.String key)
      Returns an int value held in the dictionary.
      int getInt​(java.lang.String key, int defaultValue)
      Returns an int value held in the dictionary, or the defaultValue if the key cannot be found.
      java.lang.Integer getInteger​(java.lang.String key)
      Returns a java.lang.Integer value held in the dictionary.
      java.lang.Integer getInteger​(java.lang.String key, java.lang.Integer defaultValue)
      Returns a java.lang.Integer value held in the dictionary, or the defaultValue if the key cannot be found.
      java.util.List getList​(java.lang.String key)
      Returns a List value held in the dictionary.
      java.util.List getList​(java.lang.String key, java.util.List defaultList)
      Returns a List value held in the dictionary, or the defaultList if the key cannot be found.
      long getLong​(java.lang.String key)
      Returns a long value held in the dictionary.
      long getLong​(java.lang.String key, long defaultValue)
      Returns a long value held in the dictionary, or the defaultValue if the key cannot be found.
      java.util.Map getMap()
      Gets a Map containing all the keys/values in this dictionary.
      java.lang.String getName()
      Gets the name of this dictionary.
      java.lang.String getString​(java.lang.String key)
      Returns a String value held in the dictionary.
      java.lang.String getString​(java.lang.String key, java.lang.String defaultValue)
      Returns a String value held in the dictionary, or the defaultValue if the key cannot be found.
      boolean hasKey​(java.lang.String key)
      Returns true if the specified key is contained within the dictionary.
      boolean isReadOnly()
      Returns true if this dictionary is read-only.
      java.util.Iterator keys()
      Returns an Iterator that can be used to iterate over the keys in this dictionary.
      <T> void set​(java.lang.String key, T o)
      Sets an Object value in the dictionary.
      void setBoolean​(java.lang.String key, boolean b)
      Sets a boolean value in the dictionary.
      void setDouble​(java.lang.String key, double i)
      Sets a double value in the dictionary.
      void setFloat​(java.lang.String key, float i)
      Sets a float value in the dictionary.
      void setInt​(java.lang.String key, int i)
      Sets an int value in the dictionary.
      void setInteger​(java.lang.String key, java.lang.Integer i)
      Sets an Integer value in the dictionary.
      void setList​(java.lang.String key, java.util.List list)
      Sets a List value in the dictionary.
      void setLong​(java.lang.String key, long i)
      Sets a long value in the dictionary.
      void setName​(java.lang.String name)
      Sets the name of this dictionary.
      void setString​(java.lang.String key, java.lang.String string)
      Sets a String value in the dictionary.
      java.lang.String toString()
      Returns a String representation of the dictionary.
    • Method Detail

      • getMap

        java.util.Map getMap()
        Gets a Map containing all the keys/values in this dictionary.
        Returns:
        a Map containing all the keys/values in this dictionary
      • getString

        java.lang.String getString​(java.lang.String key,
                                   java.lang.String defaultValue)
                            throws BadValueException,
                                   NoSuchValueException
        Returns a String value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myString, using default value instead: abcd

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        a String value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        NoSuchValueException - the key does not exist in the dictionary
        BadValueException - the key was null
        See Also:
        setString(String, String)
      • getInteger

        java.lang.Integer getInteger​(java.lang.String key,
                                     java.lang.Integer defaultValue)
                              throws BadValueException
        Returns a java.lang.Integer value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myInteger, using default value instead: 1234

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        a java.lang.Integer value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setInteger(String, Integer)
      • getInt

        int getInt​(java.lang.String key,
                   int defaultValue)
            throws BadValueException
        Returns an int value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myInt, using default value instead: 1234

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        an int value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setInt(String, int)
      • getLong

        long getLong​(java.lang.String key,
                     long defaultValue)
              throws BadValueException
        Returns a long value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myLong, using default value instead: 1234567890L

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        a long value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setLong(String, long)
      • getFloat

        float getFloat​(java.lang.String key,
                       float defaultValue)
                throws BadValueException
        Returns a float value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myFloat, using default value instead: 3.142F

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        a float value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setFloat(String, float)
      • getDouble

        double getDouble​(java.lang.String key,
                         double defaultValue)
                  throws BadValueException
        Returns a double value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myDouble, using default value instead: 1.234

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        a double value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setDouble(String, double)
      • getBoolean

        boolean getBoolean​(java.lang.String key,
                           boolean defaultValue)
                    throws BadValueException
        Returns a boolean value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myBoolean, using default value instead: true

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        a boolean value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setBoolean(String, boolean)
      • get

        <T> T get​(java.lang.String key)
           throws NoSuchValueException,
                  BadValueException
        Returns a reference to an Object held in the dictionary.
        Type Parameters:
        T - The type of object to retrieve from the dictionary
        Parameters:
        key - the key to be looked up in the dictionary
        Returns:
        an Object value held in the dictionary
        Throws:
        NoSuchValueException - the key does not exist in the dictionary
        BadValueException - the key was null
        See Also:
        set(String, Object)
      • get

        <T> T get​(java.lang.String key,
                  T defaultValue)
           throws BadValueException
        Returns an Object value held in the dictionary, or the defaultValue if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultValue is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myObject, using default value instead: abcd1234

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Type Parameters:
        T - The type of object to retrieve from the dictionary
        Parameters:
        key - the key to be looked up in the dictionary
        defaultValue - the value to return if the key is not present in the dictionary
        Returns:
        an Object value held in the dictionary, or the defaultValue if the key cannot be found
        Throws:
        BadValueException - the key was null
      • keys

        java.util.Iterator keys()
        Returns an Iterator that can be used to iterate over the keys in this dictionary.
        Returns:
        an Iterator that can be used to iterate over the keys in this dictionary
      • add

        void add​(DataDictionary d)
          throws NotAllowedException,
                 BadValueException
        Merges the specified DataDictionary into this DataDictionary.

        All keys and values are added to this DataDictionary. Any keys which already exist in this DataDictionary will have their values replaced.

        Parameters:
        d - the DataDictionary to be merged
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - Tried to a dd a null value to the dictionary
      • setString

        void setString​(java.lang.String key,
                       java.lang.String string)
                throws NotAllowedException,
                       BadValueException
        Sets a String value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setString("hostName", "www.testplant.com");
         
        Parameters:
        key - the key to associate with string in the dictionary
        string - the String to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getString(String)
      • setInteger

        void setInteger​(java.lang.String key,
                        java.lang.Integer i)
                 throws NotAllowedException,
                        BadValueException
        Sets an Integer value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setInteger("port", 8080);
         
        Parameters:
        key - the key to associate with i in the dictionary
        i - the Integer to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getInteger(String)
      • setInt

        void setInt​(java.lang.String key,
                    int i)
             throws NotAllowedException,
                    BadValueException
        Sets an int value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setInt("port", 8080);
         
        Parameters:
        key - the key to associate with i in the dictionary
        i - the int to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getInt(String)
      • setLong

        void setLong​(java.lang.String key,
                     long i)
              throws NotAllowedException,
                     BadValueException
        Sets a long value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setLong("amount", 9156598231230);
         
        Parameters:
        key - the key to associate with i in the dictionary
        i - the long to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getLong(String)
      • setFloat

        void setFloat​(java.lang.String key,
                      float i)
               throws NotAllowedException,
                      BadValueException
        Sets a float value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setFloat("amount", 123.45);
         
        Parameters:
        key - the key to associate with i in the dictionary
        i - the float to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getFloat(String)
      • setDouble

        void setDouble​(java.lang.String key,
                       double i)
                throws NotAllowedException,
                       BadValueException
        Sets a double value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setDouble("amount", 123.45);
         
        Parameters:
        key - the key to associate with i in the dictionary
        i - the double to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getDouble(String)
      • setBoolean

        void setBoolean​(java.lang.String key,
                        boolean b)
                 throws NotAllowedException,
                        BadValueException
        Sets a boolean value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         setBoolean("retryLogon", false);
         
        Parameters:
        key - the key to associate with b in the dictionary
        b - the boolean to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getBoolean(String)
      • set

        <T> void set​(java.lang.String key,
                     T o)
              throws NotAllowedException,
                     BadValueException
        Sets an Object value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         set("today", new Date());
         
        Type Parameters:
        T - The type of object to add to the dictionary
        Parameters:
        key - the key to associate with o in the dictionary
        o - the Object to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        get(String)
      • setList

        void setList​(java.lang.String key,
                     java.util.List list)
              throws NotAllowedException,
                     BadValueException
        Sets a List value in the dictionary.

        key is associated with the value in the dictionary. If the key already exists in the dictionary then the old value is replaced by the new value, otherwise a new key/value pair is added to the dictionary.

        e.g.

        
         List<String> hostList = new ArrayList<String>();
         hostList.add("www.testplant.com");
         setList("hosts", hostList);
         
        Parameters:
        key - the key to associate with list in the dictionary
        list - the List to be associated with the key in the dictionary
        Throws:
        NotAllowedException - This dictionary is read only
        BadValueException - the key was null
        See Also:
        getList(String)
      • getList

        java.util.List getList​(java.lang.String key,
                               java.util.List defaultList)
                        throws BadValueException
        Returns a List value held in the dictionary, or the defaultList if the key cannot be found.

        Default data warning:
        When called from a VU script, if the defaultList is returned then a message is also written to the VU Event Log. This feature helps highlight problems with data bindings when data is expected to come from a data source, but the default value is returned instead.

        An example of the message entry in the Event Log:

        TypeIDInfo
        MessageDefault data warningNo value found for key: myList, using default value instead: List with first item: Item01

        To turn this feature off, go to the Test view in eggPlant Performance Studio and uncheck the option "Enable default data warnings" on the Data tab.

        Parameters:
        key - the key to be looked up in the dictionary
        defaultList - the value to return if the key is not present in the dictionary
        Returns:
        a List value held in the dictionary, or the defaultList if the key cannot be found
        Throws:
        BadValueException - the key was null
        See Also:
        setList(String, List)
      • isReadOnly

        boolean isReadOnly()
        Returns true if this dictionary is read-only.
        Returns:
        true if this dictionary is read-only
      • toString

        java.lang.String toString()
        Returns a String representation of the dictionary.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representing the key/value pairs in the dictionary
      • getName

        java.lang.String getName()
        Gets the name of this dictionary.
        Returns:
        the name of the Data Dictionary
      • setName

        void setName​(java.lang.String name)
        Sets the name of this dictionary.
        Parameters:
        name - the name of the Data Dictionary
      • hasKey

        boolean hasKey​(java.lang.String key)
        Returns true if the specified key is contained within the dictionary.

        e.g.

        
         if (myDictionary.HasKey("newHostName"))
         {
             // do something
         }
         else
         {
             // do something else
         }
         
        Parameters:
        key - the key to be looked up in the dictionary
        Returns:
        true if the dictionary contains the specified key