1 package org.sapia.soto.state.xml; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 6 import org.sapia.soto.SotoContainer; 7 import org.sapia.soto.state.StateMachine; 8 import org.xml.sax.InputSource ; 9 import org.apache.xml.serialize.OutputFormat; 10 import org.apache.xml.serialize.Serializer; 11 import org.apache.xml.serialize.SerializerFactory; 12 13 14 import junit.framework.TestCase; 15 16 25 public class TransformStateTest extends TestCase{ 26 27 public TransformStateTest(String name){ 28 super(name); 29 } 30 31 public void testNoStylesheet() throws Exception { 32 SotoContainer cont = new SotoContainer(); 33 StateMachine stm = new StateMachine(); 34 TransformState st = new TransformState(); 35 st.setEnv(cont.toEnv()); 36 st.setId("txform"); 37 stm.addState(st); 38 stm.init(); 39 XMLContext ctx = new XMLContextImpl(); 40 41 OutputFormat format = new OutputFormat("xml", "UTF-8", true); 42 Serializer ser = SerializerFactory.getSerializerFactory("xml") 43 .makeSerializer(System.out, format); 44 ctx.setContentHandler(ser.asContentHandler()); 45 ctx.push(new InputSource (new FileInputStream (new File ("etc/stm/dog.xml")))); 46 stm.execute("txform", ctx); 47 } 48 49 public void testSingleStylesheet() throws Exception { 50 SotoContainer cont = new SotoContainer(); 51 StateMachine stm = new StateMachine(); 52 TransformState st = new TransformState(); 53 st.setEnv(cont.toEnv()); 54 st.setId("txform"); 55 stm.addState(st); 56 StyleStep step = new StyleStep(); 57 step.setEnv(cont.toEnv()); 58 step.setSrc("etc/stm/dogToCat.xsl"); 59 st.addExecutable(step); 60 stm.init(); 61 XMLContext ctx = new XMLContextImpl(); 62 OutputFormat format = new OutputFormat("xml", "UTF-8", true); 63 Serializer ser = SerializerFactory.getSerializerFactory("xml") 64 .makeSerializer(System.out, format); 65 ctx.setContentHandler(ser.asContentHandler()); 66 ctx.push(new InputSource (new FileInputStream (new File ("etc/stm/dog.xml")))); 67 stm.execute("txform", ctx); 68 } 69 70 public void testMultiStylesheets() throws Exception { 71 SotoContainer cont = new SotoContainer(); 72 StateMachine stm = new StateMachine(); 73 TransformState st = new TransformState(); 74 st.setEnv(cont.toEnv()); 75 st.setId("txform"); 76 stm.addState(st); 77 StyleStep step1 = new StyleStep(); 78 step1.setEnv(cont.toEnv()); 79 step1.setSrc("etc/stm/dogToCat.xsl"); 80 st.addExecutable(step1); 81 StyleStep step2 = new StyleStep(); 82 step2.setEnv(cont.toEnv()); 83 step2.setSrc("etc/stm/catToDog.xsl"); 84 st.addExecutable(step2); 85 stm.init(); 86 XMLContext ctx = new XMLContextImpl(); 87 OutputFormat format = new OutputFormat("xml", "UTF-8", true); 88 Serializer ser = SerializerFactory.getSerializerFactory("xml") 89 .makeSerializer(System.out, format); 90 ctx.setContentHandler(ser.asContentHandler()); 91 ctx.push(new InputSource (new FileInputStream (new File ("etc/stm/dog.xml")))); 92 stm.execute("txform", ctx); 93 } 94 95 } 96 | Popular Tags |