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

File XarFileTest.java

 

Code metrics

0
18
2
1
98
60
4
0.22
9
2
2

Classes

Class Line # Actions
XarFileTest 42 18 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.io.File;
23    import java.io.IOException;
24    import java.util.Date;
25    import java.util.Iterator;
26    import java.util.Locale;
27   
28    import org.junit.jupiter.api.BeforeEach;
29    import org.junit.jupiter.api.Test;
30    import org.xwiki.extension.ExtensionId;
31    import org.xwiki.extension.test.ExtensionPackager;
32    import org.xwiki.model.reference.LocalDocumentReference;
33    import org.xwiki.xar.internal.model.XarModel;
34   
35    import static org.junit.jupiter.api.Assertions.assertEquals;
36   
37    /**
38    * Validate {@link XarFile}.
39    *
40    * @version $Id: d525d211815b5401f23b7ec738efe29e08d3abe7 $
41    */
 
42    public class XarFileTest
43    {
44    private static final LocalDocumentReference A_PAGE = new LocalDocumentReference("a", "page", Locale.ROOT);
45   
46    private static final LocalDocumentReference A_EN = new LocalDocumentReference("a", "en", Locale.ENGLISH);
47   
48    private static final LocalDocumentReference X_PAGE = new LocalDocumentReference("x", "page", Locale.ROOT);
49   
50    private static final LocalDocumentReference X_EN = new LocalDocumentReference("x", "en", Locale.ENGLISH);
51   
52    private static final LocalDocumentReference Z_PAGE = new LocalDocumentReference("z", "page", Locale.ROOT);
53   
54    private static final LocalDocumentReference Z_EN = new LocalDocumentReference("z", "en", Locale.ENGLISH);
55   
56    private ExtensionPackager extensionPackager;
57   
 
58  1 toggle @BeforeEach
59    public void beforeEach() throws IOException
60    {
61  1 this.extensionPackager = new ExtensionPackager(null, new File("target/test-" + new Date().getTime()));
62  1 this.extensionPackager.generateExtensions();
63    }
64   
 
65  1 toggle @Test
66    public void XarFile() throws XarException, IOException
67    {
68  1 try (XarFile file = new XarFile(extensionPackager.getExtensionFile(new ExtensionId("xar1", "1.0")))) {
69  1 assertEquals(6, file.getEntries().size());
70   
71  1 XarPackageTest.assertEqualsEntry(new XarEntry(A_EN, "a/en.xml", XarModel.ACTION_MERGE, "type1"),
72    file.getEntry(A_EN));
73  1 XarPackageTest.assertEqualsEntry(new XarEntry(A_PAGE, "a/page.xml", XarModel.ACTION_SKIP, "type0"),
74    file.getEntry(A_PAGE));
75  1 XarPackageTest.assertEqualsEntry(new XarEntry(X_EN, "x/en.xml", XarModel.ACTION_MERGE, "type1"),
76    file.getEntry(X_EN));
77  1 XarPackageTest.assertEqualsEntry(new XarEntry(X_PAGE, "x/page.xml", XarModel.ACTION_SKIP, "type0"),
78    file.getEntry(X_PAGE));
79  1 XarPackageTest.assertEqualsEntry(new XarEntry(Z_EN, "z/en.xml", XarModel.ACTION_SKIP), file.getEntry(Z_EN));
80  1 XarPackageTest.assertEqualsEntry(new XarEntry(Z_PAGE, "z/page.xml", XarModel.ACTION_SKIP),
81    file.getEntry(Z_PAGE));
82   
83  1 Iterator<XarEntry> packageFilesIterator = file.getXarPackage().getPackageFiles().iterator();
84  1 XarPackageTest.assertEqualsEntry(new XarEntry(A_EN, "a/en.xml", XarModel.ACTION_MERGE, "type1"),
85    packageFilesIterator.next());
86  1 XarPackageTest.assertEqualsEntry(new XarEntry(A_PAGE, "a/page.xml", XarModel.ACTION_SKIP, "type0"),
87    packageFilesIterator.next());
88  1 XarPackageTest.assertEqualsEntry(new XarEntry(X_PAGE, "x/page.xml", XarModel.ACTION_SKIP, "type0"),
89    packageFilesIterator.next());
90  1 XarPackageTest.assertEqualsEntry(new XarEntry(X_EN, "x/en.xml", XarModel.ACTION_MERGE, "type1"),
91    packageFilesIterator.next());
92  1 XarPackageTest.assertEqualsEntry(new XarEntry(Z_EN, "z/en.xml", XarModel.ACTION_SKIP),
93    packageFilesIterator.next());
94  1 XarPackageTest.assertEqualsEntry(new XarEntry(Z_PAGE, "z/page.xml", XarModel.ACTION_SKIP),
95    packageFilesIterator.next());
96    }
97    }
98    }