use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ValidateContentDataCommandTest method test_empty_displayName.
@Test
public void test_empty_displayName() {
// setup
final FieldSet fieldSet = 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();
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:my_type").addFormItem(fieldSet).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
final Content content = Content.create().path("/mycontent").type(contentType.getName()).displayName("").build();
content.getData().setString("mySet.myInput", "thing");
// exercise
final ValidationErrors result = executeValidation(content.getData(), contentType.getName(), content.getName(), content.getDisplayName());
assertThat(result.stream()).hasSize(1);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ContentDataSerializerTest method update_validationErrors.
@Test
public void update_validationErrors() {
final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
final String binaryName = "myName";
final String binaryLabel = "myLabel";
final String binaryMimeType = "myMimeType";
final byte[] binaryData = "my binary".getBytes();
final ValidationErrors validationErrors = ValidationErrors.create().add(ValidationError.attachmentError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "SOME_CODE"), BinaryReference.from("myName")).message("someError").build()).add(ValidationError.dataError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "SOME_OTHER_CODE"), PropertyPath.from("")).message("someDataError").build()).add(ValidationError.generalError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "SERIOUS_ERROR")).message("someError").build()).build();
final UpdateContentTranslatorParams params = UpdateContentTranslatorParams.create().editedContent(Content.create().name("myContent").parentPath(ContentPath.ROOT).creator(PrincipalKey.ofAnonymous()).validationErrors(validationErrors).build()).modifier(PrincipalKey.ofAnonymous()).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(ByteSource.wrap(binaryData)).label(binaryLabel).mimeType(binaryMimeType).name(binaryName).build())).build();
final PropertyTree data = contentDataSerializer.toUpdateNodeData(params);
final Iterable<PropertySet> validationErrorsData = data.getSets("validationErrors");
assertThat(validationErrorsData).hasSize(3).extracting(propertySet -> propertySet.getString("errorCode")).containsExactly("system:SOME_CODE", "system:SOME_OTHER_CODE", "system:SERIOUS_ERROR");
assertThat(validationErrorsData).extracting(propertySet -> propertySet.getString("attachment")).containsExactly("myName", null, null);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_optionset_with_required_selection_and_empty_selection_array_fails_multiselection_check.
@Test
public void given_optionset_with_required_selection_and_empty_selection_array_fails_multiselection_check() {
contentType.getForm().getFormItems().add(makeOptionSet("myOptionSet", 0, 0, 1, 1));
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myOptionSet.option1.myUnrequiredData", "1");
content.getData().setString("myOptionSet._selected", "1");
content.getData().removeProperty("myOptionSet._selected");
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myOptionSet", 1, 1, 0);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_optionset_with_required_selection_and_missing_selection_array_has_too_little_default_options.
@Test
public void given_optionset_with_required_selection_and_missing_selection_array_has_too_little_default_options() {
contentType.getForm().getFormItems().add(makeOptionSet("myOptionSet", 2, 0, 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);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("myOptionSet", 1, 1, 0);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur1_with_two_null_values_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur1_with_two_null_values_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);
content.getData().setString("myInput[1]", null);
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
Aggregations