use of com.enonic.xp.form.FormDefaultValuesProcessor in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testOptionSetIsNotDefaultedForUnselected.
@Test
public void testOptionSetIsNotDefaultedForUnselected() {
FormOptionSet.Builder myOptionSet = FormOptionSet.create().required(false).name("myOptionSet").occurrences(Occurrences.create(1, 1));
FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
FormOptionSetOption.Builder option2 = FormOptionSetOption.create().name("option2");
option1.addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "default").build()).build()).build());
option2.addFormItem(Input.create().name("myDouble").label("double").inputType(InputTypeName.DOUBLE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "0").build()).build()).build());
myOptionSet.addOptionSetOption(option1.build());
myOptionSet.addOptionSetOption(option2.build());
final Form form = Form.create().addFormItem(myOptionSet.build()).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals("default", data.getString("myOptionSet.option1.myInput"));
assertNull(data.getDouble("myOptionSet.option1.myDouble"));
}
use of com.enonic.xp.form.FormDefaultValuesProcessor in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method defaultValue_string_nonEmptyData.
@Test
public void defaultValue_string_nonEmptyData() {
Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "two").build()).build()).build();
final Form form = Form.create().addFormItem(input).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
data.setProperty(PropertyPath.from("testInput"), ValueFactory.newString("three"));
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals("three", data.getString("testInput"));
}
use of com.enonic.xp.form.FormDefaultValuesProcessor in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testDefaultValueForInputWithOccurrences.
@Test
public void testDefaultValueForInputWithOccurrences() {
Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).occurrences(Occurrences.create(3, 3)).build();
final Form form = Form.create().addFormItem(input).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
for (int i = 0; i < 3; i++) {
assertEquals("Default Value", data.getString("testInput", i));
}
}
use of com.enonic.xp.form.FormDefaultValuesProcessor in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testDefaultValueForInputAndItemSetWithOccurrences.
@Test
public void testDefaultValueForInputAndItemSetWithOccurrences() {
Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build();
FormItemSet formItemSet = FormItemSet.create().name("field").label("field").addFormItem(input).occurrences(Occurrences.create(3, 3)).build();
final Form form = Form.create().addFormItem(formItemSet).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
for (int i = 0; i < 3; i++) {
assertEquals("Default Value", data.getProperty("field", i).getSet().getString("testInput"));
}
}
use of com.enonic.xp.form.FormDefaultValuesProcessor in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testFieldSet.
@Test
public void testFieldSet() {
FieldSet.Builder fieldSet = FieldSet.create().name("fieldSet").label("FieldSet").addFormItem(InlineMixin.create().mixin("testApp:testMixin").build()).addFormItem(Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build()).addFormItem(Input.create().name("testInput2").label("testInput2").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value 2").build()).build()).build());
FormItemSet.Builder itemSet = FormItemSet.create().name("item-set").label("Item Set").occurrences(Occurrences.create(1, 1)).addFormItem(fieldSet.build());
final Form form = Form.create().addFormItem(itemSet.build()).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals("Default Value", data.getString("item-set.testInput"));
assertEquals("Default Value 2", data.getString("item-set.testInput2"));
}
Aggregations