1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.store

File VoidAttachmentVersioningStoreTest.java

 

Code metrics

0
28
3
1
90
52
3
0.11
9.33
3
1

Classes

Class Line # Actions
VoidAttachmentVersioningStoreTest 38 28 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.store;
21   
22    import org.suigeneris.jrcs.rcs.Version;
23    import org.xwiki.model.reference.DocumentReference;
24   
25    import com.xpn.xwiki.XWiki;
26    import com.xpn.xwiki.XWikiException;
27    import com.xpn.xwiki.doc.XWikiAttachment;
28    import com.xpn.xwiki.doc.XWikiAttachmentArchive;
29    import com.xpn.xwiki.doc.XWikiDocument;
30    import com.xpn.xwiki.store.VoidAttachmentVersioningStore.VoidAttachmentArchive;
31    import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase;
32   
33    /**
34    * Unit tests for {@link VoidAttachmentVersioningStore} and {@link VoidAttachmentArchive}.
35    *
36    * @version $Id: ac12049a0869102c96a921de5b4e5da7c0fdc7f6 $
37    */
 
38    public class VoidAttachmentVersioningStoreTest extends AbstractBridgedXWikiComponentTestCase
39    {
40    AttachmentVersioningStore store;
41   
 
42  2 toggle @Override
43    protected void setUp() throws Exception
44    {
45  2 super.setUp();
46  2 XWiki xwiki = new XWiki();
47  2 getContext().setWiki(xwiki);
48   
49  2 this.store = getComponentManager().getInstance(AttachmentVersioningStore.class, "void");
50  2 xwiki.setAttachmentVersioningStore(this.store);
51    }
52   
 
53  1 toggle public void testStore() throws XWikiException
54    {
55    // is store correctly inited?
56  1 assertEquals(VoidAttachmentVersioningStore.class, this.store.getClass());
57    // create doc, attachment & attachment archive
58  1 XWikiDocument doc = new XWikiDocument(new DocumentReference("Wiki", "Main", "Test"));
59  1 XWikiAttachment attachment = new XWikiAttachment(doc, "filename");
60  1 attachment.setContent(new byte[] {1});
61  1 attachment.updateContentArchive(getContext());
62    // is archive correctly inited and cloneable?
63  1 this.store.saveArchive(attachment.getAttachment_archive(), this.getContext(), true);
64  1 XWikiAttachmentArchive archive = this.store.loadArchive(attachment, this.getContext(), false);
65  1 assertEquals(VoidAttachmentArchive.class, archive.getClass());
66  1 assertEquals(VoidAttachmentArchive.class, archive.clone().getClass());
67  1 assertEquals(archive, this.store.loadArchive(attachment, this.getContext(), true));
68   
69  1 this.store.deleteArchive(attachment, getContext(), true);
70    }
71   
 
72  1 toggle public void testHistory() throws XWikiException
73    {
74  1 XWikiDocument doc = new XWikiDocument(new DocumentReference("Wiki", "Main", "Test"));
75  1 XWikiAttachment attachment = new XWikiAttachment(doc, "filename");
76    // 1.1
77  1 attachment.setContent(new byte[] {1});
78  1 attachment.updateContentArchive(this.getContext());
79  1 assertEquals(attachment, attachment.getAttachmentRevision("1.1", this.getContext()));
80    // 1.2
81  1 attachment.setContent(new byte[] {2});
82  1 attachment.updateContentArchive(this.getContext());
83  1 assertEquals(attachment, attachment.getAttachmentRevision("1.2", this.getContext()));
84    // there should be only 1.2 version.
85  1 assertNull(attachment.getAttachmentRevision("1.1", this.getContext()));
86  1 assertNull(attachment.getAttachmentRevision("1.3", this.getContext()));
87  1 assertEquals(1, attachment.getVersions().length);
88  1 assertEquals(new Version(1, 2), attachment.getVersions()[0]);
89    }
90    }