1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.xar

File XarPackageTest.java

 

Code metrics

0
26
3
1
107
65
3
0.12
8.67
3
1

Classes

Class Line # Actions
XarPackageTest 32 26 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 org.xwiki.xar;
21   
22    import java.util.Collection;
23    import java.util.Iterator;
24    import java.util.Locale;
25   
26    import org.junit.Test;
27    import org.xwiki.model.reference.LocalDocumentReference;
28    import org.xwiki.xar.internal.model.XarModel;
29   
30    import static org.junit.Assert.assertEquals;
31   
 
32    public class XarPackageTest
33    {
34    private static final LocalDocumentReference SPACE_PAGE = new LocalDocumentReference("Space", "Page", Locale.ROOT);
35   
36    private static final LocalDocumentReference SPACE_TRANSLATIONS = new LocalDocumentReference("Space",
37    "Translations", Locale.ROOT);
38   
39    private static final LocalDocumentReference SPACE_TRANSLATIONS_FR = new LocalDocumentReference(SPACE_TRANSLATIONS,
40    Locale.FRENCH);
41   
42    private static final LocalDocumentReference SPACE_SKIPPEDPAGE = new LocalDocumentReference("Space", "SkippedPage",
43    Locale.ROOT);
44   
45    private static final LocalDocumentReference SPACE_SKIPPEDTRANSLATIONS = new LocalDocumentReference("Space",
46    "SkippedTranslations", Locale.ROOT);
47   
48    private static final LocalDocumentReference SPACE_SKIPPEDTRANSLATIONS_FR = new LocalDocumentReference(
49    SPACE_SKIPPEDTRANSLATIONS, Locale.FRENCH);
50   
51    private static final LocalDocumentReference SPACE_MERGEDPAGE = new LocalDocumentReference("Space", "MergedPage",
52    Locale.ROOT);
53   
54    private static final LocalDocumentReference SPACE_MERGEDTRANSLATIONS = new LocalDocumentReference("Space",
55    "MergedTranslations", Locale.ROOT);
56   
57    private static final LocalDocumentReference SPACE_MERGEDTRANSLATIONS_FR = new LocalDocumentReference(
58    SPACE_MERGEDTRANSLATIONS, Locale.FRENCH);
59   
 
60  1 toggle @Test
61    public void readDescriptor() throws Exception
62    {
63  1 XarPackage xarPackage = new XarPackage();
64   
65  1 xarPackage.readDescriptor(getClass().getResourceAsStream("/package.xml"));
66   
67  1 assertEquals("author", xarPackage.getPackageAuthor());
68  1 assertEquals("package description", xarPackage.getPackageDescription());
69  1 assertEquals("extension:id", xarPackage.getPackageExtensionId());
70  1 assertEquals("license", xarPackage.getPackageLicense());
71  1 assertEquals("package name", xarPackage.getPackageName());
72  1 assertEquals("1.0", xarPackage.getPackageVersion());
73   
74  1 Collection<XarEntry> files = xarPackage.getPackageFiles();
75   
76  1 assertEquals(9, files.size());
77   
78  1 Iterator<XarEntry> iterator = files.iterator();
79   
80  1 assertEqualsEntry(new XarEntry(SPACE_PAGE, XarModel.ACTION_OVERWRITE), iterator.next());
81  1 assertEqualsEntry(new XarEntry(SPACE_TRANSLATIONS, XarModel.ACTION_OVERWRITE), iterator.next());
82  1 assertEqualsEntry(new XarEntry(SPACE_TRANSLATIONS_FR, XarModel.ACTION_OVERWRITE), iterator.next());
83  1 assertEqualsEntry(new XarEntry(SPACE_SKIPPEDPAGE, XarModel.ACTION_SKIP), iterator.next());
84  1 assertEqualsEntry(new XarEntry(SPACE_MERGEDPAGE, XarModel.ACTION_MERGE), iterator.next());
85  1 assertEqualsEntry(new XarEntry(SPACE_SKIPPEDTRANSLATIONS, XarModel.ACTION_SKIP), iterator.next());
86  1 assertEqualsEntry(new XarEntry(SPACE_SKIPPEDTRANSLATIONS_FR, XarModel.ACTION_SKIP), iterator.next());
87  1 assertEqualsEntry(new XarEntry(SPACE_MERGEDTRANSLATIONS, XarModel.ACTION_MERGE), iterator.next());
88  1 assertEqualsEntry(new XarEntry(SPACE_MERGEDTRANSLATIONS_FR, XarModel.ACTION_MERGE), iterator.next());
89    }
90   
 
91  1 toggle @Test
92    public void readDescriptorWithEmptyId() throws Exception
93    {
94  1 XarPackage xarPackage = new XarPackage();
95   
96  1 xarPackage.readDescriptor(getClass().getResourceAsStream("/packagewithemptyid.xml"));
97   
98  1 assertEquals(null, xarPackage.getPackageExtensionId());
99    }
100   
 
101  9 toggle private void assertEqualsEntry(XarEntry expected, XarEntry actual)
102    {
103  9 assertEquals(expected, actual);
104  9 assertEquals(expected.getEntryName(), actual.getEntryName());
105  9 assertEquals(expected.getDefaultAction(), actual.getDefaultAction());
106    }
107    }