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