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

File XDOMOfficeDocumentTest.java

 

Code metrics

0
16
2
1
82
34
2
0.12
8
2
1

Classes

Class Line # Actions
XDOMOfficeDocumentTest 38 16 0% 2 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.officeimporter.document;
21   
22    import java.io.StringReader;
23    import java.util.HashMap;
24   
25    import org.junit.Assert;
26   
27    import org.junit.Test;
28    import org.xwiki.officeimporter.internal.AbstractOfficeImporterTest;
29    import org.xwiki.rendering.block.XDOM;
30    import org.xwiki.rendering.parser.Parser;
31   
32    /**
33    * Test case for {@link XDOMOfficeDocument}.
34    *
35    * @version $Id: 59f1cf506799ddd292df0b538094eab5381c03c7 $
36    * @since 2.2.5
37    */
 
38    public class XDOMOfficeDocumentTest extends AbstractOfficeImporterTest
39    {
40    /**
41    * Tests how document title is extracted from the content of the imported document.
42    *
43    * @throws Exception if it fails to extract the title
44    */
 
45  1 toggle @Test
46    public void testTitleExtraction() throws Exception
47    {
48  1 String content = "content before title\n" + "%s Title %s\n" + "content after title.";
49  1 XDOMOfficeDocument doc = createOfficeDocument(String.format(content, "=", "="), "xwiki/2.0");
50  1 Assert.assertEquals("Title", doc.getTitle());
51   
52  1 doc = createOfficeDocument(String.format(content, "==", "=="), "xwiki/2.0");
53  1 Assert.assertEquals("Title", doc.getTitle());
54   
55  1 doc = createOfficeDocument(String.format(content, "===", "==="), "xwiki/2.0");
56  1 Assert.assertEquals("Title", doc.getTitle());
57   
58  1 doc = createOfficeDocument(String.format(content, "====", "===="), "xwiki/2.0");
59  1 Assert.assertEquals("Title", doc.getTitle());
60   
61  1 doc = createOfficeDocument(String.format(content, "=====", "====="), "xwiki/2.0");
62  1 Assert.assertEquals("Title", doc.getTitle());
63   
64  1 doc = createOfficeDocument(String.format(content, "======", "======"), "xwiki/2.0");
65  1 Assert.assertEquals("Title", doc.getTitle());
66    }
67   
68    /**
69    * Creates an {@link XDOMOfficeDocument} by parsing the given content.
70    *
71    * @param content the content to be parsed
72    * @param syntax the syntax of the given content
73    * @return the created {@link XDOMOfficeDocument}
74    * @throws Exception if it fails to parse the given content
75    */
 
76  6 toggle private XDOMOfficeDocument createOfficeDocument(String content, String syntax) throws Exception
77    {
78  6 Parser parser = getComponentManager().getInstance(Parser.class, syntax);
79  6 XDOM xdom = parser.parse(new StringReader(content));
80  6 return new XDOMOfficeDocument(xdom, new HashMap<String, byte[]>(), getComponentManager());
81    }
82    }