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");
}
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();
}
Aggregations