use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_required_input_with_no_data_when_validate_then_hasErrors_returns_true.
@Test
public void given_required_input_with_no_data_when_validate_then_hasErrors_returns_true() {
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);
assertTrue(validationResults.hasErrors());
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur1_and_maxOccur2_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur1_and_maxOccur2_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(1).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", null);
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method testOptionSetWithUnlimitedNumberAllowedSelectionsAndDefaultValues.
@Test
public void testOptionSetWithUnlimitedNumberAllowedSelectionsAndDefaultValues() {
ContentType contentType = ContentType.create().name("myapplication:my_type").superType(ContentTypeName.structured()).form(Form.create().addFormItem(FormOptionSet.create().name("options").label("Option tests").multiselection(Occurrences.create(0, 0)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("a").label("A").build()).addOptionSetOption(FormOptionSetOption.create().name("b").label("B").defaultOption(true).build()).build()).build()).build();
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setSet("options", 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 testOptionSetWithUnlimitedNumberAllowedSelections.
@Test
public void testOptionSetWithUnlimitedNumberAllowedSelections() {
Form form = Form.create().addFormItem(FormOptionSet.create().name("options").label("Option tests").multiselection(Occurrences.create(0, 0)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("a").label("A").build()).addOptionSetOption(FormOptionSetOption.create().name("b").label("B").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();
PropertySet propertySet = new PropertySet();
propertySet.setProperty("a", ValueFactory.newString("Value A"));
propertySet.setProperty("b", ValueFactory.newString("Value B"));
content.getData().setSet("options", 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_required_field_with_no_data_within_layout_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_field_with_no_data_within_layout_when_validate_then_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(FieldSet.create().label("My layout").name("myLayout").addFormItem(Input.create().name("myField").label("Field").inputType(InputTypeName.TEXT_LINE).required(true).build()).build());
Content content = Content.create().path(MY_CONTENT_PATH).build();
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class);
}
Aggregations