use of com.enonic.xp.content.Content in project xp by enonic.
the class OccurrenceValidatorTest method given_required_optionset_with_data_when_validate_then_hasErrors_returns_false.
@Test()
public void given_required_optionset_with_data_when_validate_then_hasErrors_returns_false() {
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();
content.getData().setString("myOptionSet.option1.myInput", "value");
// exercise
final ValidationErrors validationResults = validate(content);
assertFalse(validationResults.hasErrors());
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class OccurrenceValidatorTest method given_required_set_with_no_data_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_set_with_no_data_when_validate_then_MinimumOccurrencesValidationError() {
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();
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("mySet", 1, 0);
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class OccurrenceValidatorTest method given_optionset_with_default_selection_passes_multiselection_check.
@Test
public void given_optionset_with_default_selection_passes_multiselection_check() {
contentType.getForm().getFormItems().add(makeOptionSet("myOptionSet", 1, 1, 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);
assertFalse(validationResults.hasErrors());
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur1_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur1_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.Content in project xp by enonic.
the class OccurrenceValidatorTest method given_required_set_with_no_data_within_layout_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_set_with_no_data_within_layout_when_validate_then_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(FieldSet.create().label("My layout").name("myLayout").addFormItem(FormItemSet.create().name("mySet").required(true).addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).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);
}
Aggregations