use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method data_for_input_is_not_required_if_parent_optionset_does_not_exist.
@Test
public void data_for_input_is_not_required_if_parent_optionset_does_not_exist() {
FormOptionSet.Builder myOptionSet = FormOptionSet.create().required(false).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();
content.getData().setString("myData", "1");
// 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 data_for_input_is_not_required_if_parent_data_set_does_not_exist.
@Test
public void data_for_input_is_not_required_if_parent_data_set_does_not_exist() {
Input myInput = Input.create().name("myRequiredInput").label("Input").inputType(InputTypeName.TEXT_LINE).required(true).build();
FormItemSet mySet = FormItemSet.create().name("mySet").required(false).addFormItem(myInput).build();
contentType.getForm().getFormItems().add(mySet);
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myData", "1");
// 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_input_with_minOccur3_with_two_data_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur3_with_two_data_when_validate_then_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(3).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", "value 1");
content.getData().setString("myInput[1]", "value 2");
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myInput", 3, 2);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_optionset_with_required_selection_selection_array_hast_too_few_selected_options.
@Test
public void given_optionset_with_required_selection_selection_array_hast_too_few_selected_options() {
contentType.getForm().getFormItems().add(makeOptionSet("myOptionSet", 3, 0, 3, 3));
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myOptionSet.option1.myUnrequiredData", "1");
content.getData().getSet("myOptionSet").addString("_selected", "option1");
content.getData().getSet("myOptionSet").addString("_selected", "option2");
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).get().extracting(ValidationError::getArgs, LIST).containsExactly("myOptionSet", 3, 3, 2);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_formitemset_with_input_with_minOccur1_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_formitemset_with_input_with_minOccur1_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError() {
FormItemSet crimes = FormItemSet.create().name("crimes").multiple(true).build();
contentType.getForm().getFormItems().add(crimes);
crimes.add(Input.create().name("description").label("Description").minimumOccurrences(1).inputType(InputTypeName.TEXT_LINE).build());
crimes.add(Input.create().name("year").label("Year").inputType(InputTypeName.TEXT_LINE).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("crimes[0].description", null);
content.getData().setString("crimes[0].year", "1989");
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
Aggregations