Search in sources :

Example 66 with Form

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

the class AbstractContentSynchronizerTest method setUpContentService.

private void setUpContentService() {
    final Map<String, List<String>> metadata = new HashMap<>();
    metadata.put(HttpHeaders.CONTENT_TYPE, List.of("image/jpg"));
    final ExtractedData extractedData = ExtractedData.create().metadata(metadata).build();
    final BinaryExtractor extractor = mock(BinaryExtractor.class);
    when(extractor.extract(isA(ByteSource.class))).thenReturn(extractedData);
    mediaInfoService = new MediaInfoServiceImpl();
    mediaInfoService.setBinaryExtractor(extractor);
    XDataService xDataService = mock(XDataService.class);
    MixinService mixinService = mock(MixinService.class);
    when(mixinService.inlineFormItems(isA(Form.class))).then(AdditionalAnswers.returnsFirstArg());
    pageDescriptorService = mock(PageDescriptorService.class);
    partDescriptorService = mock(PartDescriptorService.class);
    layoutDescriptorService = mock(LayoutDescriptorService.class);
    contentTypeService = new ContentTypeServiceImpl(null, null, mixinService);
    final ResourceService resourceService = mock(ResourceService.class);
    final SiteServiceImpl siteService = new SiteServiceImpl();
    siteService.setResourceService(resourceService);
    siteService.setMixinService(mixinService);
    final AuditLogService auditLogService = mock(AuditLogService.class);
    final ContentConfig contentConfig = mock(ContentConfig.class);
    final ContentAuditLogSupportImpl contentAuditLogSupport = new ContentAuditLogSupportImpl(contentConfig, new ContentAuditLogExecutorImpl(), auditLogService);
    contentService = new ContentServiceImpl(nodeService, pageDescriptorService, partDescriptorService, layoutDescriptorService);
    contentService.setEventPublisher(eventPublisher);
    contentService.setMediaInfoService(mediaInfoService);
    contentService.setSiteService(siteService);
    contentService.setContentTypeService(contentTypeService);
    contentService.setxDataService(xDataService);
    contentService.setFormDefaultValuesProcessor((form, data) -> {
    });
    contentService.setContentAuditLogSupport(contentAuditLogSupport);
    contentService.initialize(mock(ContentConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) IdProviderKey(com.enonic.xp.security.IdProviderKey) TaskServiceImpl(com.enonic.xp.impl.task.TaskServiceImpl) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) HttpHeaders(com.google.common.net.HttpHeaders) ContextAccessor(com.enonic.xp.context.ContextAccessor) Map(java.util.Map) ContextBuilder(com.enonic.xp.context.ContextBuilder) Bundle(org.osgi.framework.Bundle) SystemConstants(com.enonic.xp.security.SystemConstants) EnumSet(java.util.EnumSet) ProjectPermissionsContextManagerImpl(com.enonic.xp.core.impl.project.ProjectPermissionsContextManagerImpl) Media(com.enonic.xp.content.Media) User(com.enonic.xp.security.User) ContentServiceImpl(com.enonic.xp.core.impl.content.ContentServiceImpl) TaskManagerCleanupScheduler(com.enonic.xp.impl.task.TaskManagerCleanupScheduler) Project(com.enonic.xp.project.Project) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) AdditionalAnswers(org.mockito.AdditionalAnswers) BinaryExtractor(com.enonic.xp.extractor.BinaryExtractor) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteStreams(com.google.common.io.ByteStreams) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) ProjectServiceImpl(com.enonic.xp.core.impl.project.ProjectServiceImpl) MixinService(com.enonic.xp.schema.mixin.MixinService) ContentAuditLogExecutorImpl(com.enonic.xp.core.impl.content.ContentAuditLogExecutorImpl) ContentAuditLogSupportImpl(com.enonic.xp.core.impl.content.ContentAuditLogSupportImpl) SiteServiceImpl(com.enonic.xp.core.impl.site.SiteServiceImpl) Mockito.mock(org.mockito.Mockito.mock) CreateContentParams(com.enonic.xp.content.CreateContentParams) SecurityServiceImpl(com.enonic.xp.core.impl.security.SecurityServiceImpl) ContentConstants(com.enonic.xp.content.ContentConstants) RecurringJob(com.enonic.xp.core.internal.concurrent.RecurringJob) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) MediaInfoServiceImpl(com.enonic.xp.core.impl.media.MediaInfoServiceImpl) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ContentTypeServiceImpl(com.enonic.xp.core.impl.schema.content.ContentTypeServiceImpl) ProjectName(com.enonic.xp.project.ProjectName) AuditLogService(com.enonic.xp.audit.AuditLogService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) XDataService(com.enonic.xp.schema.xdata.XDataService) OsgiSupportMock(com.enonic.xp.core.internal.osgi.OsgiSupportMock) PropertyTree(com.enonic.xp.data.PropertyTree) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) ResourceService(com.enonic.xp.resource.ResourceService) ContentPath(com.enonic.xp.content.ContentPath) ContentInheritType(com.enonic.xp.content.ContentInheritType) NodePath(com.enonic.xp.node.NodePath) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) LocalTaskManagerImpl(com.enonic.xp.impl.task.LocalTaskManagerImpl) Mockito.when(org.mockito.Mockito.when) Form(com.enonic.xp.form.Form) ExtractedData(com.enonic.xp.extractor.ExtractedData) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) CreateMediaParams(com.enonic.xp.content.CreateMediaParams) NamedTaskFactory(com.enonic.xp.impl.task.script.NamedTaskFactory) InputStream(java.io.InputStream) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) AuditLogService(com.enonic.xp.audit.AuditLogService) MediaInfoServiceImpl(com.enonic.xp.core.impl.media.MediaInfoServiceImpl) ContentAuditLogExecutorImpl(com.enonic.xp.core.impl.content.ContentAuditLogExecutorImpl) HashMap(java.util.HashMap) Form(com.enonic.xp.form.Form) ContentTypeServiceImpl(com.enonic.xp.core.impl.schema.content.ContentTypeServiceImpl) XDataService(com.enonic.xp.schema.xdata.XDataService) ResourceService(com.enonic.xp.resource.ResourceService) SiteServiceImpl(com.enonic.xp.core.impl.site.SiteServiceImpl) MixinService(com.enonic.xp.schema.mixin.MixinService) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) BinaryExtractor(com.enonic.xp.extractor.BinaryExtractor) ExtractedData(com.enonic.xp.extractor.ExtractedData) ContentAuditLogSupportImpl(com.enonic.xp.core.impl.content.ContentAuditLogSupportImpl) ContentServiceImpl(com.enonic.xp.core.impl.content.ContentServiceImpl) ByteSource(com.google.common.io.ByteSource) List(java.util.List)

