1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.filter

File XWikiDocumentFilterUtilsTest.java

 

Code metrics

0
8
2
1
89
44
2
0.25
4
2
1

Classes

Class Line # Actions
XWikiDocumentFilterUtilsTest 51 8 0% 2 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 com.xpn.xwiki.internal.filter;
21   
22    import java.io.IOException;
23    import java.net.URL;
24   
25    import org.apache.commons.io.IOUtils;
26    import org.apache.commons.lang3.StringUtils;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.component.internal.ContextComponentManagerProvider;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.filter.FilterException;
32    import org.xwiki.filter.input.DefaultURLInputSource;
33    import org.xwiki.test.annotation.ComponentList;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import com.xpn.xwiki.objects.BaseObject;
37    import com.xpn.xwiki.objects.classes.BaseClass;
38    import com.xpn.xwiki.test.MockitoOldcoreRule;
39    import com.xpn.xwiki.test.component.XWikiDocumentFilterUtilsComponentList;
40   
41    import static org.junit.Assert.assertEquals;
42    import static org.junit.Assert.assertNotNull;
43   
44    /**
45    * Validate {@link XWikiDocumentFilterUtils}.
46    *
47    * @version $Id: 5d0abcc74f159a7f9c1251ee943718b62ba77f55 $
48    */
49    @XWikiDocumentFilterUtilsComponentList
50    @ComponentList(ContextComponentManagerProvider.class)
 
51    public class XWikiDocumentFilterUtilsTest
52    {
53    public final MockitoComponentMockingRule<XWikiDocumentFilterUtils> mocker =
54    new MockitoComponentMockingRule<>(XWikiDocumentFilterUtils.class);
55   
56    @Rule
57    public final MockitoOldcoreRule oldcore = new MockitoOldcoreRule(this.mocker);
58   
 
59  1 toggle private void assertXML(Object entity, String resource) throws FilterException, IOException, ComponentLookupException
60    {
61  1 URL url = getClass().getResource("/filter/xar/" + resource + ".xml");
62   
63  1 assertNotNull(url);
64   
65  1 String expected = IOUtils.toString(url, "UTF-8");
66  1 expected = StringUtils.removeStart(expected, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n\n");
67   
68    // Import
69   
70  1 Object importedEntity =
71    this.mocker.getComponentUnderTest().importEntity(entity, new DefaultURLInputSource(url));
72   
73    // Export
74   
75  1 String actual = this.mocker.getComponentUnderTest().exportEntity(importedEntity);
76   
77    // Validate
78   
79  1 assertEquals(expected, actual);
80    }
81   
82    // Tests
83   
 
84  1 toggle @Test
85    public void class1() throws FilterException, IOException, ComponentLookupException
86    {
87  1 assertXML(BaseClass.class, "class1");
88    }
89    }