1 64 65 package com.jcorporate.expresso.services.controller.tests; 66 67 import com.jcorporate.expresso.core.controller.Block; 68 import com.jcorporate.expresso.core.controller.ControllerElement; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.Input; 71 import com.jcorporate.expresso.core.controller.Output; 72 import com.jcorporate.expresso.core.controller.Transition; 73 import com.jcorporate.expresso.services.test.ControllerTestCase; 74 import com.jcorporate.expresso.services.test.ControllerTestSuite; 75 import junit.framework.TestSuite; 76 import org.apache.cactus.WebRequest; 77 78 import java.util.Enumeration ; 79 80 81 88 public class DBSecurityMatrixTests 89 extends ControllerTestCase { 90 97 public DBSecurityMatrixTests(String testName) 98 throws Exception { 99 super(testName, 100 com.jcorporate.expresso.services.controller.DBSecurityMatrix.class); 101 } 102 103 109 public static void main(String [] args) 110 throws Exception { 111 junit.textui.TestRunner.run(suite()); 112 } 113 114 123 public static TestSuite suite() 124 throws Exception { 125 ControllerTestSuite cts = new ControllerTestSuite(); 126 cts.addReadOnlySchemaDependency(com.jcorporate.expresso.core.ExpressoSchema.class); 127 cts.addTestSuite(DBSecurityMatrixTests.class); 128 129 return cts; 130 } 131 132 143 public void beginPromptState(WebRequest theRequest) 144 throws Exception { 145 super.logIn(theRequest); 146 super.setupParameters("prompt", theRequest); 147 } 148 149 155 public void testPromptState() 156 throws Exception { 157 ControllerResponse response = super.controllerProcess(); 158 assertTrue("Got a null response", response != null); 159 assertTrue("Incorrect Number Of Inputs", 160 response.getInputs().size() == 2); 161 assertTrue("Incorrect Number Of Transitions", 162 response.getTransitions().size() == 1); 163 assertTrue("GroupNames are not multivalued", 164 response.getInput("GroupName").getValidValues().size() > 0); 165 assertTrue("SchemaClass is not multivalued", 166 response.getInput("SchemaClass").getValidValues().size() > 0); 167 } 168 169 179 public void beginSecurityMatrix(WebRequest theRequest) 180 throws Exception { 181 super.logIn(theRequest); 182 super.setupParameters("dbobjmatrix", theRequest); 183 theRequest.addParameter("SchemaClass", 184 "com.jcorporate.expresso.core.ExpressoSchema"); 185 theRequest.addParameter("GroupName", "Admin"); 186 } 187 188 194 public void testSecurityMatrix() 195 throws Exception { 196 ControllerResponse theResponse = super.controllerProcess(); 197 assertTrue("Got a null response", theResponse != null); 198 assertTrue("Returned one security matrix block", 199 theResponse.getBlocks().size() == 1); 200 201 Block b = (Block) theResponse.getBlocks().elementAt(0); 202 Block matrix = (Block) b.getNested().elementAt(0); 203 assertTrue("Batch of security matrix blocks", 204 matrix.getBlocks().size() > 4); 205 206 for (Enumeration eRow = matrix.getNested().elements(); 208 eRow.hasMoreElements();) { 209 ControllerElement ce = (ControllerElement) eRow.nextElement(); 210 211 if (ce instanceof Block) { 212 Block oneRow = (Block) ce; 213 214 if (ce.getName().equals("oneRow")) { 215 int outputCount = 0; 216 int inputCount = 0; 217 assertTrue("Five Elements for Security Matrix Row", 218 oneRow.getNested().size() == 5 ); 220 221 for (Enumeration e = oneRow.getNested().elements(); 222 e.hasMoreElements();) { 223 ControllerElement oneElement = (ControllerElement) e.nextElement(); 224 225 if (oneElement != null) { 226 if (oneElement instanceof Output) { 227 assertTrue("Output Label is non-empty string", 228 ((Output) oneElement).getContent().length() > 0); 229 outputCount++; 230 } else if (oneElement instanceof Input) { 231 assertTrue("Input is a check box", 232 oneElement.getAttribute("checkbox") != null); 233 inputCount++; 234 } else if (oneElement instanceof Transition) { 235 fail("Did not expect a tranition within the security matrix fields"); 236 } else { 237 fail("Got Controller Element of: " + 238 oneElement.getClass().getName() + 239 " not expected element."); 240 } 241 } 242 } 243 244 assertTrue("Proper number of outputs for row", 245 outputCount == 1); 246 assertTrue("Proper number of inputs for a row", 247 inputCount == 4); 248 } else if (ce.getName().equals("TransitionRow")) { 249 super.getLog().debug("Got Here"); 250 } 251 } else { 252 fail("Expected Matrix to have only blocks nested"); 253 } 254 } 255 } 256 } | Popular Tags |