}
return result;
}
protected TestResult checkModifyReadOnlyPreferences(PortletRequest request) {
TestResult result = new TestResult();
result.setDescription("Ensure that setValue() / setValues() / reset() "
+ "methods throw ReadOnlyException when invoked "
+ "on read-only preferences.");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
if (!preferences.isReadOnly(READ_ONLY_PREF_NAME)) {
result.setReturnCode(TestResult.WARNING);
result.setResultMessage("Preference " + READ_ONLY_PREF_NAME
+ " is not a read-only preference. "
+ "This may be due to misconfiuration.");
return result;
}
boolean setValueOK = false;
boolean setValuesOK = false;
boolean resetOK = false;
// Check setValue() method.
try {
preferences.setValue(READ_ONLY_PREF_NAME, "written");
} catch (ReadOnlyException ex) {
setValueOK = true;
}
// Check setValues() method.
try {
preferences.setValues(READ_ONLY_PREF_NAME, new String[] { "written" });
} catch (ReadOnlyException ex) {
setValuesOK = true;
}
// Check reset() method.
try {
preferences.reset(READ_ONLY_PREF_NAME);
} catch (ReadOnlyException ex) {
resetOK = true;
}
if (setValueOK && setValuesOK && resetOK) {
result.setReturnCode(TestResult.PASSED);
} else {
result.setReturnCode(TestResult.FAILED);
StringBuffer buffer = new StringBuffer();
if (!setValueOK) {
buffer.append("setValue(..), ");
}
if (!setValuesOK) {
buffer.append("setValues(..), ");
}
if (!resetOK) {
buffer.append("reset(..), ");
}
result.setResultMessage("Method(s) [" + buffer.toString()
+ "] invoked on read-only preference (" + READ_ONLY_PREF_NAME
+ ") without ReadOnlyException.");
}
return result;
}