1 18 21 package org.apache.roller.ui.authoring.struts.actions; 22 23 24 25 import com.mockrunner.mock.web.MockActionMapping; 26 import com.mockrunner.mock.web.MockHttpServletRequest; 27 import com.mockrunner.mock.web.MockServletContext; 28 29 import javax.servlet.http.HttpServletRequest ; 30 31 import junit.framework.Test; 32 import junit.framework.TestSuite; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 37 import org.apache.roller.RollerException; 38 import org.apache.roller.TestUtils; 39 import org.apache.roller.model.RollerFactory; 40 import org.apache.roller.model.UserManager; 41 import org.apache.roller.pojos.FolderData; 42 import org.apache.roller.pojos.UserData; 43 import org.apache.roller.pojos.WebsiteData; 44 import org.apache.roller.ui.StrutsActionTestBase; 45 import org.apache.roller.ui.authoring.struts.formbeans.BookmarksForm; 46 import org.apache.roller.ui.core.BasePageModel; 47 import org.apache.roller.ui.core.RollerRequest; 48 49 53 public class BookmarksActionTest extends StrutsActionTestBase { 54 private WebsiteData testWeblog = null; 55 private UserData testUser = null; 56 public static Log log = LogFactory.getLog(BookmarksActionTest.class); 57 58 61 public void setUp() throws Exception { 62 super.setUp(); 63 try { 64 testUser = TestUtils.setupUser("bkmrkTestUser"); 65 testWeblog = TestUtils.setupWeblog("bkmrkTestWeblog", testUser); 66 TestUtils.endSession(true); 67 } catch (Exception ex) { 68 log.error(ex); 69 throw new Exception ("Test setup failed", ex); 70 } 71 } 72 73 public void tearDown() throws Exception { 74 super.tearDown(); 75 try { 76 TestUtils.teardownWeblog(testWeblog.getId()); 77 TestUtils.teardownUser(testUser.getId()); 78 TestUtils.endSession(true); 79 } catch (Exception ex) { 80 log.error(ex); 81 throw new Exception ("Test teardown failed", ex); 82 } 83 } 84 85 public void testSelectFolder() { 86 MockServletContext ctx = getMockFactory().getMockServletContext(); 87 ctx.setServletContextName("/roller"); 88 MockHttpServletRequest request = getMockFactory().getMockRequest(); 89 request.setContextPath("/roller"); 90 91 UserManager umgr = null; 92 UserData user = null; 93 try { 94 umgr = RollerFactory.getRoller().getUserManager(); 95 user = (UserData)umgr.getUsers(testWeblog, null, 0, Integer.MAX_VALUE).get(0); 96 doFilters(); 97 authenticateUser(user.getUserName(), "editor"); 98 } catch (RollerException e) { 99 e.printStackTrace(); 100 fail(); 101 } 102 103 BookmarksForm form = (BookmarksForm) 105 strutsModule.createActionForm(BookmarksForm.class); 106 107 MockActionMapping mapping = strutsModule.getMockActionMapping(); 109 mapping.setupForwards(new String [] {"access-denied","BookmarksForm"}); 110 mapping.setParameter("method"); 111 strutsModule.addRequestParameter("weblog",testWeblog.getHandle()); 112 strutsModule.addRequestParameter("method","selectFolder"); 113 114 try { 115 RollerRequest rreq = new RollerRequest(strutsModule.getMockPageContext()); 116 rreq.setWebsite(testWeblog); 117 strutsModule.setRequestAttribute(RollerRequest.ROLLER_REQUEST, rreq); 118 strutsModule.actionPerform(BookmarksAction.class, form); 119 } catch (Throwable e) { 120 e.printStackTrace(); 121 fail(); 122 } 123 strutsModule.verifyNoActionMessages(); 125 strutsModule.verifyForward("BookmarksForm"); 126 127 verifyPageContext(); 129 } 130 131 protected void verifyPageContext() { 132 HttpServletRequest req = (HttpServletRequest) 133 servletModule.getFilteredRequest(); 134 assertTrue(req.getAttribute("folder") instanceof FolderData); 135 assertTrue(req.getAttribute("model") instanceof BasePageModel); 136 } 137 138 public static Test suite() { 139 return new TestSuite(BookmarksActionTest.class); 140 } 141 142 } 143 | Popular Tags |