1 21 package com.jaspersoft.jasperserver.war; 22 23 import com.meterware.httpunit.Button; 24 import com.meterware.httpunit.SubmitButton; 25 import com.meterware.httpunit.WebForm; 26 import com.meterware.httpunit.WebResponse; 27 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 32 33 38 public class HttpUnitEditRoleTest 39 extends HttpUnitBaseTestCase { 40 41 private static String editRoleUserUrl = JasperServerConstants.BASE_URL + 42 "/jasperserver/editRoleSelectingUsers.html"; 43 private static String editRolePageText1 = "Only Users with this role?"; 44 private static String editRolePageText2 = "EDIT ROLE - USERS"; 45 private static String createEditPageText1 = "CREATE / EDIT USER"; 46 private static String createEditPageText2 = "Test_User"; 47 private static String pageText = "Users for Role"; 48 private static String viewEditBtnText = "btEdView"; 49 private static String cancelButtonText = "btcancsave"; 50 private static String submitButtonText = "btSaveUser"; 51 private static String textFieldText = "username"; 52 private static String chkBoxText = "enabled"; 53 private static String editRoleFormNameText = "fmRolSelUsr"; 54 private static String editUserFormNameText = "fmCreEdUsr"; 55 private static String editPgeText = "User"; 56 57 private static WebForm editRoleForm; 58 private static WebForm editUserForm; 59 private static SubmitButton editRoleSubmit; 60 61 66 public HttpUnitEditRoleTest(String s) { 67 super(s); 68 } 69 70 75 public void setUp() 76 throws Exception { 77 wResponse = commonLoginFunction(editRoleUserUrl); 78 } 79 80 81 85 86 93 public void testEditDetailsPage() 94 throws Exception { 95 96 WebResponse editDetailResponse = this.getWebConversation().getCurrentPage(); 97 assertNotNull("User searsh page is null", editDetailResponse); 98 99 String str = editDetailResponse.getText(); 100 assertNotNull("page is null", str); 101 102 if(str == null ||str.trim().length()==0) 103 fail("There is no text on response"); 104 assertTrue(str.indexOf(editRolePageText1)!= -1 && str.indexOf(editRolePageText2)!= -1); 105 106 assertNotNull("The View/Edit button Element is not present", 108 editDetailResponse.getElementsWithName(viewEditBtnText)); 109 110 assertNotNull(textFieldText+"textfield Element is not present", 112 editDetailResponse.getElementsWithName(textFieldText)); 113 114 assertNotNull(chkBoxText+"Element is not present", 116 editDetailResponse.getElementsWithName(chkBoxText)); 117 } 118 119 128 public void testSimpleEditBtnFlow()throws Exception { 129 130 WebResponse editBtnResponse = this.getWebConversation().getCurrentPage(); 131 132 editRoleForm = editBtnResponse.getFormWithName(editRoleFormNameText); 133 assertNotNull("Form is null", editRoleForm); 134 135 editRoleSubmit = editRoleForm.getSubmitButton(viewEditBtnText); 136 assertNotNull("Button is null", editRoleSubmit); 137 138 editRoleForm.submit(editRoleSubmit); 139 140 141 WebResponse editUserPage = this.getWebConversation().getCurrentPage(); 142 143 String str = editUserPage.getText(); 144 assertNotNull("Text is null", str); 145 if(str == null || str.trim().length()==0) 146 fail("There is no text on response"); 147 148 assertTrue(str.indexOf(editPgeText)!= -1); 149 150 editUserForm = editUserPage.getFormWithName(editUserFormNameText); 151 assertNotNull("Form is null", editRoleForm); 152 153 SubmitButton cancelButton = editUserForm.getSubmitButton(cancelButtonText); 154 assertNotNull("Button is null", editRoleSubmit); 155 156 editUserForm.submit(cancelButton); 157 158 WebResponse bckEditRolePage = this.getWebConversation().getCurrentPage(); 159 160 String string = bckEditRolePage.getText(); 161 assertNotNull("Page text is null", string); 162 if(string == null || string.trim().length()==0) 163 fail("There is no text on response"); 164 165 assertTrue(string.indexOf(editRolePageText2)!= -1); 166 } 167 168 176 public void testEditBtnFunctionality() throws Exception { 177 178 WebResponse editRolePage = this.getWebConversation().getCurrentPage(); 179 180 editRoleForm = editRolePage.getFormWithName(editRoleFormNameText); 181 assertNotNull("Form is null", editRoleForm); 182 183 editRoleSubmit = editRoleForm.getSubmitButton(viewEditBtnText); 184 assertNotNull("Button is null", editRoleSubmit); 185 186 editRoleForm.getScriptableObject().setParameterValue("userselected","TestUser"); 187 editRoleForm.getScriptableObject().setParameterValue("editroleuseraction","viewedituser"); 188 189 editRoleForm.submit(editRoleSubmit); 190 191 WebResponse editUserPage = this.getWebConversation().getCurrentPage(); 193 194 String string = editUserPage.getText(); 195 assertNotNull("page text is null", string); 196 197 if(string==null || string.trim().length()==0) 198 fail("No text found on the page on response"); 199 200 assertTrue(string.indexOf(editPgeText)!= -1); 201 202 WebResponse response = this.getWebConversation().getCurrentPage(); 204 205 editUserForm = response.getFormWithName(editUserFormNameText); 206 assertNotNull("Form is null", editUserForm); 207 208 214 215 Button buttons[] = editUserForm.getButtons(); 217 Button saveButton = null; 218 boolean found = false; 219 220 if(buttons != null){ 221 for(int i=0; i<buttons.length; i++){ 222 saveButton = buttons[i]; 223 if(saveButton.getName().equalsIgnoreCase(submitButtonText)){ 224 found = true; 225 break; 226 } 227 } 228 } 229 230 assertTrue("Button is null", found); 231 232 editUserForm.setParameter("username", "TestUser"); 233 editUserForm.setParameter("fullName", "Test_User"); 234 editUserForm.setParameter("password", "newPassword"); 235 editUserForm.setParameter("repassword", "newPassword"); 236 237 saveButton.click(); 238 240 241 WebResponse bkEditRolePage = this.getWebConversation().getCurrentPage(); 243 244 String str = bkEditRolePage.getText(); 245 assertNotNull("page text is null", str); 246 247 if(str==null || str.trim().length()==0) 248 fail("No text found on the page on response"); 249 250 assertTrue(str.indexOf(pageText)!= -1); 251 252 editRoleForm.getScriptableObject().setParameterValue("userselected","TestUser"); 254 editRoleForm.getScriptableObject().setParameterValue("editroleuseraction","viewedituser"); 255 256 editRoleForm.submit(editRoleSubmit); 257 258 WebResponse bkEditUserPage = this.getWebConversation().getCurrentPage(); 260 261 String page = bkEditUserPage.getText(); 262 assertNotNull("page text is null", page); 263 264 if(page==null || page.trim().length()==0) 265 fail("No text found on the page on response"); 266 267 assertTrue(page.indexOf(createEditPageText1)!= -1 && page.indexOf(createEditPageText2)!= -1); 268 269 } 270 271 272 276 277 278 281 protected String [] getloginCredentials() { 282 return new String [] { USERNAME, PASSWORD }; 283 } 284 285 289 290 295 public static void main(String [] args) { 296 try { 297 junit.textui.TestRunner.run(suite()); 298 } catch (Exception _ex) { 299 _ex.printStackTrace(); 300 } 301 } 302 303 310 public static Test suite() 311 throws Exception { 312 TestSuite suite = new TestSuite(); 313 314 TestCase test1 = new HttpUnitEditRoleTest("testEditDetailsPage"); 315 TestCase test2 = new HttpUnitEditRoleTest("testSimpleEditBtnFlow"); 316 TestCase test3 = new HttpUnitEditRoleTest("testEditBtnFunctionality"); 317 318 suite.addTest(test1); 319 suite.addTest(test2); 320 suite.addTest(test3); 322 323 return suite; 324 } 325 326 } | Popular Tags |