use of com.enonic.xp.content.DataValidationError 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);
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_required_input_at_top_and_inside_formItemSet_and_formItemSet_have_other_unrequired_data_when_validate_then_two_errors_are_found.
@Test
public void given_required_input_at_top_and_inside_formItemSet_and_formItemSet_have_other_unrequired_data_when_validate_then_two_errors_are_found() {
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);
contentType.getForm().getFormItems().add(Input.create().name("myOtherRequiredInput").label("Other input").inputType(InputTypeName.TEXT_LINE).required(true).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("mySet.myUnrequiredData", "1");
assertEquals("mySet.myRequiredInput", mySet.getInput("myRequiredInput").getPath().toString());
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream()).hasSize(2).allMatch(ve -> ve instanceof DataValidationError).extracting(ValidationError::getArgs).containsExactly(Arrays.array(List.of("mySet.myRequiredInput", 1, 0), List.of("myOtherRequiredInput", 1, 0)));
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_required_optionset_with_no_data_within_layout_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_optionset_with_no_data_within_layout_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(FieldSet.create().label("My layout").name("myLayout").addFormItem(myOptionSet.build()).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_required_input_with_no_data_when_validate_then_validation_error_propertyPath_correct.
@Test
public void given_required_input_with_no_data_when_validate_then_validation_error_propertyPath_correct() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).required(true).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).get(as(type(DataValidationError.class))).extracting(DataValidationError::getPropertyPath).asString().isEqualTo("myInput");
}
Aggregations