use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_required_optionset_with_no_data_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_optionset_with_no_data_when_validate_then_MinimumOccurrencesValidationError() {
FormOptionSet.Builder myOptionSet = FormOptionSet.create().occurrences(Occurrences.create(1, 0)).name("myOptionSet");
FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
option1.addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build());
myOptionSet.addOptionSetOption(option1.build());
contentType.getForm().getFormItems().add(myOptionSet.build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myOptionSet", 1, 0);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_required_input_with_no_data_within_layout_within_layout_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_input_with_no_data_within_layout_within_layout_when_validate_then_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(FieldSet.create().label("My outer layout").name("myOuterlayout").addFormItem(FieldSet.create().label("My Layout").name("myLayout").addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).required(true).build()).build()).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method testOptionSetWithDefaultValue.
@Test
public void testOptionSetWithDefaultValue() {
Form form = Form.create().addFormItem(FormOptionSet.create().name("checkOptionSet").label("Multi selection").expanded(true).helpText("Help Text").multiple(true).multiselection(Occurrences.create(1, 3)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("option_1").label("option_1").helpText("Help text for Option_1").build()).addOptionSetOption(FormOptionSetOption.create().name("option_2").label("option_2").helpText("Help text for Option_2").build()).addOptionSetOption(FormOptionSetOption.create().name("option_3").label("option_3").defaultOption(true).helpText("Help text for Option_3").addFormItem(Input.create().name("htmlAreaField").label("Input").inputType(InputTypeName.HTML_AREA).occurrences(Occurrences.create(2, 4)).build()).build()).build()).build();
ContentType contentType = ContentType.create().name("myapplication:my_type").superType(ContentTypeName.structured()).form(form).build();
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setSet("checkOptionSet.option_3", new PropertySet());
final ValidationErrors validationResults = validate(content);
assertFalse(validationResults.hasErrors());
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_maxOccur1_with_one_null_and_one_nonnull_value_when_validate_then_hasErrors_returns_false.
@Test
public void given_input_with_maxOccur1_with_one_null_and_one_nonnull_value_when_validate_then_hasErrors_returns_false() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).maximumOccurrences(1).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", "1");
content.getData().setString("myInput[1]", null);
// exercise
final ValidationErrors validationResults = validate(content);
assertFalse(validationResults.hasErrors());
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_optionset_with_required_selection_and_missing_selection_array_has_too_many_default_options.
@Test
public void given_optionset_with_required_selection_and_missing_selection_array_has_too_many_default_options() {
contentType.getForm().getFormItems().add(makeOptionSet("myOptionSet", 0, 2, 1, 1));
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myOptionSet.option1.myUnrequiredData", "1");
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myOptionSet", 1, 1, 2);
}
Aggregations