use of com.enonic.xp.content.ValidationErrors 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.ValidationErrors 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.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_optionset_with_required_selection_selection_array_hast_too_many_selected_options.
@Test
public void given_optionset_with_required_selection_selection_array_hast_too_many_selected_options() {
contentType.getForm().getFormItems().add(makeOptionSet("myOptionSet", 3, 0, 1, 2));
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");
content.getData().getSet("myOptionSet").addString("_selected", "option3");
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myOptionSet", 1, 2, 3);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_formoptionset_with_two_inputs_with_minOccur_with_data_when_validate_then_hasErrors_returns_false.
@Test
public void given_formoptionset_with_two_inputs_with_minOccur_with_data_when_validate_then_hasErrors_returns_false() {
FormOptionSet.Builder crimes = FormOptionSet.create().occurrences(Occurrences.create(1, 0)).name("crimes");
FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
option1.addFormItem(Input.create().name("description").label("Description").minimumOccurrences(1).inputType(InputTypeName.TEXT_LINE).build());
option1.addFormItem(Input.create().name("year").label("Year").minimumOccurrences(2).maximumOccurrences(0).inputType(InputTypeName.TEXT_LINE).build());
crimes.addOptionSetOption(option1.build());
contentType.getForm().getFormItems().add(crimes.build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("crimes[0].option1.description", "descr");
content.getData().setString("crimes[0].option1.year[0]", "1989");
content.getData().setString("crimes[0].option1.year[1]", "1990");
// exercise
final ValidationErrors validationResults = validate(content);
assertFalse(validationResults.hasErrors());
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ValidateContentDataCommandTest method testSiteConfigTextRegexpFailure.
@Test
public void testSiteConfigTextRegexpFailure() {
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
PropertyTree rootDataSet = new PropertyTree();
PropertyTree siteConfigDataSet = new PropertyTree();
siteConfigDataSet.setString("textInput-1", "test");
SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapp")).config(siteConfigDataSet).build();
new SiteConfigsDataSerializer().toProperties(SiteConfigs.from(siteConfig), rootDataSet.getRoot());
Mockito.when(siteService.getDescriptor(Mockito.isA(ApplicationKey.class))).thenReturn(createSiteDescriptor());
// exercise
final ValidationErrors result = executeValidation(rootDataSet, ContentTypeName.site());
assertThat(result.stream()).hasSize(1);
}
Aggregations