Search in sources :

Example 41 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class ExtendedURLURLNormalizerTest method normalizeWhenRootWebapp.

@Test
public void normalizeWhenRootWebapp() throws Exception {
    when(this.configurationSource.getProperty("xwiki.webapppath")).thenReturn("");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"));
    assertEquals("/one/two", this.mocker.getComponentUnderTest().normalize(extendedURL).serialize());
}
Also used : ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 42 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class ExtendedURLURLNormalizerTest method normalizeWhenConfigurationPropertyDefined.

@Test
public void normalizeWhenConfigurationPropertyDefined() throws Exception {
    when(this.configurationSource.getProperty("xwiki.webapppath")).thenReturn("xwiki");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"));
    assertEquals("/xwiki/one/two", this.mocker.getComponentUnderTest().normalize(extendedURL).serialize());
}
Also used : ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 43 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class ExtendedURLURLNormalizerTest method normalizeWhenNoConfigurationPropertyAndNoServletEnvironment.

@Test
public void normalizeWhenNoConfigurationPropertyAndNoServletEnvironment() throws Exception {
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"));
    try {
        this.mocker.getComponentUnderTest().normalize(extendedURL);
        fail("Should have thrown an exception");
    } catch (RuntimeException expected) {
        assertEquals("Failed to normalize the URL [/one/two] since the application's Servlet context couldn't be " + "computed.", expected.getMessage());
    }
}
Also used : ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 44 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class ExtendedURLURLNormalizerTest method normalizeWhenNoConfigurationPropertyButEnvironmentWithRootContext.

@Test
public void normalizeWhenNoConfigurationPropertyButEnvironmentWithRootContext() throws Exception {
    ServletContext sc = mock(ServletContext.class);
    ServletEnvironment environment = mock(ServletEnvironment.class);
    this.mocker.registerComponent(Environment.class, environment);
    when(environment.getServletContext()).thenReturn(sc);
    when(sc.getContextPath()).thenReturn("");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"));
    assertEquals("/one/two", this.mocker.getComponentUnderTest().normalize(extendedURL).serialize());
}
Also used : ServletContext(javax.servlet.ServletContext) ServletEnvironment(org.xwiki.environment.internal.ServletEnvironment) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 45 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class AbstractResourceReferenceResolver method findResourceResolver.

/**
 * Find the right Resolver for the passed Resource type and call it.
 */
protected ResourceReferenceResolver<ExtendedURL> findResourceResolver(String hintPrefix, ResourceType type) throws UnsupportedResourceReferenceException {
    ResourceReferenceResolver<ExtendedURL> resolver;
    Type roleType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
    String roleHint = computeResolverHint(hintPrefix, type.getId());
    // Step 1: Look for a Resolver specific to the scheme and specific to the Resource Type
    if (this.componentManager.hasComponent(roleType, roleHint)) {
        try {
            resolver = this.componentManager.getInstance(roleType, roleHint);
        } catch (ComponentLookupException cle) {
            // There's no Resolver registered for the passed Resource Type
            throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for hint [%s]", roleHint), cle);
        }
    } else {
        // schemes
        try {
            resolver = this.componentManager.getInstance(roleType, type.getId());
        } catch (ComponentLookupException cle) {
            // There's no Resolver registered for the passed Resource Type
            throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for type [%s]", type), cle);
        }
    }
    return resolver;
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) ResourceType(org.xwiki.resource.ResourceType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Aggregations

ExtendedURL (org.xwiki.url.ExtendedURL)46 Test (org.junit.Test)26 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 ResourceType (org.xwiki.resource.ResourceType)10 URL (java.net.URL)9 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)7 HashMap (java.util.HashMap)6 List (java.util.List)6 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)6 ServletException (javax.servlet.ServletException)5 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)5 IOException (java.io.IOException)4 Type (java.lang.reflect.Type)3 ExtensionId (org.xwiki.extension.ExtensionId)3 InstalledExtension (org.xwiki.extension.InstalledExtension)3 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ResourceReference (org.xwiki.resource.ResourceReference)3