use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PortalUrlServiceImpl_assetUrlTest method createUrl_withContentPath.
@Test
public void createUrl_withContentPath() {
final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("myapplication"), "META-INF/MANIFEST.MF");
when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 1));
final AssetUrlParams params = new AssetUrlParams().portalRequest(this.portalRequest).contextPathType(ContextPathType.RELATIVE.getValue()).path("css/my.css");
final String url = this.service.assetUrl(params);
assertEquals("/site/default/draft/context/path/_/asset/myapplication:0000000000000001/css/my.css", url);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class AbstractScriptTest method createScriptRuntimeFactory.
private ScriptRuntimeFactory createScriptRuntimeFactory() {
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.getKey()).thenReturn(APPLICATION_KEY);
Mockito.when(application.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
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(APPLICATION_KEY)).thenReturn(application);
final ResourceService resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = AbstractScriptTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
return new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class ScriptRuntimeTest method testCompileError.
@Test
public void testCompileError() {
final ResourceKey script = ResourceKey.from("myapplication:/error/error-test.js");
try {
runTestScript(script);
fail("Should throw ResourceProblemException");
} catch (final ResourceProblemException e) {
assertEquals(1, e.getLineNumber());
assertEquals(script, e.getResource());
}
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class ScriptRuntimeTest method testRuntimeError.
@Test
public void testRuntimeError() {
final ResourceKey script = ResourceKey.from("myapplication:/error/error-in-export-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
try {
exports.executeMethod("hello");
fail("Should throw ResourceProblemException");
} catch (final ResourceProblemException e) {
assertEquals(1, e.getLineNumber());
assertEquals(ResourceKey.from("myapplication:/error/error-test.js"), e.getResource());
}
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class ScriptRuntimeTest method testExecuteExported.
@Test
public void testExecuteExported() {
final ResourceKey script = ResourceKey.from("myapplication:/export-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
assertSame(script, exports.getScript());
assertTrue(exports.hasMethod("hello"));
assertEquals("Hello World!", exports.executeMethod("hello", "World").getValue());
}
Aggregations