KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > test > FullMVCTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.test;
8
9
10 import java.util.Map JavaDoc;
11
12 import javax.servlet.ServletException JavaDoc;
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 /**
29  * <p>
30  * This class does full system testing
31  * </p>
32  *
33  * @author Brian Pontarelli
34  * @since 2.0
35  * @version 2.0
36  */

37 public class FullMVCTest extends WebTestCase {
38
39     public FullMVCTest(String JavaDoc name) {
40         super(name);
41     }
42
43
44     //--------------------------------------------------------------------------
45
// Helper methods
46
//--------------------------------------------------------------------------
47

48     protected void setup(String JavaDoc 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 JavaDoc se) {
56                 fail(se.toString());
57             }
58         }
59     }
60
61     protected void addFBMVCFormParameter(Request request, String JavaDoc id, String JavaDoc property,
62             String JavaDoc input, String JavaDoc value) {
63         MetaData md = new FormMetaData(id, property);
64         String JavaDoc system = md.getModelSystem();
65         Map JavaDoc 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 JavaDoc action, String JavaDoc input,
74             String JavaDoc 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 JavaDoc 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 JavaDoc form, String JavaDoc 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 JavaDoc id, String JavaDoc property,
97             String JavaDoc input, String JavaDoc value) {
98         MetaData md = new ActionFlowModelMetaData(id, property);
99         String JavaDoc system = md.getModelSystem();
100         Map JavaDoc 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 JavaDoc action, String JavaDoc input,
109             String JavaDoc value, boolean isImage, String JavaDoc 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 JavaDoc form, String JavaDoc 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 JavaDoc form, String JavaDoc 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