1 7 package com.inversoft.verge.mvc.junit; 8 9 10 import java.util.Map ; 11 import javax.servlet.ServletException ; 12 13 import com.inversoft.junit.URL; 14 import com.inversoft.junit.WebTestCase; 15 import com.inversoft.junit.Request; 16 import com.inversoft.verge.mvc.MVCURLTools; 17 import com.inversoft.verge.mvc.model.MetaData; 18 import com.inversoft.verge.mvc.model.ModelMVCInfo; 19 import com.inversoft.verge.mvc.model.DefaultModelParser; 20 import com.inversoft.verge.mvc.model.actionflow.ActionFlowModelMetaData; 21 import com.inversoft.verge.mvc.model.form.FormMetaData; 22 import com.inversoft.verge.mvc.controller.form.FormURLTools; 23 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowURLTools; 24 import com.inversoft.verge.config.VergeConfigConstants; 25 import com.inversoft.verge.config.servlet.ConfigServlet; 26 27 28 36 public class VergeMVCTestCase extends WebTestCase { 37 38 41 public VergeMVCTestCase(String name) { 42 super(name); 43 } 44 45 46 55 protected URL createFormMVCURL(String contextPath, String form, String action) { 56 return createMVCURL(contextPath, null, FormURLTools.generateURL(form, action)); 57 } 58 59 70 protected URL createMVCURL(String contextPath, String systemName, String pathInfo) { 71 String localPathInfo = pathInfo; 72 if (systemName != null) { 73 localPathInfo = "/" + systemName + pathInfo; 74 } 75 76 return new URL(contextPath, localPathInfo, "http", null, null, 77 MVCURLTools.getURLBeginning()); 78 } 79 80 87 protected void setup(String files) { 88 if (isLocal()) { 89 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, files); 90 91 ConfigServlet cs = new ConfigServlet(); 92 try { 93 cs.init(createConfig("ConfigServlet")); 94 } catch (ServletException se) { 95 fail(se.toString()); 96 } 97 } 98 } 99 100 120 protected void addFBMVCInput(Request request, String id, String property, 121 String input, String value) { 122 MetaData md = new FormMetaData(id, property); 123 String system = md.getModelSystem(); 124 Map extraParams = md.getExtraParams(); 125 126 ModelMVCInfo info = new ModelMVCInfo(input, system, md.getDefinition(), 127 extraParams); 128 request.addParameter(DefaultModelParser.INPUT_PARAMETER, info.encode()); 129 request.addParameter(input, value); 130 } 131 132 151 protected void addFBMVCSubmit(Request request, String action, String input, 152 String value, boolean isImage) { 153 request.addParameter(FormURLTools.SUBMIT_PARAMETER, 154 FormURLTools.generateSubmitParameter(input, action)); 155 156 if (isImage) { 157 input = input + ".x"; 158 } 159 request.addParameter(input, value); 160 } 161 162 176 protected void addFBMVCForm(Request request, String form) { 177 URL url = new URL(null, FormURLTools.generateURL(form, null), null, null, 178 null, "/mvc"); 179 request.setURL(url); 180 } 181 182 191 protected void addFBMVCURL(Request request, String form, String action) { 192 URL url = new URL(null, FormURLTools.generateURL(form, null), null, null, 193 null, "/mvc"); 194 request.setURL(url); 195 } 196 197 217 protected void addAFInput(Request request, String id, String property, 218 String input, String value) { 219 MetaData md = new ActionFlowModelMetaData(id, property); 220 String system = md.getModelSystem(); 221 Map extraParams = md.getExtraParams(); 222 223 ModelMVCInfo info = new ModelMVCInfo(input, system, md.getDefinition(), 224 extraParams); 225 request.addParameter(DefaultModelParser.INPUT_PARAMETER, info.encode()); 226 request.addParameter(input, value); 227 } 228 229 249 protected void addAFSubmit(Request request, String action, String input, 250 String value, boolean isImage, String entry) { 251 request.addParameter(ActionFlowURLTools.SUBMIT_PARAMETER, 252 ActionFlowURLTools.generateSubmitParameter(input, action, entry, null)); 253 254 if (isImage) { 255 input = input + ".x"; 256 } 257 request.addParameter(input, value); 258 } 259 260 275 protected void addAFForm(Request request, String form, String namespace) { 276 URL url = new URL(null, 277 ActionFlowURLTools.generateURL(namespace, form, null, null), null, 278 null, null, "/mvc"); 279 request.setURL(url); 280 } 281 } | Popular Tags |