Search in sources :

Example 6 with PortalScriptService

use of com.enonic.xp.portal.script.PortalScriptService in project xp by enonic.

the class ResponseProcessorExecutorTest method testExecuteResponseProcessorNotImplementingMethod.

@Test
public void testExecuteResponseProcessorNotImplementingMethod() throws Exception {
    final PortalScriptService scriptService = Mockito.mock(PortalScriptService.class);
    final ScriptExports scriptExports = Mockito.mock(ScriptExports.class);
    when(scriptService.execute(any(ResourceKey.class))).thenReturn(scriptExports);
    final ResponseProcessorExecutor filterExecutor = new ResponseProcessorExecutor(scriptService);
    final ResponseProcessorDescriptor filter = ResponseProcessorDescriptor.create().application(ApplicationKey.from("myApp")).name("filter1").build();
    final PortalRequest request = new PortalRequest();
    final PortalResponse response = PortalResponse.create().build();
    try {
        filterExecutor.execute(filter, request, response);
        fail("Expected exception");
    } catch (RenderException e) {
        assertEquals("Missing exported function [responseProcessor] in response filter [/site/processors/filter1.js]", e.getMessage());
    }
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) PortalScriptService(com.enonic.xp.portal.script.PortalScriptService) ResponseProcessorDescriptor(com.enonic.xp.site.processor.ResponseProcessorDescriptor) ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Aggregations

PortalScriptService (com.enonic.xp.portal.script.PortalScriptService)6 ResourceKey (com.enonic.xp.resource.ResourceKey)4 Test (org.junit.jupiter.api.Test)4 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 ScriptExports (com.enonic.xp.script.ScriptExports)3 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Application (com.enonic.xp.app.Application)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 ApplicationService (com.enonic.xp.app.ApplicationService)1 ConfigBuilder (com.enonic.xp.config.ConfigBuilder)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 IdProviderDescriptorService (com.enonic.xp.idprovider.IdProviderDescriptorService)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)1 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)1 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)1 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)1 ResourceService (com.enonic.xp.resource.ResourceService)1