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);
}
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);
}
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);
}
Aggregations