Search in sources :

Example 11 with ScriptExports

use of com.enonic.xp.script.ScriptExports in project xp by enonic.

the class ScriptRuntimeTest method testCache.

@Test
public void testCache() {
    final ResourceKey script = ResourceKey.from("myapplication:/empty-test.js");
    final ScriptExports exports1 = runTestScript(script);
    final ScriptExports exports2 = runTestScript(script);
    assertNotNull(exports2);
    assertSame(exports1.getRawValue(), exports2.getRawValue());
    this.scriptRuntime.invalidate(ApplicationKey.from("othermodule"));
    final ScriptExports exports3 = runTestScript(script);
    assertSame(exports1.getRawValue(), exports3.getRawValue());
    this.scriptRuntime.invalidate(script.getApplicationKey());
    final ScriptExports exports4 = runTestScript(script);
    assertNotSame(exports1.getRawValue(), exports4.getRawValue());
}
Also used : ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 12 with ScriptExports

use of com.enonic.xp.script.ScriptExports in project xp by enonic.

the class ScriptRuntimeTest method testRequire.

@Test
public void testRequire() {
    final ResourceKey script = ResourceKey.from("myapplication:/site/require/require-test.js");
    final ScriptExports exports = runTestScript(script);
    assertNotNull(exports);
}
Also used : ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 13 with ScriptExports

use of com.enonic.xp.script.ScriptExports in project xp by enonic.

the class ScriptRuntimeTest method testExecuteExported_objectArg.

@Test
public void testExecuteExported_objectArg() {
    final ResourceKey script = ResourceKey.from("myapplication:/export-test.js");
    final ScriptExports exports = runTestScript(script);
    assertNotNull(exports);
    assertSame(script, exports.getScript());
    assertTrue(exports.hasMethod("helloObject"));
    assertEquals("Hello World!", exports.executeMethod("helloObject", (MapSerializable) gen -> gen.value("name", "World")).getValue());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ResourceKey(com.enonic.xp.resource.ResourceKey) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) ApplicationKey(com.enonic.xp.app.ApplicationKey) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ScriptExports(com.enonic.xp.script.ScriptExports) MapSerializable(com.enonic.xp.script.serializer.MapSerializable) ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 14 with ScriptExports

use of com.enonic.xp.script.ScriptExports in project xp by enonic.

the class NewBeanScriptTest method testEmpty.

@Test
public void testEmpty() {
    final ResourceKey script = ResourceKey.from("myapplication:/bean/simple-test.js");
    final ScriptExports exports = runTestScript(script);
    assertNotNull(exports);
    assertSame(script, exports.getScript());
}
Also used : ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test) AbstractScriptTest(com.enonic.xp.script.impl.AbstractScriptTest)

Example 15 with ScriptExports

use of com.enonic.xp.script.ScriptExports in project xp by enonic.

the class ScriptRuntimeTest method testRequire_3rd.

@Test
public void testRequire_3rd() {
    final ResourceKey script = ResourceKey.from("myapplication:/site/require/3rd/require-3rd-test.js");
    final ScriptExports exports = runTestScript(script);
    assertNotNull(exports);
}
Also used : ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Aggregations

ScriptExports (com.enonic.xp.script.ScriptExports)22 Test (org.junit.jupiter.api.Test)17 ResourceKey (com.enonic.xp.resource.ResourceKey)14 AbstractScriptTest (com.enonic.xp.script.impl.AbstractScriptTest)6 MapSerializable (com.enonic.xp.script.serializer.MapSerializable)6 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 PortalScriptService (com.enonic.xp.portal.script.PortalScriptService)3 ScriptValue (com.enonic.xp.script.ScriptValue)3 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2 ResourceNotFoundException (com.enonic.xp.resource.ResourceNotFoundException)2 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)2 HashMap (java.util.HashMap)2 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)1 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)1 TaskNotFoundException (com.enonic.xp.task.TaskNotFoundException)1 HashMultimap (com.google.common.collect.HashMultimap)1 ByteSource (com.google.common.io.ByteSource)1