View Javadoc
1   /*
2    * #%L
3    * JRst :: Api
4    * %%
5    * Copyright (C) 2011 Codelutin, Chatellier Eric
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  
23  package org.nuiton.jrst.bugs;
24  
25  import org.apache.commons.io.FileUtils;
26  import org.junit.Ignore;
27  import org.junit.Test;
28  import org.nuiton.jrst.JRST;
29  import org.nuiton.jrst.JRSTAbstractTest;
30  
31  import java.io.File;
32  import java.util.regex.Matcher;
33  import java.util.regex.Pattern;
34  
35  /**
36   * Test sur les elements de type text (liens, styles...)
37   * 
38   * @author chatellier
39   * @version $Revision$
40   * 
41   * Last update : $Date$
42   * By : $Author$
43   */
44  public class TextTest extends JRSTAbstractTest {
45  
46      /**
47       * Test que les liens avec parametres sont correctement parsés.
48       * 
49       * @throws Exception 
50       */
51      @Test
52      public void testLinksParameters() throws Exception {
53          File in = getBugTestFile("testLinks.rst");
54          File out = getOutputTestFile("jrst-testLinks.html");
55  
56          new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
57  
58              @Override
59              public void assertJRST(File in, File out) throws Exception {
60                  String content = FileUtils.readFileToString(out, JRST.UTF_8);
61                  assertTrue(content.indexOf("href=\"http://labs.libre-entreprise.org/tracker/?atid=113&amp;group_id=8&amp;func=browse\"") > 0);
62                  assertTrue(content.indexOf("href=\"http://www.docbook.org/\"") > 0);
63                  assertTrue(content.indexOf("href=\"http://www.docbook2.org/\"") > 0);
64              }
65          };
66      }
67  
68      /**
69       * Test que les caracteres speciaux dans les label des liens
70       * ne sont pas perdus.
71       * 
72       * @throws Exception
73       */
74      @Test
75      public void testLinksSpecialCharacters() throws Exception {
76          File in = getBugTestFile("testLinks1380.rst");
77          File out = getOutputTestFile("jrst-testLinks.html");
78  
79          new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
80  
81              @Override
82              public void assertJRST(File in, File out) throws Exception {
83                  String content = FileUtils.readFileToString(out, JRST.UTF_8);
84                  assertTrue(content.indexOf("nuiton's forge") > 0);
85                  assertTrue(content.indexOf("build.xml") > 0);
86              }
87          };
88      }
89  
90      /**
91       * Test que la presence de caractere "tabulation" ne cause
92       * pas d'exception lors de la generation.
93       * 
94       * @throws Exception 
95       */
96      @Test
97      public void testTabCharacter() throws Exception {
98          File in = getBugTestFile("testTab1378.rst");
99          File out = getOutputTestFile("jrst-testTab1378.html");
100 
101         new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
102 
103             @Override
104             public void assertJRST(File in, File out) throws Exception {
105                 String content = FileUtils.readFileToString(out, JRST.UTF_8);
106                 Pattern pattern = Pattern.compile(".*<blockquote>.*du bla bla \u00E9l\u00E9mentaire.*</blockquote>.*", Pattern.DOTALL);
107                 Matcher matcher = pattern.matcher(content);
108                 assertTrue(matcher.find());
109             }
110         };
111     }
112 
113     /**
114      * Test que les synthaxe options sont bien parsées.
115      * @throws Exception 
116      */
117     @Test
118     public void testOptionLists() throws Exception {
119         File in = getBugTestFile("testOptionsList644.rst");
120         File out = getOutputTestFile("jrst-testOptionList644.html");
121 
122         new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
123 
124             @Override
125             public void assertJRST(File in, File out) throws Exception {
126                 String content = FileUtils.readFileToString(out, JRST.UTF_8);
127                 assertTrue(content.indexOf("<span class=\"option\">-a</span>") > 0);
128                 assertTrue(content.indexOf("<p>options can have arguments\nand long descriptions</p>") > 0
129                         ||content.indexOf("<p>options can have arguments and long descriptions</p>") > 0);
130                 assertTrue(content.indexOf("&lt;v3region.zip|v2region.xml|v2region.xml.gz&gt;") > 0);
131                 assertTrue(content.indexOf("<span class=\"option\">/V</span>") > 0);
132                 assertTrue(content.indexOf("<p>DOS/VMS-style options too</p>") > 0);
133             }
134         };
135     }
136     
137     /**
138      * Test que les echapements de lien fonctionne.
139      * 
140      * \param_
141      * 
142      * @throws Exception
143      */
144     @Test
145     @Ignore
146     public void testLinkEscape() throws Exception {
147         File in = getBugTestFile("testLinks.rst");
148         File out = getOutputTestFile("jrst-testLinks.html");
149 
150         new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
151 
152             @Override
153             public void assertJRST(File in, File out) throws Exception {
154                 String content = FileUtils.readFileToString(out, JRST.UTF_8);
155                 assertTrue(content.indexOf("echapement de lien1_") > 0);
156                 assertTrue(content.indexOf("echapement de *.txt") > 0);
157             }
158         };
159     }
160     
161     /**
162      * Test embedded links.
163      * 
164      * @throws Exception 
165      */
166     @Test
167     public void testEmbededURIs() throws Exception {
168         File in = getBugTestFile("testEmbeddedURIs.rst");
169         File out = getOutputTestFile("jrst-testEmbeddedURIs.html");
170 
171         new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
172 
173             @Override
174             public void assertJRST(File in, File out) throws Exception {
175                 String content = FileUtils.readFileToString(out, JRST.UTF_8);
176                 assertTrue(content.contains("href=\"http://www.python.org\""));
177                 assertTrue(content.contains("href=\"./python\""));
178                 assertTrue(content.contains("href=\"http://www.rfc-editor.org/rfc/rfc2396.txt\""));
179                 assertTrue(content.contains("href=\"http://www.rfc-editor.org/rfc/rfc2732.txt\""));
180             }
181         };
182     }
183 
184 }