org.apache.myfaces.trinidad.config

## Class TestPropertyValueProvider

- java.lang.Object
- - org.apache.myfaces.trinidad.config.PropertyValueProvider
  - - org.apache.myfaces.trinidad.config.TestPropertyValueProvider

-     public final class TestPropertyValueProvider
      extends PropertyValueProvider

  A `PropertyValueProvider` that allows runtime modification of property values to support unit testing code. By using this class a unit test can exercise a piece of code with a number of different property values without needing to change property values in their underlaying source.

  This class maintains an in-memory collection of property values supplied by calling the `setProperty` method. When a value is requested by the `ConfigPropertyService` the in-memory collection of values are consulted first. If a value has been supplied that will be returned, otherwise the property value will be fetched from the configured property value provider.

  When this class is used it will coordinate with the `ConfigPropertyService` to ensure values are obained from this class.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TestPropertyValueProvider()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static TestPropertyValueProvider` | `getInstance(javax.faces.context.ExternalContext externalContext)` Obtain a reference to the test value provider.
    `String` | `getValue(javax.faces.context.ExternalContext extCtx, String name)` Used by the `ConfigPropertyService` to obtain a property value.
    `void` | `removeProperty(javax.faces.context.ExternalContext externalContext, String name)` Remove a property value from the test value provider.
    `void` | `resetValues()` Removes all in-memory property values specified by calling `setProperty`, returning them to their original values.
    `void` | `setProperty(javax.faces.context.ExternalContext externalContext, String name, String value)` Set the value of a property.

    - ### Methods inherited from class org.apache.myfaces.trinidad.config.PropertyValueProvider

      `notifyValueChanged`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TestPropertyValueProvider

          public TestPropertyValueProvider()

  - ### Method Detail

    - #### getInstance

          public static TestPropertyValueProvider getInstance(javax.faces.context.ExternalContext externalContext)

      Obtain a reference to the test value provider. Calling this method will also result in the test property value provider being installed with the `ConfigPropertyService`.
      Returns:
        a test value provider.

    - #### getValue

          public String getValue(javax.faces.context.ExternalContext extCtx,
                        String name)

      Used by the `ConfigPropertyService` to obtain a property value. If a value has been specified by calling the `setProperty` method that value will be returned, otherwise the request will be delegated to the configured property value provider.
      Specified by:
        `getValue` in class `PropertyValueProvider`
      Parameters:
        `extCtx` - container context object.
        `name` - name of the requested property.
      Returns:
        the value of the property or `null` if the property was not found.

    - #### setProperty

          public void setProperty(javax.faces.context.ExternalContext externalContext,
                         String name,
                         String value)

      Set the value of a property. Calling this method only updates the in-memory value used for test purposes. The value is not propagated to any underlying storage.

      Any PropertyChangeListener reqiested with the `ConfigPropertyService` will be notified of the value change when this method is called.

      Parameters:
        `externalContext` - container context object.
        `name` - name of the property.
        `value` - value of the property.
      Throws:
        `NullPointerException` - if the property name is null.

    - #### removeProperty

          public void removeProperty(javax.faces.context.ExternalContext externalContext,
                            String name)

      Remove a property value from the test value provider.
      Parameters:
        `name` - name of the property.
      Throws:
        `NullPointerException` - if the property name is null.

    - #### resetValues

          public void resetValues()

      Removes all in-memory property values specified by calling `setProperty`, returning them to their original values.

Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.