Search in sources :

Example 11 with VirtualHostResolver

use of com.enonic.xp.web.vhost.VirtualHostResolver in project xp by enonic.

the class VirtualHostResolverImplTest method test_matchesVHostWithLongestSourceAndEqualHosts.

@Test
public void test_matchesVHostWithLongestSourceAndEqualHosts() {
    final List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.add(createVirtualHostMapping("a", "no.domain.com", "/source", "/other/a", 0));
    virtualHosts.add(createVirtualHostMapping("b", "~(?<sub>.+)\\.domain\\.com", "/source/path", "/other/b/${sub}", 0));
    when(virtualHostService.getVirtualHosts()).thenReturn(virtualHosts);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getServerName()).thenReturn("no.domain.com");
    when(req.getRequestURI()).thenReturn(URI.create("https://no.domain.com/source/path/123").getPath());
    final VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    VirtualHost mapping = virtualHostResolver.resolveVirtualHost(req);
    assertNotNull(mapping);
    assertEquals("b", mapping.getName());
    assertEquals("/other/b/no", mapping.getTarget());
    assertEquals("no.domain.com", mapping.getHost());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostResolver(com.enonic.xp.web.vhost.VirtualHostResolver) ArrayList(java.util.ArrayList) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Aggregations

VirtualHostResolver (com.enonic.xp.web.vhost.VirtualHostResolver)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Test (org.junit.jupiter.api.Test)11 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)8 ArrayList (java.util.ArrayList)8 VirtualHostMapping (com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping)3