1 21 22 package com.jaspersoft.jasperserver.war; 23 24 import com.meterware.httpunit.SubmitButton; 25 import com.meterware.httpunit.WebForm; 26 import com.meterware.httpunit.WebLink; 27 import com.meterware.httpunit.WebResponse; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 38 public class HttpUnitRoleMgmtTest 39 extends HttpUnitBaseTestCase { 40 private static String editRolePageUrl = BASE_URL +"/jasperserver/editrole.html"; 41 private static String createUserText = "Role Management"; 42 private static String roleNameText = "Role Name:"; 43 private static String userRolePageText = "Users for Role"; 44 private static String editUserPageText = "TestUser"; 45 private static String saveRoleBtnText = "btsubmit"; 46 private static String roleNameFldText = "roleName"; 47 private static String formNameText = "fmCreEdRole"; 48 private static String roleSelFormText = "fmRolSelUsr"; 49 private static String editPageFormText = "fmCreEdUsr"; 50 private static String cancelBtnText = "btcancsave"; 51 private static String editBtnText = "btEdView"; 52 private static String saveBtnText = "btSaveUser"; 53 private static String usrRoleLink = "Users for Role"; 54 private static String roleMgmtLink = "Role Management"; 55 private static String adminStatusText = "Role is saved successfully into the Database"; 56 57 private static WebForm form; 58 59 64 public HttpUnitRoleMgmtTest(String s) { 65 super(s); 66 } 67 68 73 public void setUp() 74 throws Exception { 75 wResponse = commonLoginFunction(editRolePageUrl); 76 } 77 78 79 83 84 94 public void testEditRolePage() 95 throws Exception { 96 97 WebResponse roleMgmtPage = this.getWebConversation().getCurrentPage(); 98 assertNotNull("User search page is null", roleMgmtPage); 99 100 String string = roleMgmtPage.getText(); 101 assertNotNull("Role Mgmt page is null", string); 102 103 if ((string == null) || (string.trim().length() == 0)) 104 fail("Text is not found on wResponse"); 105 106 assertTrue(string.indexOf(roleNameText) != -1); 107 108 assertNotNull("The Save Role Element is not present", 110 roleMgmtPage.getElementsWithName(saveRoleBtnText)); 111 112 assertNotNull("The Role Name Element is not present", 114 roleMgmtPage.getElementsWithName(roleNameFldText)); 115 116 WebForm form = roleMgmtPage.getFormWithName(formNameText); 118 SubmitButton submitBtn = form.getSubmitButton(saveRoleBtnText); 119 120 form.setParameter("roleName", "Tom"); 121 122 form.submit(submitBtn); 123 124 WebResponse adminStatusPage = this.getWebConversation().getCurrentPage(); 126 127 String str = adminStatusPage.getText(); 128 assertNotNull("text page is null", str); 129 130 if(str == null ||str.trim().length()==0) 131 fail("There is no text on response"); 132 133 assertTrue(str.indexOf(adminStatusText)!= -1); 134 135 WebLink adminPageLink = adminStatusPage.getLinkWith(roleMgmtLink); 136 assertNotNull("The link is Null", adminPageLink); 137 138 adminStatusPage = adminPageLink.click(); 139 140 WebResponse bckCreatePage = this.getWebConversation().getCurrentPage(); 142 143 String page = bckCreatePage.getText(); 144 assertNotNull("text on page is Null", page); 145 146 if(page == null || page.trim().length()==0) 147 fail("There is no text on response"); 148 149 assertTrue(page.indexOf(createUserText)!= -1); 150 } 151 152 160 public void testEditPageLink() throws Exception { 161 162 WebResponse roleMgmtPage = this.getWebConversation().getCurrentPage(); 163 164 WebLink link = roleMgmtPage.getLinkWith(usrRoleLink); 165 assertNotNull("Link is Null", link); 166 167 form = roleMgmtPage.getFormWithName(formNameText); 168 form.setParameter("roleName", "Tom"); 169 170 roleMgmtPage = link.click(); 171 172 assertNotNull("User Role Link is Null", roleMgmtPage); 173 174 WebResponse editRolePage = this.getWebConversation().getCurrentPage(); 175 176 String role = editRolePage.getText(); 177 assertNotNull("page text is Null", role); 178 179 if((role == null)||(role.trim().length()==0)) 180 fail("There is no text in response"); 181 182 assertTrue(role.indexOf(userRolePageText)!= -1); 183 184 WebForm userRoleForm = editRolePage.getFormWithName(roleSelFormText); 185 assertNotNull("Form is Null", userRoleForm); 186 187 SubmitButton editButton = userRoleForm.getSubmitButton(editBtnText); 188 assertNotNull("Button is Null", editButton); 189 190 userRoleForm.getScriptableObject().setParameterValue("userselected","TestUser"); 191 192 userRoleForm.submit(editButton); 193 194 WebResponse editUserPage = this.getWebConversation().getCurrentPage(); 195 196 String string = editUserPage.getText(); 197 assertNotNull("page text is Null", string); 198 199 if((string == null)||(string.trim().length()==0)) 200 fail("There is no text in response"); 201 202 assertTrue(string.indexOf(editUserPageText)!= -1); 203 204 assertNotNull("The Save Role Element is not present", 206 editUserPage.getElementsWithName(saveBtnText)); 207 208 WebForm editForm = editUserPage.getFormWithName(editPageFormText); 209 assertNotNull("Form is Null", editForm); 210 211 SubmitButton cancelBtn = editForm.getSubmitButton(cancelBtnText); 212 assertNotNull("Button is Null", cancelBtn); 213 214 editForm.submit(cancelBtn); 215 216 WebResponse bckUserRolePage = this.getWebConversation().getCurrentPage(); 217 218 String str = bckUserRolePage.getText(); 219 assertNotNull("page text is Null", str); 220 221 if(str == null || str.trim().length()==0) 222 fail("There is no text on the page"); 223 224 assertTrue(str.indexOf(userRolePageText)!= -1); 225 } 226 227 228 236 public void testErrorLink() throws Exception { 237 238 WebResponse roleMgmtPage = this.getWebConversation().getCurrentPage(); 239 WebLink errorLink = roleMgmtPage.getLinkWith(usrRoleLink); 240 241 form.setParameter("roleName", "test"); 242 roleMgmtPage = errorLink.click(); 243 244 } 245 246 247 251 252 255 protected String [] getloginCredentials() { 256 return new String [] { USERNAME, PASSWORD }; 257 } 258 259 260 264 265 270 public static void main(String [] args) { 271 try { 272 junit.textui.TestRunner.run(suite()); 273 } catch (Exception _ex) { 274 _ex.printStackTrace(); 275 } 276 } 277 284 public static Test suite() 285 throws Exception { 286 TestSuite suite = new TestSuite(); 287 288 TestCase test1 = new HttpUnitRoleMgmtTest("testEditRolePage"); 289 TestCase test2 = new HttpUnitRoleMgmtTest("testEditPageLink"); 290 291 suite.addTest(test1); 292 suite.addTest(test2); 293 return suite; 294 } 295 } | Popular Tags |