use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class AttachmentMetadataSerializerTest method testParseSerialize.
@Test
public void testParseSerialize() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(TEST_CONTENT.getBytes("US-ASCII"));
final XWikiAttachment attach = this.serializer.parse(bais);
bais.close();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(this.serializer.serialize(attach), baos);
final String test = new String(baos.toByteArray(), "US-ASCII");
final String control = TEST_CONTENT.replaceAll("[0-9][0-9][0-9]</date>", "000</date>");
Assert.assertEquals("Parsing and serializing yields a different output.", control, test);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class AttachmentMetadataSerializerTest method testParse.
@Test
public void testParse() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(TEST_CONTENT.getBytes("US-ASCII"));
final XWikiAttachment attach = this.serializer.parse(bais);
bais.close();
Assert.assertEquals("Attachment1 had wrong name", "file1", attach.getFilename());
Assert.assertEquals("Attachment1 had wrong author", "me", attach.getAuthor());
Assert.assertEquals("Attachment1 had wrong version", "1.1", attach.getVersion());
Assert.assertEquals("Attachment1 had wrong comment", attach.getComment(), "something whitty");
// We drop milliseconds for consistency with the database so last 3 digits are 0.
Assert.assertEquals("Attachment1 had wrong date.", attach.getDate().getTime() + "", "1293045632000");
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class ListAttachmentArchive method fromRCS.
/**
* @param rcsArchive the RCS archive to import.
* @throws Exception if getting a revision from the RCS archive or deserializing an attachment from XML fails
*/
private void fromRCS(final Archive rcsArchive) throws Exception {
if (rcsArchive == null) {
return;
}
final Node[] nodes = rcsArchive.changeLog();
for (int i = nodes.length - 1; i > -1; i--) {
final Object[] lines = rcsArchive.getRevision(nodes[i].getVersion());
final StringBuilder content = new StringBuilder();
for (int j = 0; j < lines.length; j++) {
String line = lines[j].toString();
content.append(line);
if (j != lines.length - 1) {
content.append("\n");
}
}
final XWikiAttachment rev = new XWikiAttachment();
rev.fromXML(content.toString());
rev.setDoc(getAttachment().getDoc());
rev.setAttachment_archive(this);
// this should not be necessary, keeping to maintain behavior.
rev.setVersion(nodes[i].getVersion().toString());
revisions.add(rev);
}
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class ListAttachmentArchive method clone.
@Override
public Object clone() {
final ListAttachmentArchive out = new ListAttachmentArchive(cloneAttachment(this.attachment));
out.attachment.setAttachment_archive(out);
for (XWikiAttachment revision : this.revisions) {
final XWikiAttachment revClone = cloneAttachment(revision);
revClone.setAttachment_archive(out);
out.revisions.add(revClone);
}
return out;
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class DefaultDocumentRestorerFromAttachedXARTest method restoreDocumentFromAttachedXAR.
@Test
public void restoreDocumentFromAttachedXAR() throws Exception {
// Mocks
XWikiDocument workspaceInstallDoc = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", "WorkspaceManager", "Install")), any(XWikiContext.class))).thenReturn(workspaceInstallDoc);
XWikiAttachment xeXar = mock(XWikiAttachment.class);
when(workspaceInstallDoc.getAttachment("workspace-template.xar")).thenReturn(xeXar);
when(xeXar.getContentInputStream(any(XWikiContext.class))).thenReturn(getClass().getResourceAsStream("/test-restore-documents.xar"));
// Run
mocker.getComponentUnderTest().restoreDocumentFromAttachedXAR(new DocumentReference("mainWiki", "WorkspaceManager", "Install"), "workspace-template.xar", docsToRestore);
// Verify the document to restore has been restored from the xar
verify(docToRestore1).fromXML(any(InputStream.class));
verify(xwiki, times(1)).saveDocument(docToRestore1, xcontext);
verify(docToRestore2).fromXML(any(InputStream.class));
verify(xwiki, times(1)).saveDocument(docToRestore2, xcontext);
}
Aggregations