Search in sources :

Example 1 with GenerateUrlParams

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

the class PortalUrlServiceImpl_generateUrlTest method createUrl_absolute.

@Test
public void createUrl_absolute() {
    final GenerateUrlParams params = new GenerateUrlParams().type(UrlTypeConstants.ABSOLUTE).portalRequest(this.portalRequest).url("/admin").param("a", 3);
    when(req.getServerName()).thenReturn("localhost");
    when(req.getScheme()).thenReturn("http");
    when(req.getServerPort()).thenReturn(80);
    final String url = this.service.generateUrl(params);
    assertEquals("http://localhost/admin?a=3", url);
}
Also used : GenerateUrlParams(com.enonic.xp.portal.url.GenerateUrlParams) Test(org.junit.jupiter.api.Test)

Example 2 with GenerateUrlParams

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

the class PortalUrlServiceImpl_generateUrlTest method createUrl.

@Test
public void createUrl() {
    final GenerateUrlParams params = new GenerateUrlParams().portalRequest(this.portalRequest).url("/admin").param("a", 3);
    final String url = this.service.generateUrl(params);
    assertEquals("/admin?a=3", url);
}
Also used : GenerateUrlParams(com.enonic.xp.portal.url.GenerateUrlParams) Test(org.junit.jupiter.api.Test)

Example 3 with GenerateUrlParams

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

the class PortalUrlServiceImpl_generateUrlTest method createUrl_withVirtualHost.

@Test
public void createUrl_withVirtualHost() {
    final GenerateUrlParams params = new GenerateUrlParams().type(UrlTypeConstants.ABSOLUTE).portalRequest(this.portalRequest).url("/admin").param("a", 3);
    // Mocks a virtual host and the HTTP request
    final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
    when(req.getAttribute(VirtualHost.class.getName())).thenReturn(virtualHost);
    when(req.getServerName()).thenReturn("localhost");
    when(req.getScheme()).thenReturn("http");
    when(req.getServerPort()).thenReturn(80);
    // Calls the method with a virtual mapping /main -> /
    Mockito.when(virtualHost.getSource()).thenReturn("/main");
    Mockito.when(virtualHost.getTarget()).thenReturn("/");
    String url = this.service.generateUrl(params);
    assertEquals("http://localhost/main/admin?a=3", url);
    // Calls the method with a virtual mapping /main -> /site/default/draft/context
    Mockito.when(virtualHost.getSource()).thenReturn("/studio");
    Mockito.when(virtualHost.getTarget()).thenReturn("/admin");
    url = this.service.generateUrl(params);
    assertEquals("http://localhost/studio?a=3", url);
    // Calls the method with a virtual mapping /main -> /site/default/draft/context
    Mockito.when(virtualHost.getSource()).thenReturn("/");
    Mockito.when(virtualHost.getTarget()).thenReturn("/admin");
    url = this.service.generateUrl(params);
    assertEquals("http://localhost/?a=3", url);
    // Post treatment
    ServletRequestHolder.setRequest(null);
}
Also used : GenerateUrlParams(com.enonic.xp.portal.url.GenerateUrlParams) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Aggregations

GenerateUrlParams (com.enonic.xp.portal.url.GenerateUrlParams)3 Test (org.junit.jupiter.api.Test)3 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)1