Search in sources :

Example 21 with GetContentTypeParams

use of com.enonic.xp.schema.content.GetContentTypeParams 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 22 with GetContentTypeParams

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

the class ModifyContentHandlerTest method mockXData.

private void mockXData() {
    final FormItemSet cSet = FormItemSet.create().name("c").occurrences(0, 10).addFormItem(Input.create().label("d").name("d").inputType(InputTypeName.CHECK_BOX).build()).addFormItem(Input.create().label("e").name("e").occurrences(0, 0).inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().label("f").name("f").inputType(InputTypeName.LONG).build()).build();
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(cSet).addFormItem(Input.create().label("z").name("z").occurrences(0, 10).inputType(InputTypeName.TEXT_LINE).build()).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(eq(getContentType))).thenReturn(contentType);
    final XData xData1 = XData.create().name(XDataName.from("com.enonic.myapplication:myschema")).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).build();
    when(this.xDataService.getByName(eq(xData1.getName()))).thenReturn(xData1);
    final XData xData2 = XData.create().name(XDataName.from("com.enonic.myapplication:other")).addFormItem(Input.create().label("name").name("name").inputType(InputTypeName.TEXT_LINE).build()).build();
    when(this.xDataService.getByName(eq(xData1.getName()))).thenReturn(xData1);
    when(this.xDataService.getByName(eq(xData2.getName()))).thenReturn(xData2);
    when(this.mixinService.inlineFormItems(any(Form.class))).then(returnsFirstArg());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) XData(com.enonic.xp.schema.xdata.XData) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 23 with GetContentTypeParams

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

the class ContentTypeHandlerTest method testExampleGetType.

@Test
public void testExampleGetType() {
    final Form form = getExampleForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentType contentType = exampleContentType();
    final GetContentTypeParams params = new GetContentTypeParams().contentTypeName(contentType.getName());
    Mockito.when(contentTypeService.getByName(params)).thenReturn(contentType);
    runScript("/lib/xp/examples/content/getType.js");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 24 with GetContentTypeParams

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

the class CreateContentHandlerTest method createContentWithWorkflow.

@Test
public void createContentWithWorkflow() throws Exception {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
    runFunction("/test/CreateContentHandlerTest.js", "createContentWithWorkflow");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentParams(com.enonic.xp.content.CreateContentParams) Test(org.junit.jupiter.api.Test)

Example 25 with GetContentTypeParams

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

the class CreateContentHandlerTest method mockCreateContent.

private void mockCreateContent() {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    final FormItemSet eSet = FormItemSet.create().name("e").addFormItem(Input.create().label("f").name("f").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("g").name("g").inputType(InputTypeName.CHECK_BOX).build()).build();
    final FormItemSet dSet = FormItemSet.create().name("d").addFormItem(eSet).build();
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("c").name("c").occurrences(0, 10).inputType(InputTypeName.TEXT_LINE).build()).addFormItem(dSet).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
    final PropertyTree extraData = new PropertyTree();
    extraData.addDouble("a", 1.0);
    extraData.addBoolean("b", true);
    final XData xData = XData.create().name(XDataName.from("com.enonic.myapplication:myschema")).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build();
    final SiteDescriptor siteDescriptor1 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build()).build();
    final SiteDescriptor siteDescriptor2 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("c").name("c").inputType(InputTypeName.LONG).build()).build()).build();
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey1"))).thenReturn(siteDescriptor1);
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey2"))).thenReturn(siteDescriptor2);
    when(this.xDataService.getByName(Mockito.eq(XDataName.from("com.enonic.myapplication:myschema")))).thenReturn(xData);
    when(this.mixinService.inlineFormItems(any(Form.class))).then(returnsFirstArg());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) FormItemSet(com.enonic.xp.form.FormItemSet)

Aggregations

GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)26 ContentType (com.enonic.xp.schema.content.ContentType)18 Test (org.junit.jupiter.api.Test)17 CreateContentParams (com.enonic.xp.content.CreateContentParams)12 PropertyTree (com.enonic.xp.data.PropertyTree)8 Content (com.enonic.xp.content.Content)4 Form (com.enonic.xp.form.Form)4 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)3 ContentTypes (com.enonic.xp.schema.content.ContentTypes)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 FormItemSet (com.enonic.xp.form.FormItemSet)2 Node (com.enonic.xp.node.Node)2 NodePath (com.enonic.xp.node.NodePath)2 XData (com.enonic.xp.schema.xdata.XData)2 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 ContentValidator (com.enonic.xp.content.ContentValidator)1 ContentValidatorParams (com.enonic.xp.content.ContentValidatorParams)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 EditableContent (com.enonic.xp.content.EditableContent)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1