Search in sources :

Example 6 with ControllerMappingDescriptors

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