Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

XmlToolTest.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc.test;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import java.io.*;
00023 import java.sql.*;
00024 import java.util.*;
00025 import javax.xml.transform.stream.*;
00026 import javax.xml.transform.*;
00027 import junit.framework.*;
00028 import net.threebit.utils.sosc.*;
00029 import java.util.logging.*;
00030 
00035 public class XmlToolTest extends TestCase {
00036 
00037         public void test1() throws Exception {
00038 
00039                 final PipedInputStream pi = new PipedInputStream();
00040                 final PipedOutputStream po = new PipedOutputStream(pi);
00041                 final Map signal = new HashMap();
00042                 signal.put("blah","blah");
00043 
00044                 Thread t = new Thread() {
00045                         public void run() {
00046                                 try {
00047                                         XmlTool.transform(
00048                                                 // XML
00049                                                 "<simpleXML><node>val1</node></simpleXML>",
00050                                                 // XSLT
00051                                                 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
00052                                                 "<xsl:template match=\"/batch\">" +
00053                                                 "<xsl:for-each select=\"/simpleXML\">" +
00054                                                 "<xsl:value-of select=\"node\"/>" +
00055                                                 "</xsl:for-each>" +
00056                                                 "</xsl:template>" +
00057                                                 "</xsl:stylesheet>",
00058                                                 po
00059                                         );
00060                                 }
00061                                 catch (Exception e) { e.printStackTrace(); }
00062                                 try { po.close(); }
00063                                 catch (Exception e) { e.printStackTrace(); }
00064                                 signal.clear();
00065                         }
00066                 };
00067                 t.start();
00068 
00069                 BufferedReader br = new BufferedReader( new InputStreamReader(pi) );
00070                 assertTrue(br.readLine().equals("val1"));
00071                 assertTrue(br.readLine() == null);
00072 
00073                 // Give the thread a second to finish
00074                 try { Thread.sleep(1000); } catch (Exception e) { }
00075                 assertTrue(signal.size() == 0);
00076                 }
00077 
00078 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15