Search in sources :

Example 1 with GetContentTypeParams

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

the class ContentTypeHandler method getContentType.

public ContentTypeMapper getContentType() {
    if (name == null || name.isBlank()) {
        return null;
    }
    final GetContentTypeParams params = GetContentTypeParams.from(ContentTypeName.from(name));
    final ContentType ctype = contentTypeService.get().getByName(params);
    return ctype == null ? null : new ContentTypeMapper(inlineMixins(ctype));
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) ContentTypeMapper(com.enonic.xp.lib.content.mapper.ContentTypeMapper)

Example 2 with GetContentTypeParams

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

the class CreateContentHandlerTest method createContentAutoGenerateNameWithExistingName.

@Test
public void createContentAutoGenerateNameWithExistingName() throws Exception {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content")))).thenReturn(true);
    when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-1")))).thenReturn(true);
    when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-2")))).thenReturn(true);
    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", "createContentAutoGenerateNameWithExistingName");
}
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 3 with GetContentTypeParams

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

the class CreateContentHandlerTest method createContentAutoGenerateName.

@Test
public void createContentAutoGenerateName() 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", "createContentAutoGenerateName");
}
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 4 with GetContentTypeParams

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

the class ContentTypeHandlerTest method testGet.

@Test
public void testGet() throws Exception {
    final Form form = getForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentType contentType = testContentType();
    final GetContentTypeParams params = new GetContentTypeParams().contentTypeName(contentType.getName());
    Mockito.when(contentTypeService.getByName(params)).thenReturn(contentType);
    runFunction("/test/ContentTypeHandlerTest.js", "testGet");
}
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 5 with GetContentTypeParams

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

the class ModifyContentHandlerTest method testExample.

@Test
public void testExample() {
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.unstructured());
    when(this.contentTypeService.getByName(getContentType)).thenReturn(ContentType.create().name(ContentTypeName.unstructured()).setBuiltIn().build());
    final Content content = TestDataFixtures.newExampleContent();
    when(this.contentService.getByPath(Mockito.any())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], content));
    mockXData();
    runScript("/lib/xp/examples/content/modify.js");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

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