use of com.enonic.xp.form.Form 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.Form 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.Form 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"));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testOptionSetItemsAreDefaulted.
@Test
public void testOptionSetItemsAreDefaulted() {
FormOptionSet.Builder myOptionSet = FormOptionSet.create().required(false).name("myOptionSet").occurrences(Occurrences.create(1, 1));
FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
option1.addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "default").build()).build()).build()).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());
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"));
assertEquals(0, data.getDouble("myOptionSet.option1.myDouble"));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class FormDefaultValuesProcessorImplTest method testOptionSetWithMinOccurrencesEqualZero.
@Test
public void testOptionSetWithMinOccurrencesEqualZero() {
FormOptionSet.Builder checkOptionSet = FormOptionSet.create().required(false).name("checkOptionSet").occurrences(Occurrences.create(0, 3));
FormOptionSetOption.Builder option = FormOptionSetOption.create().name("option_1");
checkOptionSet.addOptionSetOption(option.build());
final Form form = Form.create().addFormItem(checkOptionSet.build()).build();
final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
final PropertyTree data = new PropertyTree();
defaultValuesProcessor.setDefaultValues(form, data);
assertEquals(0, data.getTotalSize());
}
Aggregations