Example 67 with Form

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

the class DescriptorsTest method partDescriptor.

@Test
public void partDescriptor() {
    final Form partForm = Form.create().addFormItem(Input.create().name("width").label("width").inputType(InputTypeName.DOUBLE).build()).build();
    final PartDescriptor partDescriptor = PartDescriptor.create().displayName("News part").config(partForm).key(DescriptorKey.from("module:new-part")).build();
    final PartDescriptor copy = PartDescriptor.copyOf(partDescriptor).build();
    assertEquals("News part", partDescriptor.getDisplayName());
    assertEquals(partDescriptor.getComponentPath(), copy.getComponentPath());
}
Also used : Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) Test(org.junit.jupiter.api.Test)

Example 68 with Form

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

the class DescriptorsTest method layoutDescriptor.

@Test
public void layoutDescriptor() {
    final Form layoutForm = Form.create().addFormItem(Input.create().name("columns").label("columns").inputType(InputTypeName.DOUBLE).build()).build();
    final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("Fancy layout").config(layoutForm).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:fancy-layout")).build();
    final LayoutDescriptor copy = LayoutDescriptor.copyOf(layoutDescriptor).build();
    assertEquals("Fancy layout", layoutDescriptor.getDisplayName());
    assertEquals(layoutForm, layoutDescriptor.getConfig());
    assertEquals(layoutDescriptor.getComponentPath(), copy.getComponentPath());
    assertEquals(layoutDescriptor.getRegions(), copy.getRegions());
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 69 with Form

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

the class DescriptorsTest method pageDescriptor.

@Test
public void pageDescriptor() {
    final Form pageForm = Form.create().addFormItem(Input.create().name("pause").label("pause").inputType(InputTypeName.DOUBLE).build()).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().displayName("Landing page").config(pageForm).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:landing-page")).build();
    assertEquals("Landing page", pageDescriptor.getDisplayName());
    assertEquals("landing-page", pageDescriptor.getName());
}
Also used : Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 70 with Form

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

the class PageDescriptorsTest method from.

@Test
public void from() {
    final Form pageForm = Form.create().addFormItem(Input.create().name("pause").label("pause").inputType(InputTypeName.DOUBLE).build()).build();
    final PageDescriptor pageDescriptor1 = PageDescriptor.create().displayName("Landing page").config(pageForm).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:landing-page")).build();
    final PageDescriptor pageDescriptor2 = PageDescriptor.create().displayName("Log out").config(pageForm).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:logout-page")).build();
    final PageDescriptor pageDescriptor3 = PageDescriptor.copyOf(pageDescriptor1).build();
    assertEquals(3, PageDescriptors.from(pageDescriptor1, pageDescriptor2, pageDescriptor3).getSize());
    assertEquals(3, PageDescriptors.from(Arrays.asList(pageDescriptor1, pageDescriptor2, pageDescriptor3)).getSize());
}
Also used : Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Aggregations

Form (com.enonic.xp.form.Form)79 Test (org.junit.jupiter.api.Test)59 PropertyTree (com.enonic.xp.data.PropertyTree)36 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)17 Input (com.enonic.xp.form.Input)17 FormItemSet (com.enonic.xp.form.FormItemSet)13 FormOptionSet (com.enonic.xp.form.FormOptionSet)11 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)10 ContentType (com.enonic.xp.schema.content.ContentType)8 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)7 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)5 PropertySet (com.enonic.xp.data.PropertySet)5 Content (com.enonic.xp.content.Content)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 EditableContent (com.enonic.xp.content.EditableContent)4 MacroKey (com.enonic.xp.macro.MacroKey)4 XData (com.enonic.xp.schema.xdata.XData)4 SiteConfigs (com.enonic.xp.site.SiteConfigs)4 ContentPath (com.enonic.xp.content.ContentPath)3 Page (com.enonic.xp.page.Page)3