Search in sources :

Example 1 with MockResource

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

the class WebAppHandlerTest method mockResource.

private Resource mockResource(final String uri, final byte[] data) {
    final ResourceKey key = ResourceKey.from(uri);
    final Resource resource = new MockResource(key, data, System.currentTimeMillis());
    Mockito.when(this.resourceService.getResource(key)).thenReturn(resource);
    return resource;
}
Also used : MockResource(com.enonic.xp.resource.MockResource) MockResource(com.enonic.xp.resource.MockResource) Resource(com.enonic.xp.resource.Resource) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 2 with MockResource

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

the class WebAppHandlerTest method handle_serveAsset.

@Test
public void handle_serveAsset() throws Exception {
    final Resource resource = mockResource("myapp:/assets/a/b.txt", "hello".getBytes());
    this.request.setRawPath("/webapp/myapp/a/b.txt");
    this.request.setMethod(HttpMethod.GET);
    final WebResponse response = this.handler.doHandle(this.request, null, this.chain);
    assertEquals(HttpStatus.OK, response.getStatus());
    assertSame(resource, response.getBody());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) MockResource(com.enonic.xp.resource.MockResource) Resource(com.enonic.xp.resource.Resource) Test(org.junit.jupiter.api.Test)

Aggregations

MockResource (com.enonic.xp.resource.MockResource)2 Resource (com.enonic.xp.resource.Resource)2 ResourceKey (com.enonic.xp.resource.ResourceKey)1 WebResponse (com.enonic.xp.web.WebResponse)1 Test (org.junit.jupiter.api.Test)1