Search in sources :

Example 6 with PortalScriptServiceImpl

use of com.enonic.xp.portal.impl.script.PortalScriptServiceImpl in project xp by enonic.

the class FilterScriptImplTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.portalRequest = new PortalRequest();
    this.portalResponse = PortalResponse.create().build();
    final BundleContext bundleContext = Mockito.mock(BundleContext.class);
    final Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
    final Application application = Mockito.mock(Application.class);
    Mockito.when(application.getBundle()).thenReturn(bundle);
    Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
    Mockito.when(application.isStarted()).thenReturn(true);
    Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
    final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
    Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
    this.resourceService = Mockito.mock(ResourceService.class);
    Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = FilterScriptImplTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    });
    final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
    final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
    final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
    scriptService.initialize();
    this.factory = new FilterScriptFactoryImpl();
    this.factory.setScriptService(scriptService);
    final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
    ServletRequestHolder.setRequest(req);
}
Also used : Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) URL(java.net.URL) PortalRequest(com.enonic.xp.portal.PortalRequest) ResourceKey(com.enonic.xp.resource.ResourceKey) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) UrlResource(com.enonic.xp.resource.UrlResource) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Application (com.enonic.xp.app.Application)6 ApplicationService (com.enonic.xp.app.ApplicationService)6 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 ResourceKey (com.enonic.xp.resource.ResourceKey)6 ResourceService (com.enonic.xp.resource.ResourceService)6 UrlResource (com.enonic.xp.resource.UrlResource)6 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)6 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)6 URL (java.net.URL)6 Bundle (org.osgi.framework.Bundle)6 BundleContext (org.osgi.framework.BundleContext)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PostProcessorImpl (com.enonic.xp.portal.impl.postprocess.PostProcessorImpl)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 ConfigBuilder (com.enonic.xp.config.ConfigBuilder)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 PortalScriptService (com.enonic.xp.portal.script.PortalScriptService)1