Search in sources :

Example 31 with ValidationErrors

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

the class OccurrenceValidatorTest method given_required_input_with_data_when_validate_then_hasErrors_returns_false.

@Test
public void given_required_input_with_data_when_validate_then_hasErrors_returns_false() {
    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();
    content.getData().setString("myInput", "value");
    // 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 32 with ValidationErrors

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

the class OccurrenceValidatorTest method given_input_with_maxOccur1_with_two_data_when_validate_then_MaximumOccurrencesValidationError.

@Test
public void given_input_with_maxOccur1_with_two_data_when_validate_then_MaximumOccurrencesValidationError() {
    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]", "1");
    content.getData().setString("myInput[1]", "2");
    // exercise
    final ValidationErrors validationResults = validate(content);
    assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myInput", 1, 2);
}
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 33 with ValidationErrors

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

the class OccurrenceValidatorTest method given_input_with_minOccur2_with_one_data_when_validate_then_MinimumOccurrencesValidationError.

@Test
public void given_input_with_minOccur2_with_one_data_when_validate_then_MinimumOccurrencesValidationError() {
    contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(2).build());
    Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
    content.getData().setString("myInput", "value");
    // exercise
    final ValidationErrors validationResults = validate(content);
    assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myInput", 2, 1);
}
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 34 with ValidationErrors

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

the class OccurrenceValidatorTest method given_required_set_with_data_when_validate_then_hasErrors_returns_false.

@Test()
public void given_required_set_with_data_when_validate_then_hasErrors_returns_false() {
    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();
    content.getData().setString("mySet.myInput", "value");
    // 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 35 with ValidationErrors

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

the class OccurrenceValidatorTest method given_required_set_with_no_data_and_other_set_with_data_when_validate_then_MinimumOccurrencesValidationError.

@Test
public void given_required_set_with_no_data_and_other_set_with_data_when_validate_then_MinimumOccurrencesValidationError() {
    // setup
    contentType.getForm().getFormItems().add(Input.create().name("name").label("Input").inputType(InputTypeName.TEXT_LINE).build());
    FormItemSet personalia = FormItemSet.create().name("personalia").multiple(false).required(true).build();
    personalia.add(Input.create().name("eyeColour").label("Eye color").inputType(InputTypeName.TEXT_LINE).build());
    personalia.add(Input.create().name("hairColour").label("Hair color").inputType(InputTypeName.TEXT_LINE).build());
    contentType.getForm().getFormItems().add(personalia);
    FormItemSet crimes = FormItemSet.create().name("crimes").multiple(true).build();
    contentType.getForm().getFormItems().add(crimes);
    crimes.add(Input.create().name("description").label("Description").inputType(InputTypeName.TEXT_LINE).build());
    crimes.add(Input.create().name("year").label("Year").inputType(InputTypeName.TEXT_LINE).build());
    Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
    content.getData().setString("name", "Thomas");
    content.getData().setString("crimes[0].description", "Stole tomatoes from neighbour");
    content.getData().setString("crimes[0].year", "1989");
    content.getData().setString("crimes[1].description", "Stole a chocolate from the Matbua shop");
    content.getData().setString("crimes[1].year", "1990");
    // exercise
    final ValidationErrors validationResults = validate(content);
    assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("personalia", 1, 0);
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) FormItemSet(com.enonic.xp.form.FormItemSet) DataValidationError(com.enonic.xp.content.DataValidationError) 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