Search in sources :

Example 1 with ContextAccessor

use of com.enonic.xp.context.ContextAccessor in project xp by enonic.

the class ScriptTestSupport method initialize.

protected void initialize() throws Exception {
    this.serviceRegistry = new MockServiceRegistry();
    this.portalRequest = createPortalRequest();
    PortalRequestAccessor.set(this.portalRequest);
    this.bundleContext = createBundleContext();
    this.contentService = Mockito.mock(ContentService.class);
    this.resourceService = createResourceService();
    addService(ContentService.class, this.contentService);
    addService(ResourceService.class, this.resourceService);
    addService(ViewFunctionService.class, new MockViewFunctionService());
    this.scriptSettings = ScriptSettings.create();
    this.scriptSettings.binding(Context.class, ContextAccessor::current);
    this.scriptSettings.binding(PortalRequest.class, () -> this.portalRequest);
    this.scriptSettings.debug(new ScriptDebugSettings());
    this.scriptSettings.globalVariable("testInstance", this);
    this.executor = createExecutor();
}
Also used : ContextAccessor(com.enonic.xp.context.ContextAccessor) MockViewFunctionService(com.enonic.xp.testing.mock.MockViewFunctionService) MockServiceRegistry(com.enonic.xp.testing.mock.MockServiceRegistry) ContentService(com.enonic.xp.content.ContentService)

Example 2 with ContextAccessor

use of com.enonic.xp.context.ContextAccessor in project xp by enonic.

the class PortalScriptServiceImpl method initialize.

@Activate
public void initialize() {
    final ScriptSettings settings = ScriptSettings.create().binding(Context.class, ContextAccessor::current).binding(PortalRequest.class, PortalRequestAccessor::get).build();
    this.scriptRuntime = this.scriptRuntimeFactory.create(settings);
}
Also used : ContextAccessor(com.enonic.xp.context.ContextAccessor) ScriptSettings(com.enonic.xp.script.runtime.ScriptSettings) PortalRequest(com.enonic.xp.portal.PortalRequest) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ContentService (com.enonic.xp.content.ContentService)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 ScriptSettings (com.enonic.xp.script.runtime.ScriptSettings)1 MockServiceRegistry (com.enonic.xp.testing.mock.MockServiceRegistry)1 MockViewFunctionService (com.enonic.xp.testing.mock.MockViewFunctionService)1 Activate (org.osgi.service.component.annotations.Activate)1