Search in sources :

Example 1 with IdentityUrlParams

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

the class PortalUrlServiceImpl_identityUrlTest method createUrl_withVirtualHost.

@Test
public void createUrl_withVirtualHost() {
    final IdentityUrlParams params = new IdentityUrlParams().portalRequest(this.portalRequest).idProviderKey(IdProviderKey.system()).idProviderFunction("login");
    // Mocks a virtual host and the HTTP request
    final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
    when(req.getAttribute(VirtualHost.class.getName())).thenReturn(virtualHost);
    // Calls the method with a virtual mapping /main -> /
    Mockito.when(virtualHost.getSource()).thenReturn("/main");
    Mockito.when(virtualHost.getTarget()).thenReturn("/");
    String url = this.service.identityUrl(params);
    assertEquals("/main/site/default/draft/_/idprovider/system/login", url);
    // Calls the method with a virtual mapping /main -> /site/default/draft/context
    Mockito.when(virtualHost.getSource()).thenReturn("/main");
    Mockito.when(virtualHost.getTarget()).thenReturn("/site");
    url = this.service.identityUrl(params);
    assertEquals("/main/default/draft/_/idprovider/system/login", url);
    // Calls the method with a virtual mapping /main -> /site/default/draft/context
    Mockito.when(virtualHost.getSource()).thenReturn("/main");
    Mockito.when(virtualHost.getTarget()).thenReturn("/site/default/draft");
    url = this.service.identityUrl(params);
    assertEquals("/main/_/idprovider/system/login", url);
    // Calls the method with a virtual mapping / -> /site/default/draft/context
    Mockito.when(virtualHost.getSource()).thenReturn("/");
    Mockito.when(virtualHost.getTarget()).thenReturn("/site/default/draft/context");
    url = this.service.identityUrl(params);
    assertEquals("/_/idprovider/system/login", url);
    // Calls the method with a virtual mapping /main/path -> /site/default/draft/context/path
    Mockito.when(virtualHost.getSource()).thenReturn("/main/path");
    Mockito.when(virtualHost.getTarget()).thenReturn("/site/default/draft/context/path");
    url = this.service.identityUrl(params);
    assertEquals("/main/path/_/idprovider/system/login", url);
    // Calls the method with a virtual mapping /site/default/draft/context/path -> /site/default/draft/context/path
    Mockito.when(virtualHost.getSource()).thenReturn("/site/default/draft/context/path");
    Mockito.when(virtualHost.getTarget()).thenReturn("/site/default/draft/context/path");
    url = this.service.identityUrl(params);
    assertEquals("/site/default/draft/context/path/_/idprovider/system/login", url);
    // Post treatment
    ServletRequestHolder.setRequest(null);
}
Also used : VirtualHost(com.enonic.xp.web.vhost.VirtualHost) IdentityUrlParams(com.enonic.xp.portal.url.IdentityUrlParams) Test(org.junit.jupiter.api.Test)

Example 2 with IdentityUrlParams

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

the class PortalUrlServiceImpl_identityUrlTest method createUrl_withContentPath.

@Test
public void createUrl_withContentPath() {
    final IdentityUrlParams params = new IdentityUrlParams().portalRequest(this.portalRequest).contextPathType(ContextPathType.RELATIVE.getValue()).idProviderKey(IdProviderKey.system()).idProviderFunction("login");
    final String url = this.service.identityUrl(params);
    assertEquals("/site/default/draft/context/path/_/idprovider/system/login", url);
}
Also used : IdentityUrlParams(com.enonic.xp.portal.url.IdentityUrlParams) Test(org.junit.jupiter.api.Test)

Example 3 with IdentityUrlParams

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

the class PortalUrlServiceImpl_identityUrlTest method createUrl_withoutFunction.

@Test
public void createUrl_withoutFunction() {
    final IdentityUrlParams params = new IdentityUrlParams().portalRequest(this.portalRequest).idProviderKey(IdProviderKey.system());
    final String url = this.service.identityUrl(params);
    assertEquals("/site/default/draft/_/idprovider/system", url);
}
Also used : IdentityUrlParams(com.enonic.xp.portal.url.IdentityUrlParams) Test(org.junit.jupiter.api.Test)

Example 4 with IdentityUrlParams

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

the class PortalUrlServiceImpl_identityUrlTest method createUrl.

@Test
public void createUrl() {
    final IdentityUrlParams params = new IdentityUrlParams().portalRequest(this.portalRequest).idProviderKey(IdProviderKey.system()).idProviderFunction("login");
    final String url = this.service.identityUrl(params);
    assertEquals("/site/default/draft/_/idprovider/system/login", url);
}
Also used : IdentityUrlParams(com.enonic.xp.portal.url.IdentityUrlParams) Test(org.junit.jupiter.api.Test)

Example 5 with IdentityUrlParams

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

the class PortalUrlServiceImpl_identityUrlTest method createUrl_normalizedCharacters.

@Test
public void createUrl_normalizedCharacters() {
    this.portalRequest.setContentPath(ContentPath.from(ContentPath.ROOT, "feåtures"));
    final IdentityUrlParams params = new IdentityUrlParams().portalRequest(this.portalRequest).idProviderKey(IdProviderKey.system()).idProviderFunction("login");
    final String url = this.service.identityUrl(params);
    assertEquals("/site/default/draft/_/idprovider/system/login", url);
}
Also used : IdentityUrlParams(com.enonic.xp.portal.url.IdentityUrlParams) Test(org.junit.jupiter.api.Test)

Aggregations

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