use of org.xwiki.component.util.DefaultParameterizedType 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.component.util.DefaultParameterizedType 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.component.util.DefaultParameterizedType 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.component.util.DefaultParameterizedType 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());
}
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class VfsResourceReferenceHandlerTest method setUp.
private void setUp(String scheme, String wikiName, String spaceName, String pageName, String attachmentName, List<String> path) throws Exception {
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
String attachmentReferenceAsString = String.format("%s:%s:%s.%s@%s", scheme, wikiName, spaceName, pageName, attachmentName);
this.reference = new VfsResourceReference(URI.create(attachmentReferenceAsString), path);
ResourceReferenceSerializer<VfsResourceReference, URI> trueVfsResourceReferenceSerializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), "truevfs");
String truevfsURIFragment = String.format("%s://%s:%s.%s/%s/%s", scheme, wikiName, spaceName, pageName, attachmentName, StringUtils.join(path, '/'));
when(trueVfsResourceReferenceSerializer.serialize(this.reference)).thenReturn(URI.create(truevfsURIFragment));
Provider<XWikiContext> xwikiContextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
XWikiContext xcontext = mock(XWikiContext.class);
when(xwikiContextProvider.get()).thenReturn(xcontext);
XWiki xwiki = mock(XWiki.class);
when(xcontext.getWiki()).thenReturn(xwiki);
DocumentReferenceResolver<String> documentReferenceResolver = mocker.registerMockComponent(DocumentReferenceResolver.TYPE_STRING);
this.documentReference = new DocumentReference(wikiName, Arrays.asList(spaceName), pageName);
String documentReferenceAsString = String.format("%s:%s.%s", wikiName, spaceName, pageName);
when(documentReferenceResolver.resolve(documentReferenceAsString)).thenReturn(this.documentReference);
XWikiDocument document = mock(XWikiDocument.class);
when(xwiki.getDocument(this.documentReference, xcontext)).thenReturn(document);
XWikiAttachment attachment = mock(XWikiAttachment.class);
when(document.getAttachment(attachmentName)).thenReturn(attachment);
when(attachment.getDate()).thenReturn(new Date());
when(attachment.getContentSize(xcontext)).thenReturn(1000);
when(attachment.getContentInputStream(xcontext)).thenReturn(createZipInputStream(StringUtils.join(path, '/'), "success!"));
Container container = this.mocker.getInstance(Container.class);
Response response = mock(Response.class);
when(container.getResponse()).thenReturn(response);
this.baos = new ByteArrayOutputStream();
when(response.getOutputStream()).thenReturn(this.baos);
// Register our custom Attach Driver in TrueVFS
TConfig config = TConfig.current();
// Note: Make sure we add our own Archive Detector to the existing Detector so that all archive formats
// supported by TrueVFS are handled properly.
config.setArchiveDetector(new TArchiveDetector(config.getArchiveDetector(), "attach", new AttachDriver(this.mocker)));
}
Aggregations