Search in sources :

Example 21 with SiteDescriptor

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

the class ControllerMappingsResolverTest method testResolve.

@Test
public void testResolve() {
    final Content content = newContent();
    final Site site = newSite();
    final SiteDescriptor siteDescriptor = newSiteDescriptor();
    Mockito.when(this.siteService.getDescriptor(getAppKey())).thenReturn(siteDescriptor);
    final SiteDescriptor siteDescriptor2 = newSiteDescriptor2();
    Mockito.when(this.siteService.getDescriptor(getAppKey2())).thenReturn(siteDescriptor2);
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/landing-page", ImmutableMultimap.of(), content, site.getSiteConfigs());
    assertThat(mapping).map(ControllerMappingDescriptor::getController).map(ResourceKey::getPath).contains("/site/controllers/controller2.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)

Example 22 with SiteDescriptor

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

the class ControllerMappingsResolverTest method testPatternCatchAll_matches_anything.

@Test
public void testPatternCatchAll_matches_anything() {
    final ControllerMappingDescriptor mapping1 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey2(), "/other/controller1.js")).pattern("/.*").order(10).build();
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping1);
    final Content content = newContent();
    final Site site = newSite();
    final SiteDescriptor siteDescriptor = SiteDescriptor.create().mappingDescriptors(mappings).build();
    Mockito.when(this.siteService.getDescriptor(getAppKey2())).thenReturn(siteDescriptor);
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/landing-page", ImmutableMultimap.of(), content, site.getSiteConfigs());
    assertThat(mapping).map(ControllerMappingDescriptor::getController).map(ResourceKey::getPath).contains("/other/controller1.js");
    final Optional<ControllerMappingDescriptor> mapping2 = resolver.resolve("/does-not-exist", ImmutableMultimap.of(), null, site.getSiteConfigs());
    assertThat(mapping2).map(ControllerMappingDescriptor::getController).map(ResourceKey::getPath).contains("/other/controller1.js");
    final Optional<ControllerMappingDescriptor> mapping3 = resolver.resolve("/", ImmutableMultimap.of(), site, site.getSiteConfigs());
    assertThat(mapping3).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) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors) Test(org.junit.jupiter.api.Test)

Example 23 with SiteDescriptor

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

the class ProcessorChainResolver method resolve.

public ResponseProcessorDescriptors resolve(PortalRequest request) {
    SiteDescriptor siteDescriptor;
    List<ResponseProcessorDescriptor> filterChain = new ArrayList<>();
    for (SiteConfig siteConfig : request.getSite().getSiteConfigs()) {
        siteDescriptor = siteService.getDescriptor(siteConfig.getApplicationKey());
        if (siteDescriptor != null) {
            for (ResponseProcessorDescriptor filterDescriptor : siteDescriptor.getResponseProcessors()) {
                filterChain.add(this.findIndexToInsert(filterDescriptor, filterChain), filterDescriptor);
            }
        }
    }
    return ResponseProcessorDescriptors.from(filterChain);
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ResponseProcessorDescriptor(com.enonic.xp.site.processor.ResponseProcessorDescriptor) ArrayList(java.util.ArrayList) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 24 with SiteDescriptor

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

the class ProcessorChainResolverTest method testFilterChainResolver.

@Test
public void testFilterChainResolver() {
    ApplicationKey ak1 = ApplicationKey.from("ak1");
    SiteConfig sc1 = SiteConfig.create().application(ak1).config(new PropertyTree()).build();
    ApplicationKey ak2 = ApplicationKey.from("ak2");
    SiteConfig sc2 = SiteConfig.create().application(ak2).config(new PropertyTree()).build();
    ApplicationKey ak3 = ApplicationKey.from("ak3");
    SiteConfig sc3 = SiteConfig.create().application(ak3).config(new PropertyTree()).build();
    portalRequest.setSite(Site.create().siteConfigs(SiteConfigs.from(sc1, sc2, sc3)).name("Site").path("/site").parentPath(ContentPath.ROOT).build());
    ResponseProcessorDescriptor fd12 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-2").order(2).build();
    ResponseProcessorDescriptor fd13 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-3").order(3).build();
    ResponseProcessorDescriptor fd15 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-5").order(5).build();
    SiteDescriptor sd1 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd13, fd15, fd12)).build();
    Mockito.when(siteService.getDescriptor(Mockito.eq(ak1))).thenReturn(sd1);
    ResponseProcessorDescriptor fd21 = ResponseProcessorDescriptor.create().application(ak2).name("ak2-1").order(1).build();
    ResponseProcessorDescriptor fd22 = ResponseProcessorDescriptor.create().application(ak2).name("ak1-2").order(2).build();
    ResponseProcessorDescriptor fd23 = ResponseProcessorDescriptor.create().application(ak2).name("ak2-3").order(3).build();
    SiteDescriptor sd2 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd22, fd23, fd21)).build();
    Mockito.when(siteService.getDescriptor(Mockito.eq(ak2))).thenReturn(sd2);
    ResponseProcessorDescriptor fd32 = ResponseProcessorDescriptor.create().application(ak3).name("ak3-2").order(2).build();
    SiteDescriptor sd3 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd32)).build();
    Mockito.when(siteService.getDescriptor(Mockito.eq(ak3))).thenReturn(sd3);
    ResponseProcessorDescriptors filters = resolver.resolve(portalRequest);
    assertEquals(7, filters.getSize());
    ResponseProcessorDescriptor fd = filters.get(0);
    assertEquals(1, fd.getOrder());
    assertEquals(ak2, fd.getApplication());
    fd = filters.get(1);
    assertEquals(2, fd.getOrder());
    assertEquals(ak1, fd.getApplication());
    fd = filters.get(2);
    assertEquals(2, fd.getOrder());
    assertEquals(ak2, fd.getApplication());
    fd = filters.get(3);
    assertEquals(2, fd.getOrder());
    assertEquals(ak3, fd.getApplication());
    fd = filters.get(4);
    assertEquals(3, fd.getOrder());
    assertEquals(ak1, fd.getApplication());
    fd = filters.get(5);
    assertEquals(3, fd.getOrder());
    assertEquals(ak2, fd.getApplication());
    fd = filters.get(6);
    assertEquals(5, fd.getOrder());
    assertEquals(ak1, fd.getApplication());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) ResponseProcessorDescriptor(com.enonic.xp.site.processor.ResponseProcessorDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig) ResponseProcessorDescriptors(com.enonic.xp.site.processor.ResponseProcessorDescriptors) 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