Search in sources :

Example 46 with Form

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));
}
Also used : Form(com.enonic.xp.form.Form) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 47 with Form

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));
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Form(com.enonic.xp.form.Form) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) XData(com.enonic.xp.schema.xdata.XData) Test(org.junit.jupiter.api.Test)

Example 48 with Form

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);
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 49 with 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);
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 50 with 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));
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Aggregations

Form (com.enonic.xp.form.Form)79 Test (org.junit.jupiter.api.Test)59 PropertyTree (com.enonic.xp.data.PropertyTree)36 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)17 Input (com.enonic.xp.form.Input)17 FormItemSet (com.enonic.xp.form.FormItemSet)13 FormOptionSet (com.enonic.xp.form.FormOptionSet)11 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)10 ContentType (com.enonic.xp.schema.content.ContentType)8 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)7 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)5 PropertySet (com.enonic.xp.data.PropertySet)5 Content (com.enonic.xp.content.Content)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 EditableContent (com.enonic.xp.content.EditableContent)4 MacroKey (com.enonic.xp.macro.MacroKey)4 XData (com.enonic.xp.schema.xdata.XData)4 SiteConfigs (com.enonic.xp.site.SiteConfigs)4 ContentPath (com.enonic.xp.content.ContentPath)3 Page (com.enonic.xp.page.Page)3