KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > error > test > ErrorHelperTest


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.view.jsp.error.test;
8
9
10 import com.inversoft.error.PropertyError;
11 import com.inversoft.junit.JspTestCase;
12 import com.inversoft.verge.mvc.MVCException;
13 import com.inversoft.verge.mvc.model.ModelResolution;
14 import com.inversoft.verge.mvc.model.web.WebMetaData;
15 import com.inversoft.verge.mvc.view.jsp.error.ErrorHelper;
16 import com.inversoft.verge.mvc.view.jsp.model.ModelResolutionRegistry;
17 import com.inversoft.verge.util.RequestContext;
18 import com.inversoft.verge.util.ScopeConstants;
19
20
21 /**
22  * <p>
23  * Tests the ErrorHelper class
24  * </p>
25  *
26  * @author Brian Pontarelli
27  * @since 2.0
28  * @version 2.0
29  */

30 public class ErrorHelperTest extends JspTestCase {
31
32     /**
33      * Constructs a new <code>ErrorHelperTest</code>
34      *
35      * @param name The name of the currently executing test
36      */

37     public ErrorHelperTest(String JavaDoc name) {
38         super(name);
39         setLocal(true);
40     }
41
42
43     /**
44      * Test that it correctly converts the page name to the scope name based
45      * on the meta data
46      */

47     public void testNameConversion() {
48
49         WebMetaData wmd = null;
50         try {
51             wmd = new WebMetaData("webBean", "com.inversoft.verge.mvc.test.Customer",
52                 ScopeConstants.SESSION_INT);
53         } catch (MVCException mvce) {
54             fail(mvce.toString());
55         }
56
57         ModelResolution modelResolution = new ModelResolution(new Object JavaDoc(), wmd);
58         ModelResolutionRegistry.store("pageBean", modelResolution, pageContext);
59         RequestContext context = new RequestContext(request);
60         context.addError(new PropertyError("webBean.firstName"));
61
62         assertTrue("Should have found the error",
63             ErrorHelper.hasPropertyErrors("pageBean.firstName", context, pageContext));
64     }
65
66     /**
67      * Test that it correctly finds a simple error
68      */

69     public void testSimpleHas() {
70
71         RequestContext context = new RequestContext(request);
72         context.addError(new PropertyError("pageBean.firstName"));
73
74         assertTrue("Should have found the error",
75             ErrorHelper.hasPropertyErrors("pageBean.firstName", context, pageContext));
76     }
77 }
Popular Tags