View Javadoc

1   package org.apache.maven.doxia.module.fo;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.StringWriter;
23  import java.io.Writer;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * Test FoAggregateSink.
29   *
30   * @author ltheussl
31   * @version $Id: FoAggregateSinkTest.java 1091053 2011-04-11 12:55:07Z ltheussl $
32   */
33  public class FoAggregateSinkTest
34      extends TestCase
35  {
36      private FoAggregateSink sink;
37  
38      private Writer writer;
39  
40      @Override
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45          writer = new StringWriter();
46      }
47  
48      /**
49       * Test of body method, of class FoAggregateSink.
50       */
51      public void testBody()
52      {
53          try
54          {
55              sink = new FoAggregateSink( writer );
56  
57              sink.setDocumentName( "folder/documentName.apt" );
58              sink.setDocumentTitle( "documentTitle" );
59              sink.body();
60              sink.body_();
61          }
62          finally
63          {
64              sink.close();
65          }
66  
67          assertTrue( writer.toString().indexOf( "<fo:block id=\"./folder/documentName\">" ) != -1 );
68      }
69  
70      /**
71       * Test of setDocumentName method, of class FoAggregateSink.
72       */
73      public void testSetDocumentName()
74      {
75          try
76          {
77              sink = new FoAggregateSink( writer );
78  
79              sink.setDocumentName( "folder\\documentName.boo" );
80              sink.body();
81          }
82          finally
83          {
84              sink.close();
85          }
86  
87          assertTrue( writer.toString().indexOf( "<fo:block id=\"./folder/documentName\">" ) != -1 );
88      }
89  
90      /**
91       * Test of figureGraphics method, of class FoAggregateSink.
92       */
93      public void testFigureGraphics()
94      {
95          try
96          {
97              sink = new FoAggregateSink( writer );
98              sink.setDocumentName( "./folder\\docName.xml" );
99              sink.figureGraphics( "./../images/fig.png", null );
100         }
101         finally
102         {
103             sink.close();
104         }
105 
106         assertTrue( writer.toString().indexOf( "<fo:external-graphic src=\"./images/fig.png\"" ) != -1 );
107     }
108 
109     /**
110      * Test of anchor method, of class FoAggregateSink.
111      */
112     public void testAnchor()
113     {
114         try
115         {
116             sink = new FoAggregateSink( writer );
117             sink.anchor( "invalid Anchor" );
118             sink.setDocumentName( "./folder\\docName.xml" );
119             sink.anchor( "validAnchor" );
120         }
121         finally
122         {
123             sink.close();
124         }
125 
126         assertTrue( writer.toString().indexOf( "<fo:inline id=\"#invalid_Anchor\">" ) != -1 );
127         assertTrue( writer.toString().indexOf( "<fo:inline id=\"./folder/docName#validAnchor\">" ) != -1 );
128     }
129 
130     /**
131      * Test of link method, of class FoAggregateSink.
132      */
133     public void testLink()
134     {
135         try
136         {
137             sink = new FoAggregateSink( writer );
138             sink.link( "http://www.example.com/" );
139             sink.text( "http://www.example.com/" );
140             sink.link_();
141             sink.setDocumentName( "./folder\\docName.xml" );
142             sink.link( "#anchor" );
143             sink.text( "#anchor" );
144             sink.link_();
145             sink.link( "./././index.html" );
146             sink.text( "./././index.html" );
147             sink.link_();
148             sink.link( "./../download.html" );
149             sink.text( "./../download.html" );
150             sink.link_();
151             sink.link( ".///test.html" );
152             sink.text( "./test.html" );
153             sink.link_();
154             sink.link( "./whatsnew-1.1.html" );
155             sink.text( "./whatsnew-1.1.html" );
156             sink.link_();
157             sink.setDocumentName( ".///whatsnew-1.1.html" );
158             sink.body();
159             sink.body_();
160         }
161         finally
162         {
163             sink.close();
164         }
165 
166         String result = writer.toString();
167 
168         assertTrue( result.indexOf( "<fo:basic-link external-destination=\"http://www.example.com/\">" ) != -1 );
169         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./folder/docName#anchor\">" ) != -1 );
170         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./folder/index\">" ) != -1 );
171         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./download\">" ) != -1 );
172         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./folder/test\">" ) != -1 );
173         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./folder/whatsnew-1.1\">" ) != -1 );
174         assertTrue( result.indexOf( "<fo:block id=\"./whatsnew-1.1\">" ) != -1 );
175 
176         writer = new StringWriter();
177         try
178         {
179             sink = new FoAggregateSink( writer );
180             sink.setDocumentName( "./subdir/dir/index.html" );
181             sink.link( "../../root.html" );
182             sink.text( "../../root.html" );
183             sink.link_();
184             sink.link( "../../../outside.html" );
185             sink.text( "../../../outside.html" );
186             sink.link_();
187             sink.body();
188             sink.body_();
189         }
190         finally
191         {
192             sink.close();
193         }
194 
195         result = writer.toString();
196 
197         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./root\">" ) != -1 );
198         assertTrue( result.indexOf( "<fo:basic-link internal-destination=\"./outside\">" ) != -1 );
199     }
200 }