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

File PackageTest.java

 

Code metrics

0
33
3
1
106
59
3
0.09
11
3
1

Classes

Class Line # Actions
PackageTest 35 33 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.plugin.packaging;
21   
22    import java.util.Locale;
23   
24    import org.jmock.Mock;
25    import org.xwiki.model.reference.DocumentReference;
26   
27    import com.xpn.xwiki.XWiki;
28    import com.xpn.xwiki.doc.XWikiDocument;
29   
30    /**
31    * Unit tests for the {@link com.xpn.xwiki.plugin.packaging.Package} class.
32    *
33    * @version $Id: 33fde16832358c29951ed00a573cbeaed426ebb1 $
34    */
 
35    public class PackageTest extends AbstractPackageTest
36    {
37    private Package pack;
38   
39    private Mock mockXWiki;
40   
 
41  2 toggle @Override
42    protected void setUp() throws Exception
43    {
44  2 super.setUp();
45  2 this.pack = new Package();
46   
47  2 this.mockXWiki = mock(XWiki.class);
48  2 this.mockXWiki.stubs().method("getEncoding").will(returnValue("UTF-8"));
49  2 this.mockXWiki.stubs().method("checkAccess").will(returnValue(true));
50   
51    // clone calls getVersioningStore but returning null will be satisfactory for the test.
52  2 this.mockXWiki.stubs().method("getVersioningStore").will(returnValue(null));
53   
54  2 getContext().setWiki((XWiki) this.mockXWiki.proxy());
55    }
56   
 
57  1 toggle public void testImportWithHeterogeneousEncodingInFiles() throws Exception
58    {
59  1 String docTitle = "Un \u00e9t\u00e9 36";
60  1 String docContent = "\u00e0\u00e7\u00e9\u00e8\u00c0\u00c7\u00c9\u00c8\u00ef\u00f6\u00eb\u00fc";
61   
62  1 XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Wiki", "Main", "Document1"));
63  1 doc1.setTitle(docTitle);
64  1 doc1.setContent(docContent);
65   
66  1 XWikiDocument doc2 = new XWikiDocument(new DocumentReference("Wiki", "Main", "Document2"));
67  1 doc2.setTitle(docTitle);
68  1 doc2.setContent(docContent);
69   
70  1 XWikiDocument docs[] = { doc1, doc2 };
71   
72  1 this.pack.Import(this.createZipFile(docs, new String[] { "ISO-8859-1", "UTF-8" }, null), getContext());
73   
74  1 assertEquals(2, this.pack.getFiles().size());
75  1 assertEquals(this.pack.getFiles().get(0).getDoc().getTitle(),
76    (this.pack.getFiles().get(1)).getDoc().getTitle());
77  1 assertEquals(this.pack.getFiles().get(0).getDoc().getContent(),
78    this.pack.getFiles().get(1).getDoc().getContent());
79    }
80   
 
81  1 toggle public void testImportWithHeterogeneousEncodingInFilesUsingCommonsCompress() throws Exception
82    {
83  1 String docTitle = "Un \u00e9t\u00e9 36";
84  1 String docContent = "\u00e0\u00e7\u00e9\u00e8\u00c0\u00c7\u00c9\u00c8\u00ef\u00f6\u00eb\u00fc";
85   
86  1 XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Wiki", "Main", "Document1"));
87  1 doc1.setTitle(docTitle);
88  1 doc1.setContent(docContent);
89   
90  1 XWikiDocument doc2 = new XWikiDocument(new DocumentReference("Wiki", "Main", "Document2"));
91  1 doc2.setTitle(docTitle);
92  1 doc2.setContent(docContent);
93   
94  1 XWikiDocument docs[] = { doc1, doc2 };
95   
96  1 this.pack.Import(this.createZipFileUsingCommonsCompress(docs, new String[] { "ISO-8859-1", "UTF-8" }, null),
97    getContext());
98   
99  1 assertEquals(2, this.pack.getFiles().size());
100  1 assertEquals(this.pack.getFiles().get(0).getDoc().getTitle(),
101    (this.pack.getFiles().get(1)).getDoc().getTitle());
102  1 assertEquals(this.pack.getFiles().get(0).getDoc().getContent(),
103    this.pack.getFiles().get(1).getDoc().getContent());
104    }
105   
106    }