KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > weblog > WeblogEntryActionTest


1 package org.roller.presentation.weblog;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4
5 import junit.framework.Test;
6 import junit.framework.TestSuite;
7
8 import org.roller.presentation.StrutsActionTestBase;
9 import org.roller.presentation.weblog.actions.WeblogEntryFormAction;
10 import org.roller.presentation.weblog.formbeans.WeblogEntryFormEx;
11
12 import com.mockrunner.mock.web.MockActionMapping;
13 import com.mockrunner.mock.web.MockHttpServletRequest;
14
15 /**
16  * @author dave
17  */

18 public class WeblogEntryActionTest extends StrutsActionTestBase
19 {
20     public void testCreateWeblogEntry()
21     {
22         authenticateUser(mWebsite.getUser().getUserName(), "editor");
23         
24         MockHttpServletRequest mockRequest = getMockFactory().getMockRequest();
25         mockRequest.setContextPath("/dummy");
26         
27         doFilters();
28
29         // Setup mapping and request parameters
30
MockActionMapping mapping = strutsModule.getMockActionMapping();
31         mapping.setupForwards(new String JavaDoc[] {
32             "access-denied","weblogEdit.page","weblogEntryRemove.page"});
33         mapping.setParameter("method");
34         strutsModule.addRequestParameter("method","create");
35         
36         // Setup form bean
37
WeblogEntryFormEx form = (WeblogEntryFormEx)
38             strutsModule.createActionForm(WeblogEntryFormEx.class);
39         form.setTitle("test_title");
40         form.setText("Test blog text");
41
42         strutsModule.actionPerform(WeblogEntryFormAction.class, form);
43         
44         // Test for success
45
strutsModule.verifyNoActionMessages();
46         strutsModule.verifyForward("weblogEdit.page");
47         
48         // Verify objects we put in context for JSP page
49
verifyPageContext();
50     }
51     
52     protected void verifyPageContext()
53     {
54         HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)
55             servletModule.getFilteredRequest();
56         assertNotNull(req.getAttribute("model"));
57     }
58
59     public static Test suite()
60     {
61         return new TestSuite(WeblogEntryActionTest.class);
62     }
63
64 }
65
Popular Tags