1 7 package com.inversoft.verge.mvc.test; 8 9 10 import java.util.Map ; 11 12 import javax.servlet.ServletException ; 13 14 import com.inversoft.junit.Request; 15 import com.inversoft.junit.URL; 16 import com.inversoft.junit.WebTestCase; 17 import com.inversoft.verge.config.VergeConfigConstants; 18 import com.inversoft.verge.config.servlet.ConfigServlet; 19 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowURLTools; 20 import com.inversoft.verge.mvc.controller.form.FormURLTools; 21 import com.inversoft.verge.mvc.model.DefaultModelParser; 22 import com.inversoft.verge.mvc.model.MetaData; 23 import com.inversoft.verge.mvc.model.ModelMVCInfo; 24 import com.inversoft.verge.mvc.model.actionflow.ActionFlowModelMetaData; 25 import com.inversoft.verge.mvc.model.form.FormMetaData; 26 27 28 37 public class FullMVCTest extends WebTestCase { 38 39 public FullMVCTest(String name) { 40 super(name); 41 } 42 43 44 48 protected void setup(String files) { 49 if (isLocal()) { 50 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, files); 51 52 ConfigServlet cs = new ConfigServlet(); 53 try { 54 cs.init(createConfig("ConfigServlet")); 55 } catch (ServletException se) { 56 fail(se.toString()); 57 } 58 } 59 } 60 61 protected void addFBMVCFormParameter(Request request, String id, String property, 62 String input, String value) { 63 MetaData md = new FormMetaData(id, property); 64 String system = md.getModelSystem(); 65 Map extraParams = md.getExtraParams(); 66 67 ModelMVCInfo info = new ModelMVCInfo(input, system, md.getDefinition(), 68 extraParams); 69 request.addParameter(DefaultModelParser.INPUT_PARAMETER, info.encode()); 70 request.addParameter(input, value); 71 } 72 73 protected void addFBMVCFormSubmit(Request request, String action, String input, 74 String value, boolean isImage) { 75 request.addParameter(FormURLTools.SUBMIT_PARAMETER, 76 FormURLTools.generateSubmitParameter(input, action)); 77 78 if (isImage) { 79 input = input + ".x"; 80 } 81 request.addParameter(input, value); 82 } 83 84 protected void addFBMVCForm(Request request, String form) { 85 URL url = new URL(null, FormURLTools.generateURL(form, null), null, null, 86 null, "/"); 87 request.setURL(url); 88 } 89 90 protected void addFBMVCURL(Request request, String form, String action) { 91 URL url = new URL(null, FormURLTools.generateURL(form, null), null, null, 92 null, "/"); 93 request.setURL(url); 94 } 95 96 protected void addAFFormParameter(Request request, String id, String property, 97 String input, String value) { 98 MetaData md = new ActionFlowModelMetaData(id, property); 99 String system = md.getModelSystem(); 100 Map extraParams = md.getExtraParams(); 101 102 ModelMVCInfo info = new ModelMVCInfo(input, system, md.getDefinition(), 103 extraParams); 104 request.addParameter(DefaultModelParser.INPUT_PARAMETER, info.encode()); 105 request.addParameter(input, value); 106 } 107 108 protected void addAFFormSubmit(Request request, String action, String input, 109 String value, boolean isImage, String entry) { 110 request.addParameter(ActionFlowURLTools.SUBMIT_PARAMETER, 111 ActionFlowURLTools.generateSubmitParameter(input, action, entry, null)); 112 113 if (isImage) { 114 input = input + ".x"; 115 } 116 request.addParameter(input, value); 117 } 118 119 protected void addAFForm(Request request, String form, String namespace) { 120 URL url = new URL(null, 121 ActionFlowURLTools.generateURL(namespace, form, null, null), null, 122 null, null, "/"); 123 request.setURL(url); 124 } 125 126 protected void addAFURL(Request request, String form, String namespace) { 127 URL url = new URL(null, 128 ActionFlowURLTools.generateURL(namespace, form, null, null), null, 129 null, null, "/"); 130 request.setURL(url); 131 } 132 } | Popular Tags |