use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class AttachmentListMetadataSerializer method serialize.
@Override
public void serialize(final List<XWikiAttachment> attachments, final XMLWriter writer) throws IOException {
final Element docel = new DOMElement(ROOT_ELEMENT_NAME);
docel.addAttribute(SERIALIZER_PARAM, THIS_SERIALIZER);
writer.writeOpen(docel);
for (XWikiAttachment attachment : attachments) {
this.attachSerializer.serialize(attachment, writer);
}
writer.writeClose(docel);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class FilesystemAttachmentStoreTest method documentUpdateOnDeleteTest.
@Test
public void documentUpdateOnDeleteTest() throws Exception {
final List<XWikiAttachment> attachList = new ArrayList<XWikiAttachment>();
attachList.add(this.mockAttach);
this.doc.setAttachmentList(attachList);
getMockery().checking(new Expectations() {
{
oneOf(mockAttachVersionStore).deleteArchive(mockAttach, mockContext, false);
exactly(2).of(mockHibernateSession).delete(with(any(Object.class)));
oneOf(mockHibernate).saveXWikiDoc(doc, mockContext, false);
will(new CustomAction("Make sure the attachment has been removed from the list.") {
public Object invoke(final Invocation invoc) {
final XWikiDocument document = (XWikiDocument) invoc.getParameter(0);
Assert.assertTrue("Attachment was not removed from the list.", document.getAttachmentList().size() == 0);
return null;
}
});
}
});
this.createFile();
this.attachStore.deleteXWikiAttachment(this.mockAttach, true, this.mockContext, false);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class FilesystemAttachmentVersioningStoreTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
Utils.setComponentManager(this.getComponentManager());
final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
this.storageLocation = new File(tmpDir, "test-storage-location");
this.fileTools = new FilesystemStoreTools(new FileStringEntityReferenceSerializer(), storageLocation, new DummyLockProvider());
final AttachmentListMetadataSerializer serializer = new AttachmentListMetadataSerializer(new AttachmentMetadataSerializer());
this.versionStore = new FilesystemAttachmentVersioningStore();
FieldUtils.writeDeclaredField(this.versionStore, "fileTools", this.fileTools, true);
FieldUtils.writeDeclaredField(this.versionStore, "metaSerializer", serializer, true);
final XWikiDocument doc = new XWikiDocument(new DocumentReference("xwiki", "Main", "WebHome"));
final XWikiAttachment version1 = new XWikiAttachment();
version1.setVersion("1.1");
version1.setFilename("attachment.txt");
version1.setDoc(doc);
version1.setAttachment_content(new StringAttachmentContent("I am version 1.1"));
final XWikiAttachment version2 = new XWikiAttachment();
version2.setVersion("1.2");
version2.setFilename("attachment.txt");
version2.setDoc(doc);
version2.setAttachment_content(new StringAttachmentContent("I am version 1.2"));
final XWikiAttachment version3 = new XWikiAttachment();
version3.setVersion("1.3");
version3.setFilename("attachment.txt");
version3.setDoc(doc);
version3.setAttachment_content(new StringAttachmentContent("I am version 1.3"));
this.provider = this.fileTools.getAttachmentFileProvider(version1.getReference());
this.archive = new ListAttachmentArchive(new ArrayList<XWikiAttachment>() {
{
add(version1);
add(version2);
add(version3);
}
});
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class FilesystemAttachmentVersioningStoreTest method saveArchiveTest.
@Test
public void saveArchiveTest() throws Exception {
final XWikiAttachmentContent content = this.archive.getAttachment().getAttachment_content();
final XWikiAttachment attach = this.archive.getAttachment();
Assert.assertFalse(this.provider.getAttachmentVersioningMetaFile().exists());
Assert.assertFalse(this.provider.getAttachmentVersionContentFile("1.1").exists());
Assert.assertFalse(this.provider.getAttachmentVersionContentFile("1.2").exists());
Assert.assertFalse(this.provider.getAttachmentVersionContentFile("1.3").exists());
// Because the context is only used by the legacy implementation, it is safe to pass null.
this.versionStore.saveArchive(this.archive, null, false);
Assert.assertTrue(this.provider.getAttachmentVersioningMetaFile().exists());
// Make sure it's not just:
// <?xml version="1.0" encoding="UTF-8"?>
// <attachment-list serializer="attachment-list-meta/1.0">
// </attachment-list>
Assert.assertTrue(this.provider.getAttachmentVersioningMetaFile().length() > 120);
Assert.assertTrue(this.provider.getAttachmentVersionContentFile("1.1").exists());
Assert.assertTrue(this.provider.getAttachmentVersionContentFile("1.2").exists());
Assert.assertTrue(this.provider.getAttachmentVersionContentFile("1.3").exists());
// Prove that the attachment and attachment content are the same after saving.
Assert.assertSame(attach, this.archive.getAttachment());
Assert.assertSame(content, this.archive.getAttachment().getAttachment_content());
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class AttachmentListMetadataSerializerTest method testParse.
@Test
public void testParse() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(TEST_CONTENT.getBytes("US-ASCII"));
final List<XWikiAttachment> attachList = this.serializer.parse(bais);
bais.close();
Assert.assertTrue("Attachment list was wrong size", 3 == attachList.size());
Assert.assertEquals("Attachment1 had wrong name", "file1", attachList.get(0).getFilename());
Assert.assertEquals("Attachment2 had wrong name", "file1", attachList.get(1).getFilename());
Assert.assertEquals("Attachment3 had wrong name", "file1", attachList.get(2).getFilename());
Assert.assertEquals("Attachment1 had wrong author", "me", attachList.get(0).getAuthor());
Assert.assertEquals("Attachment2 had wrong author", "you", attachList.get(1).getAuthor());
Assert.assertEquals("Attachment3 had wrong author", "them", attachList.get(2).getAuthor());
Assert.assertEquals("Attachment1 had wrong version", "1.1", attachList.get(0).getVersion());
Assert.assertEquals("Attachment2 had wrong version", "1.2", attachList.get(1).getVersion());
Assert.assertEquals("Attachment3 had wrong version", "1.3", attachList.get(2).getVersion());
Assert.assertEquals("Attachment1 had wrong comment", attachList.get(0).getComment(), "something whitty");
Assert.assertEquals("Attachment2 had wrong comment", "a comment", attachList.get(1).getComment());
Assert.assertEquals("Attachment3 had wrong comment", "i saved it", attachList.get(2).getComment());
// We drop milliseconds for consistency with the database so last 3 digits are 0.
Assert.assertEquals("Attachment1 had wrong date.", attachList.get(0).getDate().getTime() + "", "1293045632000");
Assert.assertEquals("Attachment2 had wrong date.", attachList.get(1).getDate().getTime() + "", "1293789456000");
Assert.assertEquals("Attachment3 had wrong date.", attachList.get(2).getDate().getTime() + "", "1293012345000");
}
Aggregations