Search in sources :

Example 6 with AssetUrlParams

use of com.enonic.xp.portal.url.AssetUrlParams in project xp by enonic.

the class PortalUrlServiceImpl_assetUrlTest method createUrl_absolute.

@Test
public void createUrl_absolute() {
    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().type(UrlTypeConstants.ABSOLUTE).portalRequest(this.portalRequest).path("css/my.css");
    when(req.getServerName()).thenReturn("localhost");
    when(req.getScheme()).thenReturn("http");
    when(req.getServerPort()).thenReturn(80);
    final String url = this.service.assetUrl(params);
    assertEquals("http://localhost/site/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey) AssetUrlParams(com.enonic.xp.portal.url.AssetUrlParams) Test(org.junit.jupiter.api.Test)

Example 7 with AssetUrlParams

use of com.enonic.xp.portal.url.AssetUrlParams in project xp by enonic.

the class PortalUrlServiceImpl_assetUrlTest method createUrl_encodeChars.

@Test
public void createUrl_encodeChars() {
    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).path("css/my other & strange.css");
    final String url = this.service.assetUrl(params);
    assertEquals("/site/default/draft/_/asset/myapplication:0000000000000001/css/my%20other%20&%20strange.css", url);
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey) AssetUrlParams(com.enonic.xp.portal.url.AssetUrlParams) Test(org.junit.jupiter.api.Test)

Aggregations

AssetUrlParams (com.enonic.xp.portal.url.AssetUrlParams)7 ResourceKey (com.enonic.xp.resource.ResourceKey)7 Test (org.junit.jupiter.api.Test)7 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)1