Search in sources :

Example 31 with ExtendedURL

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

the class VfsResourceReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("attach:wiki:space.page@attachment", "path1", "path2", "test.txt"), Collections.singletonMap("key", Arrays.asList("value")));
    VfsResourceReference reference = this.mocker.getComponentUnderTest().resolve(extendedURL, VfsResourceReference.TYPE, Collections.<String, Object>emptyMap());
    VfsResourceReference expected = new VfsResourceReference(URI.create("attach:wiki:space.page@attachment"), "path1/path2/test.txt");
    expected.addParameter("key", "value");
    assertEquals(expected, reference);
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 32 with ExtendedURL

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

the class VfsResourceReferenceSerializerTest method serializeWhenSpecificSchemeSerializer.

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

Example 33 with ExtendedURL

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

the class AttachVfsResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:attachment"), "path1/path2/test.txt");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "attach: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);
    AttachmentReferenceResolver<String> attachmentResolver = this.mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
    AttachmentReference attachmentReference = new AttachmentReference("attachment", new DocumentReference("wiki", Arrays.asList("space"), "page"));
    when(attachmentResolver.resolve("attachment")).thenReturn(attachmentReference);
    EntityReferenceSerializer<String> entitySerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    when(entitySerializer.serialize(attachmentReference)).thenReturn("wiki:space.page@attachment");
    assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) URLNormalizer(org.xwiki.url.URLNormalizer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 34 with ExtendedURL

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

the class DefaultVfsManagerTest method getURL.

@Test
public void getURL() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
    ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, ExtendedURL.class));
    when(serializer.serialize(reference)).thenReturn(new ExtendedURL(Arrays.asList("generated", "url")));
    assertEquals("/generated/url", this.mocker.getComponentUnderTest().getURL(reference));
}
Also used : ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Example 35 with ExtendedURL

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

the class DefaultVfsManagerTest method getURLerror.

@Test
public void getURLerror() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
    ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, ExtendedURL.class));
    when(serializer.serialize(reference)).thenThrow(new SerializeResourceReferenceException("error"));
    try {
        this.mocker.getComponentUnderTest().getURL(reference);
        fail("Should have thrown an exception");
    } catch (VfsException expected) {
        assertEquals("Failed to compute URL for [uri = [attach:xwiki:space.page@attachment], " + "path = [path1/path2/test.txt], parameters = []]", expected.getMessage());
    }
}
Also used : VfsException(org.xwiki.vfs.VfsException) SerializeResourceReferenceException(org.xwiki.resource.SerializeResourceReferenceException) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) 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