Search in sources :

Example 6 with ValidationErrors

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

Example 7 with ValidationErrors

use of com.enonic.xp.content.ValidationErrors 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);
}
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 8 with ValidationErrors

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

Example 9 with ValidationErrors

use of com.enonic.xp.content.ValidationErrors in project xp by enonic.

the class OccurrenceValidatorTest method given_input_with_maxOccur1_with_three_null_data_when_validate_then_hasErrors_returns_false.

@Test
public void given_input_with_maxOccur1_with_three_null_data_when_validate_then_hasErrors_returns_false() {
    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]", null);
    content.getData().setString("myInput[1]", null);
    content.getData().setString("myInput[2]", null);
    // exercise
    final ValidationErrors validationResults = validate(content);
    assertFalse(validationResults.hasErrors());
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 10 with ValidationErrors

use of com.enonic.xp.content.ValidationErrors in project xp by enonic.

the class OccurrenceValidatorTest method given_input_with_minOccur1_with_two_nonnull_values_when_validate_then_hasErrors_returns_false.

@Test
public void given_input_with_minOccur1_with_two_nonnull_values_when_validate_then_hasErrors_returns_false() {
    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]", "1");
    content.getData().setString("myInput[1]", null);
    // exercise
    final ValidationErrors validationResults = validate(content);
    assertFalse(validationResults.hasErrors());
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) 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