Search in sources :

Example 6 with VirtualHostMapping

use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.

the class VirtualHostResolverImplTest method testMatches_host.

@Test
public void testMatches_host() {
    this.virtualHostMapping = new VirtualHostMapping("mymapping", "foo.no", "/", "/a", VirtualHostIdProvidersMapping.create().build(), 0);
    when(virtualHostService.getVirtualHosts()).thenReturn(List.of(this.virtualHostMapping));
    VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getServerName()).thenReturn("foo.no");
    when(req.getRequestURI()).thenReturn("/a/b");
    assertNotNull(virtualHostResolver.resolveVirtualHost(req));
}
Also used : VirtualHostResolver(com.enonic.xp.web.vhost.VirtualHostResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostMapping(com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping) Test(org.junit.jupiter.api.Test)

Example 7 with VirtualHostMapping

use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.

the class VirtualHostInternalHelperTest method testGetFullTargetPathWithTrailingSlash.

@Test
public void testGetFullTargetPathWithTrailingSlash() {
    final VirtualHostMapping virtualHostMapping = new VirtualHostMapping("host", "foo.no", "/a", "/b/c", VirtualHostIdProvidersMapping.create().build(), 0);
    final HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getRequestURI()).thenReturn("/a/other/service/");
    final String fullTarget = VirtualHostInternalHelper.getFullTargetPath(virtualHostMapping, req);
    assertEquals(fullTarget, "/b/c/other/service/");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostMapping(com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping) Test(org.junit.jupiter.api.Test)

Example 8 with VirtualHostMapping

use of com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping in project xp by enonic.

the class VirtualHostInternalHelperTest method testGetFullTargetPath.

@Test
public void testGetFullTargetPath() {
    final VirtualHostMapping virtualHostMapping = new VirtualHostMapping("host", "foo.no", "/a", "/b/c", VirtualHostIdProvidersMapping.create().build(), 0);
    final HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getRequestURI()).thenReturn("/a/other/service");
    final String fullTarget = VirtualHostInternalHelper.getFullTargetPath(virtualHostMapping, req);
    assertEquals(fullTarget, "/b/c/other/service");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostMapping(com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping) Test(org.junit.jupiter.api.Test)

Aggregations

VirtualHostMapping (com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.jupiter.api.Test)5 VirtualHostResolver (com.enonic.xp.web.vhost.VirtualHostResolver)3 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)1 VirtualHostIdProvidersMapping (com.enonic.xp.web.vhost.impl.mapping.VirtualHostIdProvidersMapping)1 RequestDispatcher (javax.servlet.RequestDispatcher)1