KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > bookmarks > BookmarksActionTest


1 /*
2  * Created on Oct 27, 2003
3  */

4 package org.roller.presentation.bookmarks;
5
6 import java.util.List JavaDoc;
7 import java.util.Set JavaDoc;
8
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10
11 import junit.framework.Test;
12 import junit.framework.TestSuite;
13
14 import org.roller.pojos.FolderData;
15 import org.roller.presentation.StrutsActionTestBase;
16 import org.roller.presentation.bookmarks.actions.BookmarksAction;
17 import org.roller.presentation.bookmarks.formbeans.BookmarksForm;
18
19 import com.mockrunner.mock.web.MockActionMapping;
20 import com.mockrunner.mock.web.MockHttpServletRequest;
21 import com.mockrunner.mock.web.MockServletContext;
22
23 /**
24  * Test BookmarkAction (proof-of-concept for Mockrunner Struts testing)
25  * @author Dave Johnson
26  */

27 public class BookmarksActionTest extends StrutsActionTestBase
28 {
29     public void testSelectFolder()
30     {
31         MockServletContext ctx = getMockFactory().getMockServletContext();
32         ctx.setServletContextName("/roller");
33         MockHttpServletRequest request = getMockFactory().getMockRequest();
34         request.setContextPath("/roller");
35
36         authenticateUser(mWebsite.getUser().getUserName(), "editor");
37         doFilters();
38
39         // Setup form bean
40
BookmarksForm form = (BookmarksForm)
41             strutsModule.createActionForm(BookmarksForm.class);
42
43         // Setup mapping and request parameters
44
MockActionMapping mapping = strutsModule.getMockActionMapping();
45         mapping.setupForwards(new String JavaDoc[] {"access-denied","BookmarksForm"});
46         mapping.setParameter("method");
47         strutsModule.addRequestParameter("method","selectFolder");
48         
49         strutsModule.actionPerform(BookmarksAction.class, form);
50         
51         // Test for success
52
strutsModule.verifyNoActionMessages();
53         strutsModule.verifyForward("BookmarksForm");
54         
55         // Verify objects we put in context for JSP page
56
verifyPageContext();
57     }
58     
59     protected void verifyPageContext()
60     {
61         HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)
62         servletModule.getFilteredRequest();
63         assertTrue(req.getAttribute("folder") instanceof FolderData);
64         assertTrue(req.getAttribute("folders") instanceof List JavaDoc);
65         assertTrue(req.getAttribute("bookmarks") instanceof Set JavaDoc);
66     }
67
68     public static Test suite()
69     {
70         return new TestSuite(BookmarksActionTest.class);
71     }
72 }
73
Popular Tags