Search in sources :

Example 71 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class AssetHandlerTest method testCacheHeader_FingerprintDoesntMatch.

@Test
public void testCacheHeader_FingerprintDoesntMatch() throws Exception {
    addResource("demo:/assets/css/main.css");
    this.request.setEndpointPath("/_/asset/demo:123/css/main.css");
    final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("demo"), "META-INF/MANIFEST.MF");
    when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 1));
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertNull(res.getHeaders().get("Cache-Control"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ResourceKey(com.enonic.xp.resource.ResourceKey) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 72 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class AssetHandlerTest method addResource.

private Resource addResource(final String key) throws Exception {
    final ResourceKey resourceKey = ResourceKey.from(key);
    final Resource resource = Mockito.mock(Resource.class);
    when(resource.exists()).thenReturn(true);
    when(resource.getKey()).thenReturn(resourceKey);
    this.resources.put(resourceKey, resource);
    return resource;
}
Also used : MockResource(com.enonic.xp.resource.MockResource) Resource(com.enonic.xp.resource.Resource) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 73 with ResourceKey

use of com.enonic.xp.resource.ResourceKey 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)

Example 74 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class ScriptRuntimeTest method testEmpty.

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

Example 75 with ResourceKey

use of com.enonic.xp.resource.ResourceKey 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)

Aggregations

ResourceKey (com.enonic.xp.resource.ResourceKey)76 Test (org.junit.jupiter.api.Test)49 Resource (com.enonic.xp.resource.Resource)21 ApplicationKey (com.enonic.xp.app.ApplicationKey)12 ResourceService (com.enonic.xp.resource.ResourceService)12 ScriptExports (com.enonic.xp.script.ScriptExports)11 Application (com.enonic.xp.app.Application)9 UrlResource (com.enonic.xp.resource.UrlResource)9 URL (java.net.URL)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 PortalRequest (com.enonic.xp.portal.PortalRequest)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 ApplicationService (com.enonic.xp.app.ApplicationService)7 AssetUrlParams (com.enonic.xp.portal.url.AssetUrlParams)7 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)7 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)7 PortalResponse (com.enonic.xp.portal.PortalResponse)6 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)6 PropertyTree (com.enonic.xp.data.PropertyTree)5