use of org.xwiki.vfs.VfsResourceReference 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());
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class PathConverterTest method convertWhenOk.
@Test
public void convertWhenOk() 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"));
Path path = this.mocker.getComponentUnderTest().convert(new DefaultParameterizedType(null, Path.class), "attach:Sandbox.WebHome@my.zip/a/b/c");
assertEquals("attach://xwiki:Sandbox.WebHome/my.zip/a/b/c", path.toString());
assertEquals(TPath.class.getName(), path.getClass().getName());
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class VfsScriptServiceTest method url.
@Test
public void url() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
VfsManager manager = this.mocker.getInstance(VfsManager.class);
when(manager.getURL(reference)).thenReturn("/generated/url");
assertEquals("/generated/url", this.mocker.getComponentUnderTest().url(new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt")));
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class CascadingVfsPermissionCheckerTest method checkPermissionWithAttachSchemeChecker.
@Test
public void checkPermissionWithAttachSchemeChecker() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:whatever"), "whatever");
AttachmentReferenceResolver<String> resolver = this.mocker.registerMockComponent(AttachmentReferenceResolver.TYPE_STRING);
DocumentReference attachmentDocumentReference = new DocumentReference("wiki", "space", "page");
AttachmentReference attachmentReference = new AttachmentReference("file", attachmentDocumentReference);
when(resolver.resolve("whatever")).thenReturn(attachmentReference);
ContextualAuthorizationManager authorizationManager = this.mocker.registerMockComponent(ContextualAuthorizationManager.class);
when(authorizationManager.hasAccess(Right.VIEW, attachmentReference)).thenReturn(true);
this.mocker.getComponentUnderTest().checkPermission(reference);
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class CascadingVfsPermissionCheckerTest method checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed.
@Test
public void checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("customscheme:whatever"), "whatever");
AuthorizationManager authorizationManager = this.mocker.registerMockComponent(AuthorizationManager.class);
when(authorizationManager.hasAccess(Right.PROGRAM, this.contextUser, null)).thenReturn(false);
try {
this.mocker.getComponentUnderTest().checkPermission(reference);
fail("Should have raised exception");
} catch (VfsException expected) {
assertEquals("Current logged-in user ([" + this.contextUser + "]) needs to have Programming Rights to use the [customscheme] VFS", expected.getMessage());
}
}
Aggregations