Search in sources :

Example 6 with FieldSet

use of com.enonic.xp.form.FieldSet in project xp by enonic.

the class ValidateContentDataCommandTest method test_unnamed.

@Test
public void test_unnamed() {
    // 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()).name(ContentName.unnamed()).displayName("display-name").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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) FieldSet(com.enonic.xp.form.FieldSet) ContentType(com.enonic.xp.schema.content.ContentType) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 7 with FieldSet

use of com.enonic.xp.form.FieldSet in project xp by enonic.

the class ValidateContentDataCommandTest method validation_no_errors.

@Test
public void validation_no_errors() {
    // 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()).build();
    content.getData().setString("mySet.myInput", "thing");
    // exercise
    final ValidationErrors result = executeValidation(content.getData(), contentType.getName());
    assertFalse(result.hasErrors());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) FieldSet(com.enonic.xp.form.FieldSet) ContentType(com.enonic.xp.schema.content.ContentType) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 8 with FieldSet

use of com.enonic.xp.form.FieldSet in project xp by enonic.

the class FormDefaultValuesProcessorImplTest method testFieldSet.

@Test
public void testFieldSet() {
    FieldSet.Builder fieldSet = FieldSet.create().name("fieldSet").label("FieldSet").addFormItem(InlineMixin.create().mixin("testApp:testMixin").build()).addFormItem(Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build()).addFormItem(Input.create().name("testInput2").label("testInput2").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value 2").build()).build()).build());
    FormItemSet.Builder itemSet = FormItemSet.create().name("item-set").label("Item Set").occurrences(Occurrences.create(1, 1)).addFormItem(fieldSet.build());
    final Form form = Form.create().addFormItem(itemSet.build()).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    assertEquals("Default Value", data.getString("item-set.testInput"));
    assertEquals("Default Value 2", data.getString("item-set.testInput2"));
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 9 with FieldSet

use of com.enonic.xp.form.FieldSet in project xp by enonic.

the class FormJsonToPropertyTreeTranslatorTest method createFormForFieldSet.

private Form createFormForFieldSet() {
    final FieldSet fieldSet1 = FieldSet.create().name("properties").label("Properties").addFormItem(Input.create().name("number").label("Number").inputType(InputTypeName.LONG).build()).build();
    final FormItemSet itemSet = FormItemSet.create().name("attributes").occurrences(0, 0).addFormItem(Input.create().name("key").label("Key").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(fieldSet1).build();
    final FieldSet fieldSet = FieldSet.create().name("attributes").label("Attributes").addFormItem(itemSet).build();
    return Form.create().addFormItem(fieldSet).build();
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 10 with FieldSet

use of com.enonic.xp.form.FieldSet 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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) FieldSet(com.enonic.xp.form.FieldSet) ContentType(com.enonic.xp.schema.content.ContentType) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

FieldSet (com.enonic.xp.form.FieldSet)14 Test (org.junit.jupiter.api.Test)9 FormItemSet (com.enonic.xp.form.FormItemSet)7 ContentType (com.enonic.xp.schema.content.ContentType)5 FormItem (com.enonic.xp.form.FormItem)4 FormOptionSet (com.enonic.xp.form.FormOptionSet)4 Input (com.enonic.xp.form.Input)4 Content (com.enonic.xp.content.Content)3 ValidationErrors (com.enonic.xp.content.ValidationErrors)3 Form (com.enonic.xp.form.Form)3 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)3 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)3 PropertySet (com.enonic.xp.data.PropertySet)2 Property (com.enonic.xp.data.Property)1 PropertyPath (com.enonic.xp.data.PropertyPath)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Value (com.enonic.xp.data.Value)1 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)1 InlineMixin (com.enonic.xp.form.InlineMixin)1 InputTypeProperty (com.enonic.xp.inputtype.InputTypeProperty)1