Search in sources :

Example 36 with ValidationErrors

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

Example 37 with ValidationErrors

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);
}
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 38 with ValidationErrors

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

Example 39 with ValidationErrors

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

Example 40 with ValidationErrors

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);
}
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