1 64 65 package com.jcorporate.expresso.core.controller.tests; 66 67 import com.jcorporate.expresso.core.controller.Transition; 68 import com.jcorporate.expresso.core.misc.StringDOMParser; 69 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 70 import com.jcorporate.expresso.services.test.CommandLineParser; 71 import com.jcorporate.expresso.services.test.ExpressoTestCase; 72 import junit.framework.TestSuite; 73 import org.w3c.dom.Document ; 74 75 76 83 public class TransitionTests 84 extends ExpressoTestCase { 85 Transition t = null; 86 StringDOMParser parser = null; 87 static final String transitionName = "Test Transition"; 88 static final String transitionLabel = "Click Here To Continue"; 89 static final String transitionController = "com.jcorporate.expresso.services.controller.DBMaint"; 90 91 public TransitionTests(String testName) 92 throws Exception { 93 super(testName); 94 } 95 96 public static void main(String [] args) 97 throws Exception { 98 99 CommandLineParser.parseCommandLine(args); 101 junit.textui.TestRunner.run(suite()); 102 } 103 104 public void setUp() 105 throws Exception { 106 t = new Transition(transitionName, transitionLabel, 107 transitionController); 108 t.addParam("a", "b"); 109 t.addParam("c", "d"); 110 parser = new StringDOMParser(); 111 } 112 113 116 public static junit.framework.Test suite() 117 throws Exception { 118 return new TestSuite(TransitionTests.class); 119 } 120 121 125 private Document getXMLDoc() 126 throws Exception { 127 FastStringBuffer fsb = new FastStringBuffer(128); 128 String result = t.toXML(fsb).toString(); 129 System.out.println("\nTransition Before Serialization:"); 130 System.out.println(result); 131 132 Document d = parser.parseString(result); 133 134 if (d == null) { 135 fail("Transition returned mal-formed XML document"); 136 } 137 138 return d; 139 } 140 141 144 private Transition getTransition(Document d) 145 throws Exception { 146 Transition anotherTransition = (Transition) Transition.fromXML(d); 147 FastStringBuffer fsb = new FastStringBuffer(128); 148 System.out.println("\nTransition After De-Serialization:"); 149 System.out.println(anotherTransition.toXML(fsb).toString()); 150 151 return anotherTransition; 152 } 153 154 157 public void testXML() 158 throws Exception { 159 Document d = getXMLDoc(); 160 Transition newTransition = getTransition(d); 161 assertTrue("getTransition returned null", newTransition != null); 162 assertTrue("Proper Name", 163 newTransition.getName().equals(transitionName)); 164 assertTrue("Proper Controller", 165 newTransition.getControllerObject().equals(transitionController)); 166 assertTrue("Proper Parameter a", 167 newTransition.getParam("a").equals("b")); 168 assertTrue("Proper Parameter c", 169 newTransition.getParam("c").equals("d")); 170 } 171 } | Popular Tags |