Search in sources :

Example 1 with FileStringEntityReferenceSerializer

use of org.xwiki.store.internal.FileStringEntityReferenceSerializer 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);
        }
    });
}
Also used : FileStringEntityReferenceSerializer(org.xwiki.store.internal.FileStringEntityReferenceSerializer) FilesystemStoreTools(org.xwiki.store.filesystem.internal.FilesystemStoreTools) ArrayList(java.util.ArrayList) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) AttachmentListMetadataSerializer(org.xwiki.store.serialization.xml.internal.AttachmentListMetadataSerializer) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DummyLockProvider(org.xwiki.store.locks.dummy.internal.DummyLockProvider) File(java.io.File) DocumentReference(org.xwiki.model.reference.DocumentReference) ListAttachmentArchive(org.xwiki.store.legacy.doc.internal.ListAttachmentArchive) AttachmentMetadataSerializer(org.xwiki.store.serialization.xml.internal.AttachmentMetadataSerializer) Before(org.junit.Before)

Example 2 with FileStringEntityReferenceSerializer

use of org.xwiki.store.internal.FileStringEntityReferenceSerializer in project xwiki-platform by xwiki.

the class FilesystemAttachmentStoreTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    getMockery().setImposteriser(ClassImposteriser.INSTANCE);
    Utils.setComponentManager(this.getComponentManager());
    this.mockContext = getMockery().mock(XWikiContext.class);
    final XWiki mockXWiki = getMockery().mock(XWiki.class);
    this.mockHibernate = getMockery().mock(XWikiHibernateStore.class);
    final XWikiAttachmentContent mockDirtyContent = getMockery().mock(XWikiAttachmentContent.class);
    this.mockAttachVersionStore = getMockery().mock(AttachmentVersioningStore.class);
    this.mockArchive = getMockery().mock(XWikiAttachmentArchive.class);
    this.mockHibernateSession = getMockery().mock(Session.class);
    this.doc = new XWikiDocument(new DocumentReference("xwiki", "Main", "WebHome"));
    this.mockAttachReference = new AttachmentReference("file.name", doc.getDocumentReference());
    this.mockAttach = getMockery().mock(XWikiAttachment.class);
    getMockery().checking(new Expectations() {

        {
            allowing(mockContext).getWiki();
            will(returnValue(mockXWiki));
            allowing(mockXWiki).getStore();
            will(returnValue(mockHibernate));
            allowing(mockXWiki).getHibernateStore();
            will(returnValue(mockHibernate));
            allowing(mockHibernate).checkHibernate(mockContext);
            allowing(mockHibernate).beginTransaction(mockContext);
            allowing(mockHibernate).getSession(mockContext);
            will(returnValue(mockHibernateSession));
            allowing(mockXWiki).getDefaultAttachmentArchiveStore();
            will(returnValue(mockAttachVersionStore));
            allowing(mockAttachVersionStore).saveArchive(mockArchive, mockContext, false);
            allowing(mockAttach).getContentInputStream(mockContext);
            will(returnValue(HELLO_STREAM));
            allowing(mockAttach).setDoc(doc);
            allowing(mockAttach).getDoc();
            will(returnValue(doc));
            allowing(mockAttach).getFilename();
            will(returnValue(mockAttachReference.getName()));
            allowing(mockAttach).getReference();
            will(returnValue(mockAttachReference));
            allowing(mockAttach).updateContentArchive(mockContext);
            allowing(mockAttach).getAttachment_archive();
            will(returnValue(mockArchive));
            allowing(mockAttach).isArchiveStoreSet();
            will(returnValue(false));
            allowing(mockAttach).getArchiveStore();
            will(returnValue("file"));
            allowing(mockAttach).getAttachment_content();
            will(returnValue(mockDirtyContent));
            allowing(mockAttach).isContentStoreSet();
            will(returnValue(false));
            allowing(mockAttach).getContentStore();
            will(returnValue("file"));
            allowing(mockAttach).isContentDirty();
            will(returnValue(true));
            allowing(mockDirtyContent).isContentDirty();
            will(returnValue(true));
            allowing(mockAttach).addNameModifiedListener(with(any(AttachmentNameChanged.class)));
            allowing(mockAttach).removeNameModifiedListener(with(any(AttachmentNameChanged.class)));
        }
    });
    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());
    this.attachStore = new FilesystemAttachmentStore();
    FieldUtils.writeField(this.attachStore, "fileTools", this.fileTools, true);
    this.storeFile = this.fileTools.getAttachmentFileProvider(this.mockAttachReference).getAttachmentContentFile();
    HELLO_STREAM.reset();
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) Expectations(org.jmock.Expectations) FileStringEntityReferenceSerializer(org.xwiki.store.internal.FileStringEntityReferenceSerializer) AttachmentVersioningStore(com.xpn.xwiki.store.AttachmentVersioningStore) XWikiAttachmentArchive(com.xpn.xwiki.doc.XWikiAttachmentArchive) FilesystemStoreTools(org.xwiki.store.filesystem.internal.FilesystemStoreTools) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) XWikiAttachmentContent(com.xpn.xwiki.doc.XWikiAttachmentContent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) AttachmentNameChanged(com.xpn.xwiki.doc.XWikiAttachment.AttachmentNameChanged) DummyLockProvider(org.xwiki.store.locks.dummy.internal.DummyLockProvider) File(java.io.File) DocumentReference(org.xwiki.model.reference.DocumentReference) Session(org.hibernate.Session) Before(org.junit.Before)

Aggregations

XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 File (java.io.File)2 Before (org.junit.Before)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 FilesystemStoreTools (org.xwiki.store.filesystem.internal.FilesystemStoreTools)2 FileStringEntityReferenceSerializer (org.xwiki.store.internal.FileStringEntityReferenceSerializer)2 DummyLockProvider (org.xwiki.store.locks.dummy.internal.DummyLockProvider)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 AttachmentNameChanged (com.xpn.xwiki.doc.XWikiAttachment.AttachmentNameChanged)1 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)1 XWikiAttachmentContent (com.xpn.xwiki.doc.XWikiAttachmentContent)1 AttachmentVersioningStore (com.xpn.xwiki.store.AttachmentVersioningStore)1 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)1 ArrayList (java.util.ArrayList)1 Session (org.hibernate.Session)1 Expectations (org.jmock.Expectations)1 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1 ListAttachmentArchive (org.xwiki.store.legacy.doc.internal.ListAttachmentArchive)1