Search in sources :

Example 1 with ControllerMappingDescriptor

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

the class ControllerMappingsResolverTest method testNoDescriptors.

@Test
public void testNoDescriptors() {
    final Content content = newContent();
    final Site site = newSite();
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/landing-page", ImmutableMultimap.of(), content, site.getSiteConfigs());
    assertTrue(mapping.isEmpty());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with ControllerMappingDescriptor

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

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

the class MappingHandlerTest method executeScript.

@Test
public void executeScript() throws Exception {
    final ResourceKey controller = ResourceKey.from("demo:/services/test");
    final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().controller(controller).pattern(".*/content").build();
    setupContentAndSite(mapping);
    this.request.setBaseUri("/site");
    this.request.setContentPath(ContentPath.from("/site/somesite/content"));
    when(rendererDelegate.render(isA(ControllerMappingDescriptor.class), same(request))).thenReturn(PortalResponse.create().body("Ok").build());
    final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    assertNotNull(this.request.getApplicationKey());
    assertNotNull(this.request.getSite());
    assertNotNull(this.request.getContent());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 4 with ControllerMappingDescriptor

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

the class MappingHandlerTest method executeNothing.

@Test
public void executeNothing() throws Exception {
    final ResourceKey controller = ResourceKey.from("demo:/services/test");
    final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().controller(controller).pattern("/nomatch").build();
    setupContentAndSite(mapping);
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setBaseUri("/site");
    this.request.setContentPath(ContentPath.from("/site/somesite/content"));
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 5 with ControllerMappingDescriptor

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

Aggregations

ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)17 Test (org.junit.jupiter.api.Test)11 Site (com.enonic.xp.site.Site)7 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)7 Content (com.enonic.xp.content.Content)6 ControllerMappingDescriptors (com.enonic.xp.site.mapping.ControllerMappingDescriptors)6 ResourceKey (com.enonic.xp.resource.ResourceKey)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 WebResponse (com.enonic.xp.web.WebResponse)2 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 ContentResolverResult (com.enonic.xp.portal.impl.ContentResolverResult)1 HttpMethod (com.enonic.xp.web.HttpMethod)1 WebException (com.enonic.xp.web.WebException)1 WebHandlerChain (com.enonic.xp.web.handler.WebHandlerChain)1 DomElement (com.enonic.xp.xml.DomElement)1