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