Search in sources :

Example 1 with AssetUrlParams

use of com.enonic.xp.portal.url.AssetUrlParams 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);
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey) AssetUrlParams(com.enonic.xp.portal.url.AssetUrlParams) Test(org.junit.jupiter.api.Test)

Example 2 with AssetUrlParams

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

the class PortalUrlServiceImpl_assetUrlTest method createUrl_withVirtualHost.

@Test
public void createUrl_withVirtualHost() {
    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.css");
    // Mocks a virtual host and the HTTP request
    final VirtualHost virtualHost = mock(VirtualHost.class);
    when(req.getAttribute(VirtualHost.class.getName())).thenReturn(virtualHost);
    // Calls the method with a virtual mapping /main -> /
    when(virtualHost.getSource()).thenReturn("/main");
    when(virtualHost.getTarget()).thenReturn("/");
    String url = this.service.assetUrl(params);
    assertEquals("/main/site/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
    // Calls the method with a virtual mapping /main -> /site/default/draft/context
    when(virtualHost.getSource()).thenReturn("/main");
    when(virtualHost.getTarget()).thenReturn("/site");
    url = this.service.assetUrl(params);
    assertEquals("/main/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
    // Calls the method with a virtual mapping /main -> /site/default/draft/context
    when(virtualHost.getSource()).thenReturn("/main");
    when(virtualHost.getTarget()).thenReturn("/site/default/draft");
    url = this.service.assetUrl(params);
    assertEquals("/main/_/asset/myapplication:0000000000000001/css/my.css", url);
    // Calls the method with a virtual mapping / -> /site/default/draft/context
    when(virtualHost.getSource()).thenReturn("/");
    when(virtualHost.getTarget()).thenReturn("/site/default/draft/context");
    url = this.service.assetUrl(params);
    assertEquals("/_/asset/myapplication:0000000000000001/css/my.css", url);
    // Calls the method with a virtual mapping /main/path -> /site/default/draft/context/path
    when(virtualHost.getSource()).thenReturn("/main/path");
    when(virtualHost.getTarget()).thenReturn("/site/default/draft/context/path");
    url = this.service.assetUrl(params);
    assertEquals("/main/path/_/asset/myapplication:0000000000000001/css/my.css", url);
    // Calls the method with a virtual mapping /site/default/draft/context/path -> /site/default/draft/context/path
    when(virtualHost.getSource()).thenReturn("/site/default/draft/context/path");
    when(virtualHost.getTarget()).thenReturn("/site/default/draft/context/path");
    url = this.service.assetUrl(params);
    assertEquals("/site/default/draft/context/path/_/asset/myapplication:0000000000000001/css/my.css", url);
}
Also used : VirtualHost(com.enonic.xp.web.vhost.VirtualHost) ResourceKey(com.enonic.xp.resource.ResourceKey) AssetUrlParams(com.enonic.xp.portal.url.AssetUrlParams) Test(org.junit.jupiter.api.Test)

Example 3 with AssetUrlParams

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

the class PortalUrlServiceImpl_assetUrlTest method createUrl.

@Test
public void createUrl() {
    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.css");
    final String url = this.service.assetUrl(params);
    assertEquals("/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 4 with AssetUrlParams

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

the class PortalUrlServiceImpl_assetUrlTest method createUrl_withApplication.

@Test
public void createUrl_withApplication() {
    final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("otherapplication"), "META-INF/MANIFEST.MF");
    when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 2));
    final AssetUrlParams params = new AssetUrlParams().portalRequest(this.portalRequest).application("otherapplication").path("css/my.css");
    final String url = this.service.assetUrl(params);
    assertEquals("/site/default/draft/_/asset/otherapplication:0000000000000002/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 5 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