Search in sources :

Example 1 with ScriptSettings

use of com.enonic.xp.script.runtime.ScriptSettings in project xp by enonic.

the class BeanContextImplTest method getBinding.

@Test
public void getBinding() {
    final Supplier<String> binding = () -> "hello";
    final ScriptSettings settings = ScriptSettings.create().binding(String.class, binding).build();
    Mockito.when(this.executor.getScriptSettings()).thenReturn(settings);
    assertNotNull(this.context.getBinding(String.class));
    assertSame("hello", this.context.getBinding(String.class).get());
    assertNotNull(this.context.getBinding(Integer.class));
    assertNull(this.context.getBinding(Integer.class).get());
}
Also used : ScriptSettings(com.enonic.xp.script.runtime.ScriptSettings) Test(org.junit.jupiter.api.Test)

Example 2 with ScriptSettings

use of com.enonic.xp.script.runtime.ScriptSettings 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

ScriptSettings (com.enonic.xp.script.runtime.ScriptSettings)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 Test (org.junit.jupiter.api.Test)1 Activate (org.osgi.service.component.annotations.Activate)1