public final class TestPropertyValueProvider extends PropertyValueProvider
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 and Description |
---|
TestPropertyValueProvider() |
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.
|
notifyValueChanged
public static TestPropertyValueProvider getInstance(javax.faces.context.ExternalContext externalContext)
ConfigPropertyService
.public String getValue(javax.faces.context.ExternalContext extCtx, String name)
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.getValue
in class PropertyValueProvider
extCtx
- container context object.name
- name of the requested property.null
if the property was not found.public void setProperty(javax.faces.context.ExternalContext externalContext, String name, String value)
Any PropertyChangeListener reqiested with the ConfigPropertyService
will be notified of the value change when this method is called.
externalContext
- container context object.name
- name of the property.value
- value of the property.NullPointerException
- if the property name is null.public void removeProperty(javax.faces.context.ExternalContext externalContext, String name)
name
- name of the property.NullPointerException
- if the property name is null.public void resetValues()
setProperty
, returning them to their original values.Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.