use of com.enonic.xp.form.Form in project xp by enonic.
the class ImageContentProcessorTest method testProcessCreateWithExtraData.
@Test
public void testProcessCreateWithExtraData() throws IOException {
final Form.Builder form = Form.create();
form.addFormItem(createTextLine("shutterTime", "Exposure Time").occurrences(0, 1).build());
form.addFormItem(createTextLine("altitude", "Gps Altitude").occurrences(0, 1).build());
final XData xDataInfo = createXData(MediaInfo.IMAGE_INFO_METADATA_NAME, "Extra Info", form.build());
Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(xDataInfo));
final CreateContentParams params = createContentParams(createAttachments());
final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().addMetadata("exposure time", "1").addMetadata("gps altitude ", "2").build());
final ProcessCreateResult result = this.imageContentProcessor.processCreate(processCreateParams);
final ExtraData extraData = result.getCreateContentParams().getExtraDatas().first();
assertEquals(xDataInfo.getName(), extraData.getName());
assertEquals(extraData.getData().getString("shutterTime", 0), "1");
assertEquals(extraData.getData().getString("altitude", 0), "2");
assertEquals(13, extraData.getData().getLong(MediaInfo.MEDIA_INFO_BYTE_SIZE, 0));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class ImageContentProcessorTest method testProcessUpdateWithMediaInfo.
@Test
public void testProcessUpdateWithMediaInfo() throws IOException {
final Form.Builder form = Form.create();
form.addFormItem(createTextLine("shutterTime", "Exposure Time").occurrences(0, 1).build());
form.addFormItem(createTextLine("altitude", "Gps Altitude").occurrences(0, 1).build());
final XData xDataInfo = createXData(MediaInfo.IMAGE_INFO_METADATA_NAME, "Extra Info", form.build());
Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(xDataInfo));
final CreateAttachments createAttachments = createAttachments();
final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().superType(ContentTypeName.imageMedia()).name("myContent").build()).mediaInfo(MediaInfo.create().addMetadata("exposure time", "1").addMetadata("gps altitude ", "2").build()).createAttachments(createAttachments).build();
final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
final PropertyTree data = new PropertyTree();
final EditableContent editableContent = new EditableContent(Content.create().name("myContentName").parentPath(ContentPath.ROOT).data(data).build());
result.getEditor().edit(editableContent);
assertEquals(editableContent.extraDatas.first().getData().getString("shutterTime", 0), "1");
assertEquals(editableContent.extraDatas.first().getData().getString("altitude", 0), "2");
assertEquals(13, editableContent.extraDatas.first().getData().getLong(MediaInfo.MEDIA_INFO_BYTE_SIZE, 0));
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class InputValidationVisitorTest method validateInputTypeValid.
@Test
public void validateInputTypeValid() throws Exception {
Input myTextLine = Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").required(true).build();
Form form = Form.create().addFormItem(myTextLine).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setString("myTextLine", "33");
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
validationVisitor.traverse(form);
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class InputValidationVisitorTest method validateItemSetValid.
@Test
public void validateItemSetValid() throws Exception {
FormItemSet myFormItemSet = FormItemSet.create().name("myFormItemSet").label("My form item set").addFormItem(Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").required(false).build()).build();
Form form = Form.create().addFormItem(myFormItemSet).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setString("myFormItemSet.myTextLine", "33");
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
validationVisitor.traverse(form);
}
use of com.enonic.xp.form.Form in project xp by enonic.
the class InputValidationVisitorTest method validateItemSetInvalid.
@Test
public void validateItemSetInvalid() throws Exception {
FormItemSet myFormItemSet = FormItemSet.create().name("myFormItemSet").label("My form item set").addFormItem(Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").required(false).build()).build();
Form form = Form.create().addFormItem(myFormItemSet).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setLong("myFormItemSet.myTextLine", 33L);
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
assertThrows(InputTypeValidationException.class, () -> validationVisitor.traverse(form));
}
Aggregations