use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_required_input_with_data_when_validate_then_hasErrors_returns_false.
@Test
public void given_required_input_with_data_when_validate_then_hasErrors_returns_false() {
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();
content.getData().setString("myInput", "value");
// 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_maxOccur1_with_two_data_when_validate_then_MaximumOccurrencesValidationError.
@Test
public void given_input_with_maxOccur1_with_two_data_when_validate_then_MaximumOccurrencesValidationError() {
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]", "2");
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myInput", 1, 2);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur2_with_one_data_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur2_with_one_data_when_validate_then_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(2).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput", "value");
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myInput", 2, 1);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_required_set_with_data_when_validate_then_hasErrors_returns_false.
@Test()
public void given_required_set_with_data_when_validate_then_hasErrors_returns_false() {
contentType.getForm().getFormItems().add(FormItemSet.create().name("mySet").required(true).addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build()).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("mySet.myInput", "value");
// 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_required_set_with_no_data_and_other_set_with_data_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_set_with_no_data_and_other_set_with_data_when_validate_then_MinimumOccurrencesValidationError() {
// setup
contentType.getForm().getFormItems().add(Input.create().name("name").label("Input").inputType(InputTypeName.TEXT_LINE).build());
FormItemSet personalia = FormItemSet.create().name("personalia").multiple(false).required(true).build();
personalia.add(Input.create().name("eyeColour").label("Eye color").inputType(InputTypeName.TEXT_LINE).build());
personalia.add(Input.create().name("hairColour").label("Hair color").inputType(InputTypeName.TEXT_LINE).build());
contentType.getForm().getFormItems().add(personalia);
FormItemSet crimes = FormItemSet.create().name("crimes").multiple(true).build();
contentType.getForm().getFormItems().add(crimes);
crimes.add(Input.create().name("description").label("Description").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("name", "Thomas");
content.getData().setString("crimes[0].description", "Stole tomatoes from neighbour");
content.getData().setString("crimes[0].year", "1989");
content.getData().setString("crimes[1].description", "Stole a chocolate from the Matbua shop");
content.getData().setString("crimes[1].year", "1990");
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("personalia", 1, 0);
}
Aggregations