1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.xar

File XarPackageTest.java

 

Code metrics

0
27
3
1
111
67
3
0.11
9
3
1

Classes

Class Line # Actions
XarPackageTest 33 27 0% 3 0
1.0100%
 

Contributing tests

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