Search in sources :

Example 1 with ControllerMappingDescriptors

use of com.enonic.xp.site.mapping.ControllerMappingDescriptors in project xp by enonic.

the class ControllerMappingsResolverTest method newDescriptorForFragments.

private SiteDescriptor newDescriptorForFragments() {
    final ControllerMappingDescriptor mapping1 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey(), "/site/controllers/controller1.js")).pattern("/.*").contentConstraint("type:'portal:fragment'").order(10).build();
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping1);
    return SiteDescriptor.create().mappingDescriptors(mappings).build();
}
Also used : ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors)

Example 2 with ControllerMappingDescriptors

use of com.enonic.xp.site.mapping.ControllerMappingDescriptors in project xp by enonic.

the class ControllerMappingsResolverTest method newSiteDescriptor3.

private SiteDescriptor newSiteDescriptor3() {
    final ControllerMappingDescriptor mapping1 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey2(), "/other/controller1.js")).pattern("/.*api.*\\?category=.*&key=\\d+").order(10).build();
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping1);
    return SiteDescriptor.create().mappingDescriptors(mappings).build();
}
Also used : ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors)

Example 3 with ControllerMappingDescriptors

use of com.enonic.xp.site.mapping.ControllerMappingDescriptors in project xp by enonic.

the class ControllerMappingsResolverTest method testPatternCatchAllType_not_matches_missing.

@Test
public void testPatternCatchAllType_not_matches_missing() {
    final ControllerMappingDescriptor mapping1 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey2(), "/other/controller1.js")).contentConstraint("type:'.+:.+'").order(10).build();
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping1);
    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("/does-not-exist", ImmutableMultimap.of(), null, site.getSiteConfigs());
    assertTrue(mapping.isEmpty());
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors) Test(org.junit.jupiter.api.Test)

Example 4 with ControllerMappingDescriptors

use of com.enonic.xp.site.mapping.ControllerMappingDescriptors 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 5 with ControllerMappingDescriptors

use of com.enonic.xp.site.mapping.ControllerMappingDescriptors in project xp by enonic.

the class ControllerMappingsResolverTest method newSiteDescriptor.

private SiteDescriptor newSiteDescriptor() {
    final ControllerMappingDescriptor mapping1 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey(), "/site/controllers/controller1.js")).pattern("/.*").contentConstraint("_id:'123456'").order(10).build();
    final ControllerMappingDescriptor mapping2 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey(), "/site/controllers/controller2.js")).pattern("/.*").contentConstraint("_path:'/mysite/landing-page'").order(5).build();
    final ControllerMappingDescriptor mapping3 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey(), "/site/controllers/controller3.js")).pattern("/.*").contentConstraint("_name:'landing-page'").order(15).build();
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping1, mapping2, mapping3);
    return SiteDescriptor.create().mappingDescriptors(mappings).build();
}
Also used : ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors)

Aggregations

ControllerMappingDescriptors (com.enonic.xp.site.mapping.ControllerMappingDescriptors)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)6 Site (com.enonic.xp.site.Site)3 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)3 Content (com.enonic.xp.content.Content)2 Test (org.junit.jupiter.api.Test)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 ContentPath (com.enonic.xp.content.ContentPath)1