1 64 65 package com.jcorporate.expresso.core.controller.tests; 66 67 import com.jcorporate.expresso.core.controller.Input; 68 import com.jcorporate.expresso.core.dbobj.ValidValue; 69 import com.jcorporate.expresso.core.misc.StringDOMParser; 70 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 71 import com.jcorporate.expresso.services.test.CommandLineParser; 72 import com.jcorporate.expresso.services.test.ExpressoTestCase; 73 import junit.framework.TestSuite; 74 import org.w3c.dom.Document ; 75 76 import java.util.Enumeration ; 77 import java.util.Vector ; 78 79 80 87 public class InputTests 88 extends ExpressoTestCase { 89 Input i = null; 90 StringDOMParser parser = null; 91 92 public InputTests(String testName) 93 throws Exception { 94 super(testName); 95 } 96 97 public static void main(String [] args) 98 throws Exception { 99 100 CommandLineParser.parseCommandLine(args); 102 junit.textui.TestRunner.run(suite()); 103 } 104 105 public void setUp() 106 throws Exception { 107 i = new Input("Test Input", "This is a test Input"); 108 i.setLookup("com.jcorporate.expresso.services.dbobj.MimeTypes"); 109 i.setDescription("This is a test input description"); 110 i.setDisplayLength(30); 111 i.setType("boolean"); 112 i.setAttribute("checkbox", ""); 113 parser = new StringDOMParser(); 114 } 115 116 119 public static junit.framework.Test suite() 120 throws Exception { 121 return new TestSuite(InputTests.class); 122 } 123 124 128 private Document getXMLDoc() 129 throws Exception { 130 FastStringBuffer fsb = new FastStringBuffer(128); 131 String result = i.toXML(fsb).toString(); 132 System.out.println("\nInput Before Serialization:"); 133 System.out.println(result); 134 135 Document d = parser.parseString(result); 136 137 if (d == null) { 138 fail("Input returned mal-formed XML document"); 139 } 140 141 return d; 142 } 143 144 147 private Input getInput(Document d) 148 throws Exception { 149 Input anotherI = (Input) Input.fromXML(d); 150 151 return anotherI; 154 } 155 156 159 public void testXML() 160 throws Exception { 161 Document d = getXMLDoc(); 162 Input newInput = getInput(d); 163 assertTrue("getInput returned null", newInput != null); 164 assertTrue("Proper Display Length", newInput.getDisplayLength() == 30); 165 assertTrue("Proper Lookup", 166 newInput.getLookup().equals("com.jcorporate.expresso.services.dbobj.MimeTypes")); 167 assertTrue("Proper Name", newInput.getName().equals("Test Input")); 168 assertTrue("Proper Description", 169 newInput.getDescription().equals("This is a test input description")); 170 assertTrue("Proper Label", 171 newInput.getLabel().equals("This is a test Input")); 172 assertTrue("Proper Type", newInput.getType().equals("boolean")); 173 assertTrue("Checkbox Attribute Exists", 174 newInput.getAttribute("checkbox") != null); 175 } 176 177 180 public void testXMLMultiValues() 181 throws Exception { 182 i.addValidValue("one", "One Value"); 183 i.addValidValue("two", "Two Values"); 184 i.addValidValue("three", "Three Values"); 185 i.setType("C"); 186 187 Document d = getXMLDoc(); 188 Input newInput = getInput(d); 189 assertTrue("getInput returned null", newInput != null); 190 assertTrue("Proper Display Length", newInput.getDisplayLength() == 30); 191 assertTrue("Proper Lookup", 192 newInput.getLookup().equals("com.jcorporate.expresso.services.dbobj.MimeTypes")); 193 assertTrue("Proper Name", newInput.getName().equals("Test Input")); 194 assertTrue("Proper Description", 195 newInput.getDescription().equals("This is a test input description")); 196 assertTrue("Proper Label", 197 newInput.getLabel().equals("This is a test Input")); 198 assertTrue("Proper Type", newInput.getType().equals("C")); 199 assertTrue("Checkbox Attribute Exists", 200 newInput.getAttribute("checkbox") != null); 201 202 Vector v = newInput.getValidValues(); 204 assertTrue("Returned Vector of valid values", 205 (v != null && !v.isEmpty())); 206 assertTrue("Returned proper number of valid values", v.size() == 3); 207 208 for (Enumeration e = v.elements(); e.hasMoreElements();) { 209 ValidValue vv = (ValidValue) e.nextElement(); 210 assertTrue("Valid Value != null", vv != null); 211 212 String value = vv.getValue(); 213 String description = vv.getDescription(); 214 215 if (value.equals("one")) { 216 assertTrue("Proper Description for one", 217 description.equals("One Value")); 218 } else if (value.equals("two")) { 219 assertTrue("Proper Description for two", 220 description.equals("Two Values")); 221 } else if (value.equals("three")) { 222 assertTrue("Proper Description for three", 223 description.equals("Three Values")); 224 } else { 225 fail("Got invalid valid value: " + value); 226 } 227 } 228 } 229 230 233 public void testXMLWithNestedInput() 234 throws Exception { 235 Input nested = new Input("nested1", "label1"); 236 i.addNested(nested); 237 nested = new Input("nested2", "label2"); 238 i.addNested(nested); 239 240 Document d = getXMLDoc(); 241 Input newInput = getInput(d); 242 assertTrue("getInput returned null", newInput != null); 243 assertTrue("Proper Display Length", newInput.getDisplayLength() == 30); 244 assertTrue("Proper Lookup", 245 newInput.getLookup().equals("com.jcorporate.expresso.services.dbobj.MimeTypes")); 246 assertTrue("Proper Name", newInput.getName().equals("Test Input")); 247 assertTrue("Proper Description", 248 newInput.getDescription().equals("This is a test input description")); 249 assertTrue("Proper Label", 250 newInput.getLabel().equals("This is a test Input")); 251 assertTrue("Proper Type", newInput.getType().equals("boolean")); 252 assertTrue("Checkbox Attribute Exists", 253 newInput.getAttribute("checkbox") != null); 254 nested = (Input) newInput.getNested("nested1"); 255 assertTrue("Got nested 1", nested != null); 256 assertTrue("Proper Nested 1 Label", nested.getLabel().equals("label1")); 257 nested = (Input) newInput.getNested("nested2"); 258 assertTrue("Got nested 2", nested != null); 259 assertTrue("Proper Nested 2 Label", nested.getLabel().equals("label2")); 260 } 261 } | Popular Tags |