prefs = (PreferenceSetComposite) entity.getPreferenceSet();
assertNotNull(prefs.get("pref1"));
PreferenceComposite pref = (PreferenceComposite) prefs.get("pref1");
assertEquals("1", pref.getValueAt(0));
pref.setValueAt(0, "2");
assertEquals("2", pref.getValueAt(0));
prefs.add("pref2", Arrays.asList(new String[]
{ "2", "3" }));
entity.store();
PreferenceComposite pref2 = (PreferenceComposite) prefs.get("pref2");
assertNotNull(pref2);
Iterator prefsValues = pref2.getValues();
int count = 0;
while (prefsValues.hasNext())
{
prefsValues.next();
count++;
}
assertEquals(2, count);
pref2.addValue("4");
prefsValues = pref2.getValues();
count = 0;
while (prefsValues.hasNext())
{
assertEquals(String.valueOf(count + 2), prefsValues.next());
count++;
}
assertEquals(3, count);
// testing preferences null values assignments fix, issue JS2-607
pref2.setValueAt(0, null);
assertNull("pref2.value[0] should be null", pref2.getValueAt(0));
String[] values = pref2.getValueArray();
assertEquals(3, values.length);
assertNull("pref2.value[0] should be null", values[0]);
assertEquals("3", values[1]);
pref2.setValues(new String[]{"2",null,"3"});
assertNull("pref2.value[1] should be null", pref2.getValueAt(1));
values = pref2.getValueArray();
assertEquals(3, values.length);
assertEquals("2", values[0]);
assertNull("pref2.value[1] should be null", values[1]);
assertEquals("3", values[2]);
assertTrue(pref2.isValueSet());
pref2.setValues((String[])null);
assertFalse(pref2.isValueSet());
assertTrue(pref2.getValueArray().length == 0);
pref2.setValues(new String[]{});
assertFalse(pref2.isValueSet());
assertTrue(pref2.getValueArray().length == 0);
MutablePortletEntity entity2 = entityAccess.getPortletEntityForFragment(f1);
assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
assertNotNull("entity's portlet ", entity2.getPortletDefinition());
mockf1.verify();