1 64 65 package com.jcorporate.expresso.services.controller.tests; 66 67 import com.jcorporate.expresso.core.controller.ControllerException; 68 import com.jcorporate.expresso.core.controller.ControllerResponse; 69 import com.jcorporate.expresso.core.controller.Input; 70 import com.jcorporate.expresso.core.controller.Transition; 71 import com.jcorporate.expresso.services.controller.DBMaint; 72 import com.jcorporate.expresso.services.test.ControllerTestCase; 73 import com.jcorporate.expresso.services.test.ControllerTestSuite; 74 import junit.framework.TestSuite; 75 import org.apache.cactus.WebRequest; 76 77 85 public class DBMaintTests extends ControllerTestCase { 86 87 94 public DBMaintTests(String testName) 95 throws Exception { 96 super(testName, 97 com.jcorporate.expresso.services.controller.DBMaint.class); 98 } 99 100 106 public static void main(String [] args) 107 throws Exception { 108 junit.textui.TestRunner.run(suite()); 109 } 110 111 120 public static TestSuite suite() 121 throws Exception { 122 ControllerTestSuite cts = new ControllerTestSuite(); 123 cts.addReadOnlySchemaDependency(com.jcorporate.expresso.core.ExpressoSchema.class); 124 cts.addTestSuite(DBMaintTests.class); 125 126 return cts; 127 } 128 129 130 136 public void beginPromptState(WebRequest theRequest) 137 throws Exception { 138 super.logIn(theRequest); 139 super.setupParameters("prompt", theRequest); 140 } 141 142 148 public void testPromptState() 149 throws Exception { 150 try { 151 ControllerResponse response = super.controllerProcess(); 152 assertTrue("Must have a non-null response", response != null); 153 Input i = response.getInput("SchemaClass"); 154 assertTrue("Must have a SchemaClass Input", i != null); 155 assertTrue("Schema Class Input must have valid values", i.getValidValues().size() > 0); 156 157 Transition t = response.getTransition("selDBObj"); 158 assertTrue("Must have a transition to next state", t != null); 159 assertTrue("Must transition to this controller", 160 t.getControllerObject().equals(DBMaint.class.getName())); 161 162 assertTrue("Must transition to appropriate state", 163 t.getState().equals("selDBObj")); 164 } catch (Exception ex) { 165 ex.printStackTrace(); 166 fail("Caught Exception in testPromptState: " + ex.getMessage()); 167 } 168 } 169 170 171 177 public void beginSelDBObjState(WebRequest theRequest) 178 throws Exception { 179 super.logIn(theRequest); 180 super.setupParameters("selDBObj", theRequest); 181 theRequest.addParameter("SchemaClass", com.jcorporate.expresso.core.ExpressoSchema.class.getName()); 182 } 183 184 188 public void testSelDBObjState() 189 throws Exception { 190 try { 191 ControllerResponse response = super.controllerProcess(); 192 assertTrue("Must have a non-null response", response != null); 193 Input i = response.getInput("dbobj"); 194 assertTrue("Must have dbobject input", i != null); 195 assertTrue("Must have valid values", i.getValidValues().size() > 0); 196 verifyAddListSearchButtons(response); 197 198 } catch (Exception ex) { 199 ex.printStackTrace(); 200 fail("Caught Exception in testListDBOBjState: " + ex.getMessage()); 201 } 202 203 } 204 205 206 212 public void beginListDBObjState(WebRequest theRequest) 213 throws Exception { 214 super.logIn(theRequest); 215 super.setupParameters("List", theRequest); 216 theRequest.addParameter("dbobj", com.jcorporate.expresso.services 217 .dbobj.MimeTypes.class.getName()); 218 } 219 220 226 public void testListDBObjState() 227 throws Exception { 228 try { 229 ControllerResponse response = super.controllerProcess(); 230 assertTrue("Must have a non-null response", response != null); 231 assertTrue("Must have a Buttons Block", response.getBlock("buttons") != null); 232 assertTrue("Must have a record list block", response.getBlock("recordList") != null); 233 } catch (Exception ex) { 234 ex.printStackTrace(); 235 fail("Caught Exception in testListDBOBjState: " + ex.getMessage()); 236 } 237 238 } 239 240 246 protected void verifyAddListSearchButtons(ControllerResponse response) throws ControllerException { 247 Transition t = response.getTransition("Add"); 248 assertTrue("Must have Add Transition", t != null); 249 assertTrue("Add Must transition to this controller", 250 t.getControllerObject().equals(DBMaint.class.getName())); 251 252 assertTrue("Add Must transition to appropriate state", 253 t.getState().equals("Add")); 254 255 t = response.getTransition("List"); 256 assertTrue("Must have List Transition", t != null); 257 assertTrue("List Must transition to this controller", 258 t.getControllerObject().equals(DBMaint.class.getName())); 259 260 assertTrue("List Must transition to appropriate state", 261 t.getState().equals("List")); 262 263 t = response.getTransition("Search"); 264 assertTrue("Must have Search Transition", t != null); 265 assertTrue("Search Must transition to this controller", 266 t.getControllerObject().equals(DBMaint.class.getName())); 267 268 assertTrue("Search Must transition to appropriate state", 269 t.getState().equals("Search")); 270 271 } 272 273 274 281 public void beginAddDBObjState(WebRequest theRequest) 282 throws Exception { 283 super.logIn(theRequest); 284 super.setupParameters("Add", theRequest); 285 theRequest.addParameter("dbobj", com.jcorporate.expresso.services 286 .dbobj.MimeTypes.class.getName()); 287 } 288 289 295 public void testAddDBObjState() 296 throws Exception { 297 ControllerResponse response = super.controllerProcess(); 298 assertTrue("Must have a non-null response", response != null); 299 300 } 301 302 303 309 public void beginSearchDBObjState(WebRequest theRequest) 310 throws Exception { 311 super.logIn(theRequest); 312 super.setupParameters("Search", theRequest); 313 theRequest.addParameter("dbobj", com.jcorporate.expresso.services 314 .dbobj.DefaultUserInfo.class.getName()); 315 } 316 317 323 public void testSearchDBObjState() 324 throws Exception { 325 ControllerResponse response = super.controllerProcess(); 326 assertTrue("Must have a non-null response", response != null); 327 328 } 329 330 } | Popular Tags |