Java Code Examples for org.apache.struts.action.ActionMapping#addForwardConfig()
The following examples show how to use
org.apache.struts.action.ActionMapping#addForwardConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginActionTest.java From spacewalk with GNU General Public License v2.0 | 6 votes |
public void testPerformNoPasswordName() { LoginAction action = new LoginAction(); ActionMapping mapping = new ActionMapping(); ActionForward failure = new ActionForward("failure", "path", false); PxtCookieManager pcm = new PxtCookieManager(); RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm"); RhnMockHttpServletRequest request = new RhnMockHttpServletRequest(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); request.setSession(new MockHttpSession()); request.setupServerName("mymachine.rhndev.redhat.com"); WebSession s = requestContext.getWebSession(); request.addCookie(pcm.createPxtCookie(s.getId(), request, 10)); mapping.addForwardConfig(failure); form.set("username", "someusername"); form.set("password", ""); ActionForward rc = action.execute(mapping, form, request, response); assertEquals(rc, failure); }
Example 2
Source File: LoginSetupActionTest.java From spacewalk with GNU General Public License v2.0 | 6 votes |
public void testUrlBounce() { LoginSetupAction action = new LoginSetupAction(); // setup stuff for Struts ActionMapping mapping = new ActionMapping(); mapping.addForwardConfig( new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false)); RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm"); RhnMockHttpServletRequest req = new RhnMockHttpServletRequest(); RhnMockHttpServletResponse resp = new RhnMockHttpServletResponse(); req.setSession(new MockHttpSession()); req.setupServerName("mymachine.rhndev.redhat.com"); req.addAttribute("url_bounce", "/rhn/UserDetails.do?sid=1"); // ok run it ActionForward rc = action.execute(mapping, form, req, resp); // verify String bounce = (String) req.getAttribute("url_bounce"); assertNotNull(bounce); assertEquals(bounce, "/rhn/UserDetails.do?sid=1"); assertNotNull(rc); assertEquals(RhnHelper.DEFAULT_FORWARD, rc.getName()); }
Example 3
Source File: ResetLinkActionTest.java From uyuni with GNU General Public License v2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); action = new ResetLinkAction(); mapping = new ActionMapping(); valid = new ActionForward("valid", "path", false); invalid = new ActionForward("invalid", "path", false); form = new RhnMockDynaActionForm("resetPasswordForm"); request = new RhnMockHttpServletRequest(); response = new RhnMockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); MockHttpSession mockSession = new MockHttpSession(); mockSession.setupGetAttribute("token", null); mockSession.setupGetAttribute("request_method", "GET"); request.setSession(mockSession); request.setupServerName("mymachine.rhndev.redhat.com"); WebSession s = requestContext.getWebSession(); mapping.addForwardConfig(valid); mapping.addForwardConfig(invalid); }
Example 4
Source File: ResetPasswordSubmitActionTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); adminUser = UserTestUtils.findNewUser("testAdminUser", "testOrg" + this.getClass().getSimpleName(), true); action = new ResetPasswordSubmitAction(); mapping = new ActionMapping(); mismatch = new ActionForward("mismatch", "path", false); invalid = new ActionForward("invalid", "path", false); badpwd = new ActionForward("badpwd", "path", false); form = new RhnMockDynaActionForm("resetPasswordForm"); request = new RhnMockHttpServletRequest(); response = new RhnMockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); MockHttpSession mockSession = new MockHttpSession(); mockSession.setupGetAttribute("token", null); mockSession.setupGetAttribute("request_method", "GET"); request.setSession(mockSession); request.setupServerName("mymachine.rhndev.redhat.com"); WebSession s = requestContext.getWebSession(); mapping.addForwardConfig(mismatch); mapping.addForwardConfig(invalid); mapping.addForwardConfig(badpwd); }
Example 5
Source File: CreateActionTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
public void testCreateErrata() { CreateAction action = new CreateAction(); ActionMapping mapping = new ActionMapping(); ActionForward failure = new ActionForward("failure", "path", false); ActionForward success = new ActionForward("success", "path", false); mapping.addForwardConfig(failure); mapping.addForwardConfig(success); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RhnMockHttpSession session = new RhnMockHttpSession(); request.setSession(session); request.setupServerName("mymachine.rhndev.redhat.com"); RhnMockDynaActionForm form = fillOutForm(); form.set("synopsis", ""); //required field, so we should get a validation error ActionForward result = action.execute(mapping, form, request, response); assertEquals(result.getName(), "failure"); //fillout form correctly form = fillOutForm(); result = action.execute(mapping, form, request, response); assertEquals(result.getName(), "success"); }
Example 6
Source File: NotifyActionTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
public void testNotifyAction() throws Exception { NotifyAction action = new NotifyAction(); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); MockHttpServletResponse response = new MockHttpServletResponse(); mapping.addForwardConfig(def); RequestContext requestContext = new RequestContext(request); User user = requestContext.getCurrentUser(); Errata published = ErrataFactoryTest .createTestPublishedErrata(user.getOrg().getId()); Channel c = ChannelFactoryTest.createBaseChannel(user); published.addChannel(c); Errata unpublished = ErrataFactoryTest .createTestUnpublishedErrata(user.getOrg().getId()); //test PublishOnly exception request.setupAddParameter("eid", unpublished.getId().toString()); try { action.execute(mapping, form, request, response); fail(); } catch (PublishedOnlyException e) { //Success!!! } //test default case request.setupAddParameter("eid", published.getId().toString()); ActionForward result = action.execute(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); Long id = published.getId(); flushAndEvict(published); Errata errata = ErrataManager.lookupErrata(id, user); assertEquals(1, errata.getNotificationQueue().size()); }
Example 7
Source File: LoginActionTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * In this test we actually return an HttpServletRequest so * this code can be reused by other tests to Login a user * and get the Request (with session) that appears logged * in. * In order for this test to be executed by JUnit we have to * wrap its call in the above method with a void return type. * @throws Exception something bad happened * @return a HttpServletRequest */ public HttpServletRequest loginUserIntoSessionTest() throws Exception { LoginAction action = new LoginAction(); User u = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName()); ActionMapping mapping = new ActionMapping(); mapping.addForwardConfig(new ActionForward("loggedin", "path", false)); PxtCookieManager pcm = new PxtCookieManager(); RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm"); RhnMockHttpServletRequest request = new RhnMockHttpServletRequest(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); MockHttpSession mockSession = new MockHttpSession(); mockSession.setupGetAttribute("url_bounce", null); mockSession.setupGetAttribute("request_method", "GET"); request.setSession(mockSession); request.setupServerName("mymachine.rhndev.redhat.com"); WebSession s = requestContext.getWebSession(); request.addCookie(pcm.createPxtCookie(s.getId(), request, 10)); form.set("username", u.getLogin()); /** * Since we know testUser's password is "password", just set that here. * using u.getPassword() will fail when we're using encrypted passwords. */ form.set("password", "password"); form.set("request_method", "POST"); ActionForward rc = action.execute(mapping, form, request, response); assertNull(rc); return request; }
Example 8
Source File: ResetPasswordSubmitActionTest.java From uyuni with GNU General Public License v2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); adminUser = UserTestUtils.findNewUser("testAdminUser", "testOrg" + this.getClass().getSimpleName(), true); action = new ResetPasswordSubmitAction(); mapping = new ActionMapping(); mismatch = new ActionForward("mismatch", "path", false); invalid = new ActionForward("invalid", "path", false); badpwd = new ActionForward("badpwd", "path", false); form = new RhnMockDynaActionForm("resetPasswordForm"); request = new RhnMockHttpServletRequest(); response = new RhnMockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); MockHttpSession mockSession = new MockHttpSession(); mockSession.setupGetAttribute("token", null); mockSession.setupGetAttribute("request_method", "GET"); request.setSession(mockSession); request.setupServerName("mymachine.rhndev.redhat.com"); WebSession s = requestContext.getWebSession(); mapping.addForwardConfig(mismatch); mapping.addForwardConfig(invalid); mapping.addForwardConfig(badpwd); }
Example 9
Source File: DeleteBugActionTest.java From uyuni with GNU General Public License v2.0 | 5 votes |
public void testDeleteBug() throws Exception { DeleteBugAction action = new DeleteBugAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", true); mapping.addForwardConfig(def); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RhnMockHttpSession session = new RhnMockHttpSession(); request.setSession(session); request.setupServerName("mymachine.rhndev.redhat.com"); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RequestContext requestContext = new RequestContext(request); //Create a test errata with a bug User user = requestContext.getCurrentUser(); Errata e = ErrataFactoryTest.createTestPublishedErrata(user.getOrg().getId()); Long bugId = 42L; String bugSummary = "This bug is tagged for destruction"; Bug bug = ErrataManagerTest.createNewPublishedBug(bugId, bugSummary); e.addBug(bug); ErrataManager.storeErrata(e); Long eid = e.getId(); assertEquals(1, e.getBugs().size()); //setup the request request.setupAddParameter("eid", eid.toString()); request.setupAddParameter("bid", bugId.toString()); ActionForward result = action.execute(mapping, form, request, response); assertEquals(result.getName(), RhnHelper.DEFAULT_FORWARD); flushAndEvict(e); //get rid of e Errata e2 = ErrataManager.lookupErrata(eid, user); assertTrue(e2.getBugs().isEmpty()); //make sure bug was removed }
Example 10
Source File: LoginActionTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
public void testDisabledUser() { LoginAction action = new LoginAction(); User u = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName()); UserManager.disableUser(u, u); ActionMapping mapping = new ActionMapping(); mapping.addForwardConfig(new ActionForward("failure", "path", false)); PxtCookieManager pcm = new PxtCookieManager(); RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm"); RhnMockHttpServletRequest request = new RhnMockHttpServletRequest(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); request.setSession(new MockHttpSession()); request.setupServerName("mymachine.rhndev.redhat.com"); WebSession s = requestContext.getWebSession(); request.addCookie(pcm.createPxtCookie(s.getId(), request, 10)); form.set("username", u.getLogin()); /** * Since we know testUser's password is "password", just set that here. * using u.getPassword() will fail when we're using encrypted passwords. */ form.set("password", "password"); ActionForward rc = action.execute(mapping, form, request, response); assertEquals("failure", rc.getName()); }
Example 11
Source File: EditActionTest.java From uyuni with GNU General Public License v2.0 | 5 votes |
public void testSetupExecute() throws Exception { EditAction action = new EditAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); MockHttpServletResponse response = new MockHttpServletResponse(); mapping.addForwardConfig(def); RequestContext requestContext = new RequestContext(request); User user = requestContext.getCurrentUser(); Errata errata = ErrataFactoryTest.createTestErrata(user.getOrg().getId()); request.setupAddParameter("eid", errata.getId().toString()); //make sure our form vars are null assertNull(form.get("synopsis")); //execute the action ActionForward result = action.unspecified(mapping, form, request, response); assertEquals(result.getName(), RhnHelper.DEFAULT_FORWARD); //make sure form was filled out properly assertEquals(form.get("synopsis"), errata.getSynopsis()); assertEquals(form.get("advisoryName"), errata.getAdvisoryName()); //check select list to make sure correct one is selected assertEquals(form.get("advisoryType"), errata.getAdvisoryType()); //We created a published errata above assertEquals(request.getAttribute("isPublished"), "true"); }
Example 12
Source File: NotifyActionTest.java From uyuni with GNU General Public License v2.0 | 5 votes |
public void testNotifyAction() throws Exception { NotifyAction action = new NotifyAction(); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); MockHttpServletResponse response = new MockHttpServletResponse(); mapping.addForwardConfig(def); RequestContext requestContext = new RequestContext(request); User user = requestContext.getCurrentUser(); Errata published = ErrataFactoryTest.createTestPublishedErrata(user.getOrg().getId()); Channel c = ChannelFactoryTest.createBaseChannel(user); published.addChannel(c); //test default case request.setupAddParameter("eid", published.getId().toString()); ActionForward result = action.execute(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); Long id = published.getId(); flushAndEvict(published); Errata errata = ErrataManager.lookupErrata(id, user); assertEquals(1, errata.getNotificationQueue().size()); }
Example 13
Source File: EditActionTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
public void testSetupExecute() throws Exception { EditAction action = new EditAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); MockHttpServletResponse response = new MockHttpServletResponse(); mapping.addForwardConfig(def); RequestContext requestContext = new RequestContext(request); User user = requestContext.getCurrentUser(); Errata errata = ErrataFactoryTest.createTestErrata(user.getOrg().getId()); request.setupAddParameter("eid", errata.getId().toString()); //make sure our form vars are null assertNull(form.get("synopsis")); //execute the action ActionForward result = action.unspecified(mapping, form, request, response); assertEquals(result.getName(), RhnHelper.DEFAULT_FORWARD); //make sure form was filled out properly assertEquals(form.get("synopsis"), errata.getSynopsis()); assertEquals(form.get("advisoryName"), errata.getAdvisoryName()); //check select list to make sure correct one is selected assertEquals(form.get("advisoryType"), errata.getAdvisoryType()); //We created a published errata above assertEquals(request.getAttribute("isPublished"), "true"); }
Example 14
Source File: UserPrefActionTest.java From uyuni with GNU General Public License v2.0 | 4 votes |
/** * * @throws Exception on server init failure */ public void testPerformExecute() throws Exception { UserPrefAction action = new UserPrefAction(); ActionMapping mapping = new ActionMapping(); ActionForward success = new ActionForward("success", "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); MockHttpServletResponse response = new MockHttpServletResponse(); mapping.addForwardConfig(success); RequestContext requestContext = new RequestContext(request); User user = UserManager.lookupUser(requestContext.getCurrentUser(), requestContext.getParamAsLong("uid")); request.setAttribute(RhnHelper.TARGET_USER, user); // we have to get the actual user here so we can call setupAddParamter // a second time. The MockRequest counts the number of times getParamter // is called. request.setupAddParameter("uid", user.getId().toString()); // populate with any set of information // then get the verify the user was changed correctly. form.set("emailNotif", Boolean.FALSE); form.set("email", Boolean.TRUE); form.set("call", Boolean.TRUE); form.set("fax", Boolean.TRUE); form.set("mail", Boolean.FALSE); form.set("pagesize", PAGE_SIZE); form.set("timezone", PREF_LOC); form.set("csvSeparator", ','); ActionForward rc = action.execute(mapping, form, request, response); // verify the correct ActionForward was returned assertTrue(rc.getName().equals("success")); assertEquals("path?uid=" + String.valueOf(user.getId()), rc.getPath()); assertFalse(rc.getRedirect()); assertEquals(PAGE_SIZE.intValue(), user.getPageSize()); }
Example 15
Source File: EditActionTest.java From uyuni with GNU General Public License v2.0 | 4 votes |
public void testUpdateErrata() throws Exception { EditAction action = new EditAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false); ActionForward failure = new ActionForward("failure", "path", false); ActionForward success = new ActionForward("updated", "path", true); mapping.addForwardConfig(def); mapping.addForwardConfig(failure); mapping.addForwardConfig(success); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RhnMockDynaActionForm form = new RhnMockDynaActionForm("errataEditForm"); //request.setSession(session); request.setupServerName("mymachine.rhndev.redhat.com"); RequestContext requestContext = new RequestContext(request); //Create a new unpublished errata User user = requestContext.getCurrentUser(); Errata errata = ErrataFactoryTest .createTestPublishedErrata(user.getOrg().getId()); //Create another for checking adv name uniqueness constraint Errata errata2 = ErrataFactoryTest .createTestPublishedErrata(user.getOrg().getId()); request.setupAddParameter("eid", errata.getId().toString()); request.setupAddParameter("eid", errata.getId().toString()); //Execute setupAction to fillout form ActionForward result = action.unspecified(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure form was filled out assertEquals(form.get("synopsis"), errata.getSynopsis()); //add empty buglistId & buglistSummary so validator doesn't freak out form.set("buglistId", ""); form.set("buglistSummary", ""); form.set("buglistUrlNew", ""); //make sure we still get validation errors request.setupAddParameter("eid", errata.getId().toString()); form.set("synopsis", ""); //required field, so we should get a validation error result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure adv name has to be unique request.setupAddParameter("eid", errata.getId().toString()); form.set("synopsis", "this errata has been edited"); form.set("advisoryName", errata2.getAdvisoryName()); result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure adv name cannot start with rh request.setupAddParameter("eid", errata.getId().toString()); form.set("advisoryName", "rh" + TestUtils.randomString()); result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure we can edit an errata String newAdvisoryName = errata.getAdvisoryName() + "edited"; /* * I hate it when Mock Objects don't act like the objects they mock */ request.setupAddParameter("eid", errata.getId().toString()); request.setupAddParameter("eid", errata.getId().toString()); form.set("advisoryName", newAdvisoryName); //add a bug form.set("buglistIdNew", "123"); form.set("buglistSummaryNew", "test bug for a test errata"); form.set("buglistUrlNew", "https://bugzilla.redhat.com/show_bug.cgi?id=123"); //edit the keywords form.set("keywords", "yankee, hotel, foxtrot"); Map<String, Object> params = new HashMap<String, Object>(); params.put("eid", errata.getId().toString()); params.put("buglistIdNew", "123"); params.put("buglistSummaryNew", "test bug for a test errata"); params.put("buglistUrlNew", "https://bugzilla.redhat.com/show_bug.cgi?id=123"); request.setupGetParameterMap(params); request.setupAddParameter("buglistIdNew", "123"); request.setupAddParameter("buglistSummaryNew", "test bug for a test errata"); request.setupAddParameter("buglistUrlNew", "https://bugzilla.redhat.com/show_bug.cgi?id=123"); result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //errata has now been edited... let's look it back up from the db and make sure //our changes were saved. Long id = errata.getId(); flushAndEvict(errata); //kick errata from session Errata edited = ErrataManager.lookupErrata(id, user); //make sure adv name was changed assertEquals(edited.getAdvisoryName(), newAdvisoryName); //make sure keywords were added assertEquals(3, edited.getKeywords().size()); //make sure bug was added assertEquals(1, edited.getBugs().size()); }
Example 16
Source File: UserPrefActionTest.java From spacewalk with GNU General Public License v2.0 | 4 votes |
/** * * @throws Exception on server init failure */ public void testPerformExecute() throws Exception { UserPrefAction action = new UserPrefAction(); ActionMapping mapping = new ActionMapping(); ActionForward success = new ActionForward("success", "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); MockHttpServletResponse response = new MockHttpServletResponse(); mapping.addForwardConfig(success); RequestContext requestContext = new RequestContext(request); User user = UserManager.lookupUser(requestContext.getCurrentUser(), requestContext.getParamAsLong("uid")); request.setAttribute(RhnHelper.TARGET_USER, user); // we have to get the actual user here so we can call setupAddParamter // a second time. The MockRequest counts the number of times getParamter // is called. request.setupAddParameter("uid", user.getId().toString()); // populate with any set of information // then get the verify the user was changed correctly. form.set("emailNotif", Boolean.FALSE); form.set("email", Boolean.TRUE); form.set("call", Boolean.TRUE); form.set("fax", Boolean.TRUE); form.set("mail", Boolean.FALSE); form.set("pagesize", PAGE_SIZE); form.set("csvSeparator", ','); ActionForward rc = action.execute(mapping, form, request, response); // verify the correct ActionForward was returned assertTrue(rc.getName().equals("success")); assertEquals("path?uid=" + String.valueOf(user.getId()), rc.getPath()); assertFalse(rc.getRedirect()); assertEquals(PAGE_SIZE.intValue(), user.getPageSize()); }
Example 17
Source File: EditActionTest.java From spacewalk with GNU General Public License v2.0 | 4 votes |
public void testUpdateErrata() throws Exception { EditAction action = new EditAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", false); ActionForward failure = new ActionForward("failure", "path", false); ActionForward success = new ActionForward("updated", "path", true); mapping.addForwardConfig(def); mapping.addForwardConfig(failure); mapping.addForwardConfig(success); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RhnMockDynaActionForm form = new RhnMockDynaActionForm("errataEditForm"); //request.setSession(session); request.setupServerName("mymachine.rhndev.redhat.com"); RequestContext requestContext = new RequestContext(request); //Create a new unpublished errata User user = requestContext.getCurrentUser(); Errata errata = ErrataFactoryTest .createTestUnpublishedErrata(user.getOrg().getId()); //Create another for checking adv name uniqueness constraint Errata errata2 = ErrataFactoryTest .createTestUnpublishedErrata(user.getOrg().getId()); request.setupAddParameter("eid", errata.getId().toString()); request.setupAddParameter("eid", errata.getId().toString()); //Execute setupAction to fillout form ActionForward result = action.unspecified(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure form was filled out assertEquals(form.get("synopsis"), errata.getSynopsis()); //add empty buglistId & buglistSummary so validator doesn't freak out form.set("buglistId", ""); form.set("buglistSummary", ""); form.set("buglistUrlNew", ""); //make sure we still get validation errors request.setupAddParameter("eid", errata.getId().toString()); form.set("synopsis", ""); //required field, so we should get a validation error result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure adv name has to be unique request.setupAddParameter("eid", errata.getId().toString()); form.set("synopsis", "this errata has been edited"); form.set("advisoryName", errata2.getAdvisoryName()); result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure adv name cannot start with rh request.setupAddParameter("eid", errata.getId().toString()); form.set("advisoryName", "rh" + TestUtils.randomString()); result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //make sure we can edit an errata String newAdvisoryName = errata.getAdvisoryName() + "edited"; /* * I hate it when Mock Objects don't act like the objects they mock */ request.setupAddParameter("eid", errata.getId().toString()); request.setupAddParameter("eid", errata.getId().toString()); form.set("advisoryName", newAdvisoryName); //add a bug form.set("buglistIdNew", "123"); form.set("buglistSummaryNew", "test bug for a test errata"); form.set("buglistUrlNew", "https://bugzilla.redhat.com/show_bug.cgi?id=123"); //edit the keywords form.set("keywords", "yankee, hotel, foxtrot"); Map<String, Object> params = new HashMap<String, Object>(); params.put("eid", errata.getId().toString()); params.put("buglistIdNew", "123"); params.put("buglistSummaryNew", "test bug for a test errata"); params.put("buglistUrlNew", "https://bugzilla.redhat.com/show_bug.cgi?id=123"); request.setupGetParameterMap(params); request.setupAddParameter("buglistIdNew", "123"); request.setupAddParameter("buglistSummaryNew", "test bug for a test errata"); request.setupAddParameter("buglistUrlNew", "https://bugzilla.redhat.com/show_bug.cgi?id=123"); result = action.update(mapping, form, request, response); assertEquals(RhnHelper.DEFAULT_FORWARD, result.getName()); //errata has now been edited... let's look it back up from the db and make sure //our changes were saved. Long id = errata.getId(); flushAndEvict(errata); //kick errata from session Errata edited = ErrataManager.lookupErrata(id, user); //make sure adv name was changed assertEquals(edited.getAdvisoryName(), newAdvisoryName); //make sure keywords were added assertEquals(3, edited.getKeywords().size()); //make sure bug was added assertEquals(1, edited.getBugs().size()); }
Example 18
Source File: ChannelActionTest.java From spacewalk with GNU General Public License v2.0 | 4 votes |
public void testPublish() throws Exception { MessageQueue.configureDefaultActions(); ChannelAction action = new ChannelAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", true); ActionForward publish = new ActionForward("publish", "path", true); ActionForward failure = new ActionForward("failure", "path", false); mapping.addForwardConfig(def); mapping.addForwardConfig(publish); mapping.addForwardConfig(failure); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RhnMockHttpSession session = new RhnMockHttpSession(); request.setSession(session); request.setupServerName("mymachine.rhndev.redhat.com"); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RequestContext requestContext = new RequestContext(request); User usr = requestContext.getCurrentUser(); //create the errata Errata errata = ErrataFactoryTest.createTestUnpublishedErrata(usr.getOrg().getId()); //We can't publish without selecting channels. Make sure we get an error. request.setupAddParameter("eid", errata.getId().toString()); request.setupAddParameter("items_on_page", ""); request.setupAddParameter("items_selected", new String[0]); ActionForward result = action.publish(mapping, form, request, response); assertEquals("failure", result.getName()); //now create the channel Channel c1 = ChannelFactoryTest.createTestChannel(usr); //setup the request request.setupAddParameter("eid", errata.getId().toString()); request.setupAddParameter("items_on_page", ""); request.setupAddParameter("items_selected", c1.getId().toString()); result = action.publish(mapping, form, request, response); //we won't know the id of the published errata, so all we can do is make sure //we got forwarded to publish assertEquals(result.getName(), "publish"); }
Example 19
Source File: ChannelActionTest.java From spacewalk with GNU General Public License v2.0 | 4 votes |
public void testUpdateChannels() throws Exception { ChannelAction action = new ChannelAction(); ActionMapping mapping = new ActionMapping(); ActionForward def = new ActionForward(RhnHelper.DEFAULT_FORWARD, "path", true); ActionForward failure = new ActionForward("failure", "path", false); ActionForward push = new ActionForward("push", "path", false); mapping.addForwardConfig(def); mapping.addForwardConfig(failure); mapping.addForwardConfig(push); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); RhnMockHttpServletResponse response = new RhnMockHttpServletResponse(); RhnMockHttpSession session = new RhnMockHttpSession(); request.setSession(session); request.setupServerName("mymachine.rhndev.redhat.com"); RhnMockDynaActionForm form = new RhnMockDynaActionForm(); RequestContext requestContext = new RequestContext(request); User user = requestContext.getCurrentUser(); user.addPermanentRole(RoleFactory.CHANNEL_ADMIN); //create the errata Errata errata = ErrataFactoryTest. createTestPublishedErrata(user.getOrg().getId()); //get the id for errata and flush so things get stored to the db Long id = errata.getId(); flushAndEvict(errata); //We can't take away all channels. make sure we get an error request.setupAddParameter("eid", id.toString()); request.setupAddParameter("items_on_page", ""); request.setupAddParameter("items_selected", new String[0]); ActionForward result = action.publish(mapping, form, request, response); assertEquals("failure", result.getName()); //make sure we can add channels //first create the channel family //now create the channels Channel c1 = ChannelFactoryTest.createTestChannel(user); Channel c2 = ChannelFactoryTest.createTestChannel(user); //setup the request String[] selected = {c1.getId().toString(), c2.getId().toString()}; request.setupAddParameter("eid", id.toString()); request.setupAddParameter("items_on_page", ""); request.setupAddParameter("items_selected", selected); result = action.updateChannels(mapping, form, request, response); assertEquals("push", result.getName()); //Lookup the errata and make sure there are at least 2 channels Errata e2 = ErrataManager.lookupErrata(errata.getId(), user); int size = e2.getChannels().size(); assertTrue(size >= 2); //clear the set RhnSetFactory.save(RhnSetDecl.CHANNELS_FOR_ERRATA.get(user)); RhnSetDecl.CHANNELS_FOR_ERRATA.clear(user); RhnSetFactory.remove(RhnSetDecl.CHANNELS_FOR_ERRATA.get(user)); //make sure we can take away channels //setup the request String[] selected2 = {c2.getId().toString()}; request.setupAddParameter("eid", id.toString()); request.setupAddParameter("items_on_page", ""); request.setupAddParameter("items_selected", selected2); result = action.updateChannels(mapping, form, request, response); assertEquals("push", result.getName()); Errata e3 = ErrataManager.lookupErrata(errata.getId(), user); assertTrue(e3.getChannels().size() < size); //less than before }
Example 20
Source File: UserEditActionTest.java From uyuni with GNU General Public License v2.0 | 4 votes |
/** * Test the SelfEditAction */ public void testSelfEditAction() { SelfEditAction action = new SelfEditAction(); ActionMapping mapping = new ActionMapping(); ActionForward success = new ActionForward("success", "path", false); ActionForward failure = new ActionForward("failure", "path", false); RhnMockDynaActionForm form = new RhnMockDynaActionForm("userDetailsForm"); RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext requestContext = new RequestContext(request); mapping.addForwardConfig(success); mapping.addForwardConfig(failure); User user = UserManager.lookupUser(requestContext.getCurrentUser(), requestContext.getParamAsLong("uid")); request.setAttribute(RhnHelper.TARGET_USER, user); //Try password mismatch request.setupAddParameter("uid", user.getId().toString()); form.set("prefix", user.getPrefix()); form.set("firstNames", user.getFirstNames()); form.set("lastName", user.getLastName()); form.set("title", user.getTitle()); form.set(UserActionHelper.DESIRED_PASS, "foobar"); form.set(UserActionHelper.DESIRED_PASS_CONFIRM, "foobar-foobar"); ActionForward result = action.execute(mapping, form, request, response); assertTrue(result.getName().equals("failure")); //Try validation errors request.setupAddParameter("uid", user.getId().toString()); form.set(UserActionHelper.DESIRED_PASS_CONFIRM, "foobar"); form.set("firstNames", ""); result = action.execute(mapping, form, request, response); assertTrue(result.getName().equals("failure")); //Try Valid edit request.setupAddParameter("uid", user.getId().toString()); form.set("firstNames", "Larry"); result = action.execute(mapping, form, request, response); assertTrue(result.getName().equals("success")); //make sure our user was updated assertEquals("Larry", user.getFirstNames()); }