Search in sources :

Example 21 with ExtendedURL

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

the class IntegrationTest method assertURL.

private void assertURL(String url, ResourceType expectedType, ResourceReference expectedReference) throws Exception {
    ExtendedURL extendedURL = new ExtendedURL(new URL(url), "xwiki");
    ResourceType resourceType = this.resourceTypeResolver.resolve(extendedURL, Collections.<String, Object>emptyMap());
    assertEquals(expectedType.getId(), resourceType.getId());
    ResourceReference reference = this.resourceReferenceResolver.resolve(extendedURL, resourceType, Collections.<String, Object>emptyMap());
    assertEquals(expectedReference, reference);
}
Also used : ResourceType(org.xwiki.resource.ResourceType) ResourcesResourceReference(org.xwiki.resource.resources.ResourcesResourceReference) SkinsResourceReference(org.xwiki.resource.skins.SkinsResourceReference) ResourceReference(org.xwiki.resource.ResourceReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 22 with ExtendedURL

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

the class PathWikiReferenceExtractorTest method testAndAssert.

private void testAndAssert(String urlToTest, String expectedWikiId) throws Exception {
    ExtendedURL url = new ExtendedURL(new URL(urlToTest), "xwiki");
    // Remove the resource type (i.e. the first segment) since this is what is expected by the extractor
    url.getSegments().remove(0);
    WikiReference wikiReference = this.mocker.getComponentUnderTest().extract(url);
    assertEquals(new WikiReference(expectedWikiId), wikiReference);
}
Also used : ExtendedURL(org.xwiki.url.ExtendedURL) WikiReference(org.xwiki.model.reference.WikiReference) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 23 with ExtendedURL

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

the class BinEntityResourceReferenceResolverTest method testCreateResource.

private ResourceReference testCreateResource(String testURL, String expectedActionName, EntityReference expectedReference, EntityReference returnedReference, EntityType expectedEntityType) throws Exception {
    when(this.entityReferenceResolver.resolve(expectedReference, expectedEntityType)).thenReturn(returnedReference);
    ExtendedURL extendedURL = new ExtendedURL(new URL(testURL), null);
    // Remove the resource type segment since this is what gets passed to specific Reference Resolvers.
    extendedURL.getSegments().remove(0);
    EntityResourceReference entityResource = this.resolver.resolve(extendedURL, new ResourceType("bin"), Collections.<String, Object>emptyMap());
    assertEquals(expectedActionName, entityResource.getAction().getActionName());
    assertEquals(returnedReference, entityResource.getEntityReference());
    return entityResource;
}
Also used : EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ResourceType(org.xwiki.resource.ResourceType) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 24 with ExtendedURL

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

the class WikiEntityResourceReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    ExtendedURL url = new ExtendedURL(new URL("http://localhost/wiki/somewiki/view/space/page"), null);
    url.getSegments().remove(0);
    when(wikiReferenceExtractor.extract(url)).thenReturn(this.wikiReference);
    EntityReference reference = buildEntityReference("somewiki", "space", "page");
    EntityResourceReference result = (EntityResourceReference) testCreateResource("http://localhost/wiki/somewiki/view/space/page", "view", reference, reference, EntityType.DOCUMENT);
    assertEquals(new DocumentReference("somewiki", "space", "page"), result.getEntityReference());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 25 with ExtendedURL

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

the class VfsResourceReferenceSerializerTest method serializeWhenNoSpecificSchemeSerializer.

@Test
public void serializeWhenNoSpecificSchemeSerializer() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("somescheme:wiki:space.page@attachment"), "path1/path2/test.txt");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "somescheme:wiki:space.page@attachment", "path1", "path2", "test.txt"));
    URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
    when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
    assertEquals("/vfs/somescheme%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
Also used : URLNormalizer(org.xwiki.url.URLNormalizer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

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