Search in sources :

Example 76 with Content

use of com.enonic.xp.content.Content 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 77 with Content

use of com.enonic.xp.content.Content 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 78 with Content

use of com.enonic.xp.content.Content 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 79 with Content

use of com.enonic.xp.content.Content 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 80 with Content

use of com.enonic.xp.content.Content 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)

Aggregations

Content (com.enonic.xp.content.Content)560 Test (org.junit.jupiter.api.Test)432 PropertyTree (com.enonic.xp.data.PropertyTree)130 CreateContentParams (com.enonic.xp.content.CreateContentParams)57 ContentId (com.enonic.xp.content.ContentId)50 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)48 ContentPath (com.enonic.xp.content.ContentPath)47 ValidationErrors (com.enonic.xp.content.ValidationErrors)47 Site (com.enonic.xp.site.Site)43 PropertySet (com.enonic.xp.data.PropertySet)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)27 Page (com.enonic.xp.page.Page)26 Contents (com.enonic.xp.content.Contents)25 Node (com.enonic.xp.node.Node)25 ContentIds (com.enonic.xp.content.ContentIds)24 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)24 ContentQuery (com.enonic.xp.content.ContentQuery)23 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)23 DataValidationError (com.enonic.xp.content.DataValidationError)21 ContentType (com.enonic.xp.schema.content.ContentType)20