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);
}
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());
}
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"));
}
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();
}
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);
}
Aggregations