Search in sources :

Example 16 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class ModifyContentHandlerTest method modifySiteConfig.

@Test
public void modifySiteConfig() {
    final Content content = TestDataFixtures.newSmallContent();
    when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], TestDataFixtures.newSmallContent()));
    mockXData();
    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);
    runFunction("/test/ModifyContentHandlerTest.js", "modifySiteConfig");
    runFunction("/test/ModifyContentHandlerTest.js", "modifySiteConfig_strict");
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

Example 17 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class ModifyContentHandlerTest method modifySiteSingleDescriptor.

@Test
public void modifySiteSingleDescriptor() {
    final Content content = TestDataFixtures.newSmallContent();
    when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], TestDataFixtures.newSmallContent()));
    mockXData();
    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();
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey1"))).thenReturn(siteDescriptor1);
    runFunction("/test/ModifyContentHandlerTest.js", "modifySiteSingleDescriptor");
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

Example 18 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class HtmlAreaContentProcessor method processSiteConfigData.

private void processSiteConfigData(final SiteConfigs siteConfigs, final ContentIds.Builder processedIds) {
    siteConfigs.forEach(siteConfig -> {
        final SiteDescriptor siteDescriptor = siteService.getDescriptor(siteConfig.getApplicationKey());
        if (siteDescriptor == null) {
            return;
        }
        final Collection<Property> properties = getProperties(siteConfig.getConfig(), siteDescriptor.getForm().getFormItems());
        processDataTree(properties, processedIds);
    });
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) Property(com.enonic.xp.data.Property)

Example 19 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class MappingHandlerTest method setupContentAndSite.

private void setupContentAndSite(final ControllerMappingDescriptor mapping) {
    final Content content = createPage("id", "site/somesite/content", "myapplication:ctype", true);
    final Site site = createSite("id", "site", "myapplication:contenttypename");
    final ContentPath path = ContentPath.from("site/somesite/content").asAbsolute();
    when(this.contentService.getByPath(path)).thenReturn(content);
    when(this.contentService.findNearestSiteByPath(eq(path))).thenReturn(site);
    when(this.contentService.getById(content.getId())).thenReturn(content);
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping);
    final SiteDescriptor siteDescriptor = SiteDescriptor.create().mappingDescriptors(mappings).build();
    when(this.siteService.getDescriptor(any(ApplicationKey.class))).thenReturn(siteDescriptor);
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors)

Example 20 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class ControllerMappingsResolverTest method testResolveWithParameters.

@Test
public void testResolveWithParameters() {
    final Content content = newContent();
    final Site site = newSite();
    final SiteDescriptor siteDescriptor = newSiteDescriptor3();
    Mockito.when(this.siteService.getDescriptor(getAppKey2())).thenReturn(siteDescriptor);
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/api", ImmutableMultimap.of("key", "123", "category", "foo"), content, site.getSiteConfigs());
    assertThat(mapping).map(ControllerMappingDescriptor::getController).map(ResourceKey::getPath).contains("/other/controller1.js");
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) Content(com.enonic.xp.content.Content) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

SiteDescriptor (com.enonic.xp.site.SiteDescriptor)24 Test (org.junit.jupiter.api.Test)17 ApplicationKey (com.enonic.xp.app.ApplicationKey)13 Content (com.enonic.xp.content.Content)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 Site (com.enonic.xp.site.Site)6 SiteConfig (com.enonic.xp.site.SiteConfig)4 ControllerMappingDescriptors (com.enonic.xp.site.mapping.ControllerMappingDescriptors)3 EditableContent (com.enonic.xp.content.EditableContent)2 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Form (com.enonic.xp.form.Form)2 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)2 ContentPath (com.enonic.xp.content.ContentPath)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 Property (com.enonic.xp.data.Property)1 FormItemSet (com.enonic.xp.form.FormItemSet)1 ContentType (com.enonic.xp.schema.content.ContentType)1 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)1 XData (com.enonic.xp.schema.xdata.XData)1