public void testGetSetProperties() throws Exception { PortletContext original = PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false); PropertyMap props = consumer.getProperties(original); checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE); PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original); props = consumer.getProperties(clone); checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE); consumer.setProperties( clone, new PropertyChange[] { PropertyChange.newUpdate( BasicPortletManagementBehavior.PROPERTY_NAME, BasicPortletManagementBehavior.PROPERTY_NEW_VALUE) }); checkProperties( consumer.getProperties(clone), BasicPortletManagementBehavior.PROPERTY_NEW_VALUE); consumer.setProperties( clone, new PropertyChange[] { PropertyChange.newReset(BasicPortletManagementBehavior.PROPERTY_NAME) }); checkProperties(consumer.getProperties(clone), BasicPortletManagementBehavior.PROPERTY_VALUE); }
public void testSetResetSameProperty() throws PortletInvokerException { PortletContext original = PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false); PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original); try { consumer.setProperties( clone, new PropertyChange[] { PropertyChange.newUpdate( BasicPortletManagementBehavior.PROPERTY_NAME, BasicPortletManagementBehavior.PROPERTY_NEW_VALUE), PropertyChange.newReset(BasicPortletManagementBehavior.PROPERTY_NAME) }); fail("Shouldn't be possible to set and reset the same property in the same call"); } catch (Exception e) { assertTrue( e.getCause() .getLocalizedMessage() .contains( BasicPortletManagementBehavior .CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME)); } }
private void savePreferences() throws Exception { UIFormInputSet uiPortletPrefSet = getChildById(FIELD_PORTLET_PREF); List<UIFormStringInput> uiFormInputs = new ArrayList<UIFormStringInput>(3); uiPortletPrefSet.findComponentOfType(uiFormInputs, UIFormStringInput.class); if (uiFormInputs.size() < 1) { return; } PropertyChange[] propertyChanges = new PropertyChange[uiFormInputs.size()]; for (int i = 0; i < uiFormInputs.size(); i++) { String name = uiFormInputs.get(i).getName(); String value = uiFormInputs.get(i).getValue(); propertyChanges[i] = PropertyChange.newUpdate(name, value); } // Now save it uiPortlet_.update(propertyChanges); }