Search in sources :

Example 1 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference 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)

Example 2 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceTest method toURI.

@Test
public void toURI() {
    VfsResourceReference reference = new VfsResourceReference(URI.create("scheme:specific"), "a/b");
    URI expected = URI.create("scheme:specific/a/b");
    assertEquals(expected, reference.toURI());
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) URI(java.net.URI) Test(org.junit.Test)

Example 3 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceTest method constructor.

@Test
public void constructor() {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:Sandbox.WebHome@my.zip/path/to/file"));
    assertEquals("attach:Sandbox.WebHome@my.zip", reference.getURI().toString());
    assertEquals("path/to/file", reference.getPath());
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) Test(org.junit.Test)

Example 4 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class PathConverterTest method convertWhenError.

@Test
public void convertWhenError() throws Exception {
    ResourceReferenceSerializer<VfsResourceReference, URI> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), "truevfs");
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:Sandbox.WebHome@my.zip"), "a/b/c");
    when(serializer.serialize(reference)).thenThrow(new SerializeResourceReferenceException("error"));
    try {
        this.mocker.getComponentUnderTest().convert(new DefaultParameterizedType(null, Path.class), "attach:Sandbox.WebHome@my.zip/a/b/c");
        fail("Should have thrown an exception here");
    } catch (ConversionException expected) {
        assertEquals("Failed to convert [attach:Sandbox.WebHome@my.zip/a/b/c] to a Path object", expected.getMessage());
    }
}
Also used : TPath(net.java.truevfs.access.TPath) Path(java.nio.file.Path) ConversionException(org.xwiki.properties.converter.ConversionException) SerializeResourceReferenceException(org.xwiki.resource.SerializeResourceReferenceException) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) URI(java.net.URI) Test(org.junit.Test)

Example 5 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class PathConverterTest method convertWhenNoPermission.

@Test
public void convertWhenNoPermission() throws Exception {
    ResourceReferenceSerializer<VfsResourceReference, URI> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), "truevfs");
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:Sandbox.WebHome@my.zip"), "a/b/c");
    when(serializer.serialize(reference)).thenReturn(URI.create("attach://xwiki:Sandbox.WebHome/my.zip/a/b/c"));
    VfsPermissionChecker permissionChecker = this.mocker.getInstance(VfsPermissionChecker.class, "cascading");
    doThrow(new VfsException("unauthorized")).when(permissionChecker).checkPermission(reference);
    try {
        this.mocker.getComponentUnderTest().convert(new DefaultParameterizedType(null, Path.class), "attach:Sandbox.WebHome@my.zip/a/b/c");
        fail("Should have thrown an exception here");
    } catch (ConversionException expected) {
        assertEquals("Failed to convert [attach:Sandbox.WebHome@my.zip/a/b/c] to a Path object", expected.getMessage());
        assertEquals("VfsException: unauthorized", ExceptionUtils.getRootCauseMessage(expected));
    }
}
Also used : VfsException(org.xwiki.vfs.VfsException) TPath(net.java.truevfs.access.TPath) Path(java.nio.file.Path) ConversionException(org.xwiki.properties.converter.ConversionException) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) VfsPermissionChecker(org.xwiki.vfs.VfsPermissionChecker) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) URI(java.net.URI) Test(org.junit.Test)

Aggregations

VfsResourceReference (org.xwiki.vfs.VfsResourceReference)26 Test (org.junit.Test)19 URI (java.net.URI)11 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)8 ExtendedURL (org.xwiki.url.ExtendedURL)7 TPath (net.java.truevfs.access.TPath)6 VfsException (org.xwiki.vfs.VfsException)6 Path (java.nio.file.Path)5 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ConversionException (org.xwiki.properties.converter.ConversionException)3 SerializeResourceReferenceException (org.xwiki.resource.SerializeResourceReferenceException)3 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)2 URLNormalizer (org.xwiki.url.URLNormalizer)2 VfsManager (org.xwiki.vfs.VfsManager)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1