protected TestResult checkStorePreferences(PortletRequest request) {
TestResult result = new TestResult();
result.setDescription("Ensure storage works for portlet preferences.");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
if (LOG.isDebugEnabled()) {
LOG.debug("Preferences to store: " + preferences);
}
boolean setOccured = false;
boolean storeOccured = false;
try {
// Set new value for preference "dummyName".
preferences.setValue(PREF_NAME, NEW_VALUE);
String value = preferences.getValue(PREF_NAME, DEF_VALUE);
if (NEW_VALUE.equals(value)) {
setOccured = true;
}
// Store the preference and get value.
preferences.store();
value = preferences.getValue(PREF_NAME, DEF_VALUE);
if (NEW_VALUE.equals(value)) {
storeOccured = true;
}
} catch (ReadOnlyException ex) {
TestUtils.failOnException("Unable to set preference value.", ex, result);
return result;
} catch (ValidatorException ex) {
TestUtils.failOnException("Unable to store preference value.", ex, result);
return result;
} catch(IOException ex) {
TestUtils.failOnException("Unable to store preference value.", ex, result);
return result;
} finally {
// Reset preference to default value, and store!
try {
preferences.reset(PREF_NAME);
preferences.store();
} catch (Exception ex) {
TestUtils.failOnException("Unable to set preference value.", ex, result);
return result;
}
}