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