View Javadoc

1   package javancss.test;
2   
3   import java.io.File;
4   
5   import ccl.util.FileUtil;
6   import ccl.util.Test;
7   import ccl.util.Util;
8   import ccl.xml.XMLUtil;
9   
10  import javancss.Javancss;
11  import javancss.XmlFormatter;
12  
13  /**
14   * This test class checks that the xml output feature is
15   * working properly.
16   *
17   * @version $Id: XmlFormatterTest.java 121 2009-01-17 22:19:45Z hboutemy $
18   * @author  Chr. Clemens Lee
19   */
20  public class XmlFormatterTest extends AbstractTest {
21      /**
22       * Is it at least possible to properly parse generated xml code?
23       */
24      public void testParsing()
25          throws Exception
26      {
27          Javancss pJavancss = new Javancss( getTestFile( 57 ) );
28          pJavancss.setXML( true );
29  
30          String sXML = XmlFormatter.printStart()
31                 + pJavancss.printPackageNcss()
32                 + pJavancss.printObjectNcss()
33                 + pJavancss.printFunctionNcss()
34                 + pJavancss.printJavaNcss()
35                 + XmlFormatter.printEnd();
36  
37          try
38          {
39              String sText = XMLUtil.getXML( sXML, getXslFile( "xmltest.xsl" ) );
40              Assert( sText.equals( "79" ), sText );
41          }
42          catch( NoClassDefFoundError error )
43          {
44              Util.print( "skipped: 'xalan.jar' and or 'xerces.jar' library missing." );
45          }
46  
47          pJavancss = new Javancss( getTestFile( 117 ) );
48          pJavancss.setXML( true );
49  
50          sXML = XmlFormatter.printStart()
51                 + pJavancss.printPackageNcss()
52                 + pJavancss.printObjectNcss()
53                 + pJavancss.printFunctionNcss()
54                 + pJavancss.printJavaNcss()
55                 + XmlFormatter.printEnd();
56          Assert( Util.isEmpty( sXML ) == false );
57  
58          pJavancss = new Javancss( getTestFile( 118 ) );
59          pJavancss.setXML( true );
60  
61          sXML = XmlFormatter.printStart()
62                 + pJavancss.printPackageNcss()
63                 + pJavancss.printObjectNcss()
64                 + pJavancss.printFunctionNcss()
65                 + pJavancss.printJavaNcss()
66                 + XmlFormatter.printEnd();
67          Assert( Util.isEmpty( sXML ) == false );
68      }
69  
70      /**
71       * Is the transformed XML output identical to the standard ASCI output?
72       */
73      public void testXML2Text()
74          throws Exception
75      {
76          Javancss pJavancss = new Javancss( getTestFile( 32 ) );
77          pJavancss.setXML( true );
78  
79          String sXML = XmlFormatter.printStart()
80                 + pJavancss.printPackageNcss()
81                 + pJavancss.printObjectNcss()
82                 + pJavancss.printFunctionNcss()
83                 + pJavancss.printJavaNcss()
84                 + XmlFormatter.printEnd();
85  
86          try
87          {
88              String sText = XMLUtil.getXML( sXML, getXslFile( "javancss2text.xsl" ) );
89              FileUtil.writeFile( "/tmp/t", sText );
90              String sCompare = FileUtil.readFile( getTestFile( "Output32.txt" ).getAbsolutePath() );
91              Assert( sText.equals( sCompare ), sText );
92          }
93          catch( NoClassDefFoundError error )
94          {
95              Util.print( "skipped: 'xalan.jar' and or 'xerces.jar' library missing." );
96          }
97      }
98  
99      public XmlFormatterTest()
100     {
101         super();
102     }
103 
104     public XmlFormatterTest( Test pTest_ )
105     {
106         super( pTest_ );
107     }
108 
109     private File getXslFile( String filename )
110     {
111         return new File( getTestDir(), ".." + File.separator + "xslt" + File.separator + filename );
112     }
113 
114     /**
115      * Test code goes here.
116      */
117     protected void _doIt()
118         throws Exception
119     {
120         testParsing ();
121         testXML2Text();
122     }
123 
124     public static void main( String[] asArg_ )
125     {
126         new XmlFormatterTest().main();
127     }
128 }