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.Test;
27  import org.nuiton.jrst.JRST;
28  import org.nuiton.jrst.JRSTAbstractTest;
29  
30  import java.io.File;
31  
32  /**
33   * Test concernant les directives.
34   * 
35   * @author chatellier
36   * @version $Revision$
37   * 
38   * Last update : $Date$
39   * By : $Author$
40   */
41  public class DirectiveTest extends JRSTAbstractTest {
42  
43      /**
44       * Test que les options des directives images sont correctement
45       * parsées.
46       * 
47       * @throws Exception 
48       */
49      @Test
50      public void testImageDirectiveOption() throws Exception {
51          File in = getBugTestFile("testImages21.rst");
52          File out = getOutputTestFile("jrst-testImages.html");
53  //        out.deleteOnExit();
54          new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
55  
56              @Override
57              public void assertJRST(File in, File out) throws Exception {
58                  String content = FileUtils.readFileToString(out, JRST.UTF_8);
59                  log.info(content);
60                  assertTrue(content.indexOf("alt=\"alternate text\"") > 0);
61                  assertTrue(content.indexOf("width=\"200px\"") > 0
62                          || content.indexOf("width=\"200 px\"") > 0);
63                  assertTrue(content.indexOf("align=\"center\"") > 0);
64                  assertTrue(content.indexOf("alt=\"tab alternate text\"") > 0);
65                  // scale
66                  assertTrue(content.indexOf("alt=\"tab alternate text\"") > 0);
67                  //assertTrue(content.indexOf("width=\"49%\" height=\"49%\"") > 0);
68              }
69          };
70      }
71      
72      /**
73       * Test que le titre d'un content n'est pas perdu.
74       * 
75       * @throws Exception
76       */
77      @Test
78      public void testContentDirective() throws Exception {
79          File in = getBugTestFile("testContent877.rst");
80          File out = getOutputTestFile("jrst-testContent.html");
81  //        out.deleteOnExit();
82  
83          new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
84  
85              @Override
86              public void assertJRST(File in, File out) throws Exception {
87                  String content = FileUtils.readFileToString(out, JRST.UTF_8);
88                  assertTrue(content.indexOf("Table des matières") > 0);
89              }
90          };
91      }
92      
93      /**
94       * Test strong and emphasis in title.
95       * 
96       * @throws Exception
97       */
98      @Test
99      public void testContentsDirective() throws Exception {
100         File in = getBugTestFile("testContents.rst");
101         File out = getOutputTestFile("jrst-testContents.html");
102 //        out.deleteOnExit();
103 
104         new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) {
105 
106             @Override
107             public void assertJRST(File in, File out) throws Exception {
108                 String content = FileUtils.readFileToString(out, JRST.UTF_8);
109                 assertTrue(content.indexOf("<b>") > 0);
110                 assertTrue(content.indexOf("<em>") > 0);
111             }
112         };
113     }
114 }