use of com.enonic.xp.resource.ResourceKey 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);
}
use of com.enonic.xp.resource.ResourceKey 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());
}
use of com.enonic.xp.resource.ResourceKey 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());
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class ScriptExportsCacheTest method expireCacheIfNeeded.
@Test
void expireCacheIfNeeded() throws Exception {
final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("some.app"), "main.js");
final Resource resource = mock(Resource.class);
when(resource.getTimestamp()).thenReturn(1L, 2L);
final Object value = new Object();
when(requireFunction.apply(resource)).thenReturn(value);
when(resourceLookup.apply(resourceKey)).thenReturn(resource);
final ScriptExportsCache scriptExportsCache = new ScriptExportsCache(RunMode.DEV, resourceLookup, expiredCallback);
final Object getOrCompute1 = scriptExportsCache.getOrCompute(resourceKey, requireFunction);
scriptExportsCache.expireCacheIfNeeded();
final Object getOrCompute2 = scriptExportsCache.getOrCompute(resourceKey, requireFunction);
assertAll(() -> assertSame(value, getOrCompute1), () -> assertSame(value, getOrCompute2));
verify(resourceLookup, times(2)).apply(resourceKey);
verifyNoMoreInteractions(resourceLookup);
verify(requireFunction, times(2)).apply(resource);
verifyNoMoreInteractions(requireFunction);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class RequireResolverTest method resolve_no_ext_json.
@Test
public void resolve_no_ext_json() throws Exception {
touchFile("dummy/index.json");
final ResourceKey key2 = resolve("/a/b/c.js", "/dummy");
assertEquals("/dummy/index.json", key2.getPath());
}
Aggregations