Search in sources :

Example 21 with ValidationErrors

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());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Test(org.junit.jupiter.api.Test)

Example 22 with ValidationErrors

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);
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) DataValidationError(com.enonic.xp.content.DataValidationError) Test(org.junit.jupiter.api.Test)

Example 23 with ValidationErrors

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);
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) DataValidationError(com.enonic.xp.content.DataValidationError) Test(org.junit.jupiter.api.Test)

Example 24 with ValidationErrors

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());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Test(org.junit.jupiter.api.Test)

Example 25 with ValidationErrors

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ApplicationKey(com.enonic.xp.app.ApplicationKey) ContentType(com.enonic.xp.schema.content.ContentType) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) ValidationErrors(com.enonic.xp.content.ValidationErrors) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationErrors (com.enonic.xp.content.ValidationErrors)51 Content (com.enonic.xp.content.Content)48 Test (org.junit.jupiter.api.Test)48 DataValidationError (com.enonic.xp.content.DataValidationError)21 ContentType (com.enonic.xp.schema.content.ContentType)10 FormOptionSet (com.enonic.xp.form.FormOptionSet)8 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)8 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)7 FormItemSet (com.enonic.xp.form.FormItemSet)5 PropertySet (com.enonic.xp.data.PropertySet)4 ApplicationKey (com.enonic.xp.app.ApplicationKey)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 ContentDataValidationException (com.enonic.xp.content.ContentDataValidationException)2 UpdateContentTranslatorParams (com.enonic.xp.content.UpdateContentTranslatorParams)2 FieldSet (com.enonic.xp.form.FieldSet)2 Input (com.enonic.xp.form.Input)2 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)2 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)2 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)2 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)2