Search in sources :

Example 51 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XDataConfigProcessorTest method processForms.

private PatternIndexConfigDocument processForms(final Form... forms) {
    final XDatas.Builder xDatasBuilder = XDatas.create();
    for (int i = 0; i < forms.length; i++) {
        xDatasBuilder.add(XData.create().form(forms[i]).name(XDataName.from("appName:localName" + i)).build());
    }
    final XDatas xDatas = xDatasBuilder.build();
    final ContentType contentType = ContentType.create().superType(ContentTypeName.folder()).xData(XDataNames.from(xDatas.getNames())).name("contentType").build();
    Mockito.when(contentTypeService.getByName(new GetContentTypeParams().contentTypeName(contentTypeName))).thenReturn(contentType);
    Mockito.when(xDataService.getFromContentType(contentType)).thenReturn(xDatasBuilder.build());
    final XDataConfigProcessor configProcessor = new XDataConfigProcessor(xDatas);
    return configProcessor.processDocument(PatternIndexConfigDocument.create()).build();
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) XDatas(com.enonic.xp.schema.xdata.XDatas)

Example 52 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class OccurrenceValidatorTest method testOptionSetWithUnlimitedNumberAllowedSelections.

@Test
public void testOptionSetWithUnlimitedNumberAllowedSelections() {
    Form form = Form.create().addFormItem(FormOptionSet.create().name("options").label("Option tests").multiselection(Occurrences.create(0, 0)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("a").label("A").build()).addOptionSetOption(FormOptionSetOption.create().name("b").label("B").build()).build()).build();
    ContentType contentType = ContentType.create().name("myapplication:my_type").superType(ContentTypeName.structured()).form(form).build();
    Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
    PropertySet propertySet = new PropertySet();
    propertySet.setProperty("a", ValueFactory.newString("Value A"));
    propertySet.setProperty("b", ValueFactory.newString("Value B"));
    content.getData().setSet("options", propertySet);
    final ValidationErrors validationResults = validate(content);
    assertFalse(validationResults.hasErrors());
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 53 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class OccurrenceValidatorTest method testOptionSetWithUnlimitedNumberAllowedSelectionsAndDefaultValues.

@Test
public void testOptionSetWithUnlimitedNumberAllowedSelectionsAndDefaultValues() {
    ContentType contentType = ContentType.create().name("myapplication:my_type").superType(ContentTypeName.structured()).form(Form.create().addFormItem(FormOptionSet.create().name("options").label("Option tests").multiselection(Occurrences.create(0, 0)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("a").label("A").build()).addOptionSetOption(FormOptionSetOption.create().name("b").label("B").defaultOption(true).build()).build()).build()).build();
    Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
    content.getData().setSet("options", new PropertySet());
    final ValidationErrors validationResults = validate(content);
    assertFalse(validationResults.hasErrors());
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 54 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class InputValidatorTest method before.

@BeforeEach
public void before() {
    final ContentType contentType = createContentTypeForAllInputTypes(ContentTypeName.audioMedia());
    this.inputValidator = InputValidator.create().form(contentType.getForm()).inputTypeResolver(InputTypes.BUILTIN).build();
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 55 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class AbstractCommand method doTransformInlineMixins.

private ContentTypes doTransformInlineMixins(final ContentTypes contentTypes) {
    final ContentTypes.Builder transformedContentTypes = ContentTypes.create();
    for (final ContentType contentType : contentTypes) {
        final Form transformedForm = mixinService.inlineFormItems(contentType.getForm());
        final ContentType transformedCty = ContentType.create(contentType).form(transformedForm).build();
        transformedContentTypes.add(transformedCty);
    }
    return transformedContentTypes.build();
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) ContentTypes(com.enonic.xp.schema.content.ContentTypes)

Aggregations

ContentType (com.enonic.xp.schema.content.ContentType)56 Test (org.junit.jupiter.api.Test)35 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)28 Content (com.enonic.xp.content.Content)12 CreateContentParams (com.enonic.xp.content.CreateContentParams)10 ValidationErrors (com.enonic.xp.content.ValidationErrors)9 Form (com.enonic.xp.form.Form)8 PropertyTree (com.enonic.xp.data.PropertyTree)7 Input (com.enonic.xp.form.Input)7 FormItem (com.enonic.xp.form.FormItem)6 FieldSet (com.enonic.xp.form.FieldSet)5 FormItemSet (com.enonic.xp.form.FormItemSet)5 ContentTypes (com.enonic.xp.schema.content.ContentTypes)5 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)4 EditableSite (com.enonic.xp.content.EditableSite)3 PropertySet (com.enonic.xp.data.PropertySet)3 FormOptionSet (com.enonic.xp.form.FormOptionSet)3 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)3 XData (com.enonic.xp.schema.xdata.XData)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2