1 25 26 package org.objectweb.jonas.jonasadmin.test.domain; 27 28 29 import junit.framework.TestSuite; 30 31 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth; 32 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase; 33 import org.xml.sax.SAXException ; 34 35 import com.meterware.httpunit.HttpUnitOptions; 36 import com.meterware.httpunit.HttpUnitUtils; 37 import com.meterware.httpunit.TableCell; 38 import com.meterware.httpunit.WebConversation; 39 import com.meterware.httpunit.WebLink; 40 import com.meterware.httpunit.WebResponse; 41 import com.meterware.httpunit.WebTable; 42 43 48 public class F_JonasAdminDomain extends JonasAdminTestCase { 49 50 53 private static final String TITLE_OTHERSERVERS = "Other servers in domain"; 54 55 59 public static void main(String [] args) { 60 61 String testtorun = null; 62 for (int argn = 0; argn < args.length; argn++) { 64 String sArg = args[argn]; 65 if (sArg.equals("-n")) { 66 testtorun = args[++argn]; 67 } 68 } 69 if (testtorun == null) { 70 junit.textui.TestRunner.run(suite()); 71 } else { 72 junit.textui.TestRunner.run(new F_JonasAdminDomain(testtorun)); 73 } 74 } 75 76 80 public static TestSuite suite() { 81 return new TestSuite(F_JonasAdminDomain.class); 82 } 83 84 89 public static TestSuite suite(WebConversation wc) { 90 TestSuite suite = new TestSuite(); 91 suite.addTest(new F_JonasAdminDomain(wc, "testSuccessfulSelect")); 92 suite.addTest(new F_JonasAdminDomain(wc, "testSuccesfulServerLink")); 93 suite.addTest(new F_JonasAdminDomain(wc, "testOtherServers")); 94 return suite; 95 } 96 97 102 protected void setUp() throws Exception { 103 super.setUp(); 104 105 if (wc.getCurrentPage().getURL() == null) { 106 useWar("jonasAdmin"); 107 try { 109 JonasAdminAuth.doValidAuth(wc, url); 110 } catch (Exception e) { 111 fail("authentification failed : " + e); 112 } 113 } else { 114 try { 116 wc.getFrameContents(FRAME_TREE); 117 } catch (Exception e) { 118 wc.getResponse(urlLogOut); 119 try { 121 JonasAdminAuth.doValidAuth(wc, url); 122 } catch (Exception auth) { 123 fail("authentification failed : " + auth); 124 } 125 } 126 } 127 } 128 129 130 134 public F_JonasAdminDomain(String s) { 135 super(s, URL_JONASADMIN); 136 } 137 138 143 public F_JonasAdminDomain(WebConversation wc, String s) { 144 super(wc, s, URL_JONASADMIN); 145 } 146 147 153 private boolean treeControlSelected (WebResponse wr, String name) { 154 boolean isSelected = false; int nbSelectedLink = 0; String attribut; 158 WebLink[] links; 160 try { 161 links = wr.getLinks(); 162 163 for (int i = 0; i < links.length; i++) { 166 attribut = links[i].getAttribute("class"); 167 if (attribut.indexOf("tree-control-selected") != -1) { 168 nbSelectedLink++; 169 } 170 } 171 172 if (nbSelectedLink == 1) { 173 WebLink link = wr.getLinkWith(name); 174 String content = link.getAttribute("class"); 175 if (content.indexOf("tree-control-selected") != -1) { 176 isSelected = true; 177 } 178 } 179 } catch (SAXException e) { 180 fail("No link was found. " + e); 181 } 182 183 return isSelected; 184 } 185 186 187 192 public void testSuccessfulSelect() throws Exception { 193 194 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 196 197 WebResponse treeFrame = wc.getFrameContents(FRAME_TREE); 199 200 WebLink link = treeFrame.getLinkWith("Domain"); 202 link.click(); 203 204 treeFrame = wc.getFrameContents(FRAME_TREE); 206 207 if (!treeControlSelected(treeFrame, "Domain")) { 210 fail("Domain is not selected in the tree."); 211 } 212 213 link = treeFrame.getLinkWith("Services"); 215 link.click(); 216 217 treeFrame = wc.getFrameContents(FRAME_TREE); 219 220 if (treeControlSelected(treeFrame, "Domain")) { 223 fail("Domain is selected in the tree."); 224 } 225 226 227 link = treeFrame.getLinkWith("Domain"); 229 link.click(); 230 231 treeFrame = wc.getFrameContents(FRAME_TREE); 233 234 if (!treeControlSelected(treeFrame, "Domain")) { 237 fail("Domain is not selected in the tree."); 238 } 239 240 } 241 242 247 public void testSuccesfulServerLink() throws Exception { 248 249 String expectedLink = URL_JONASADMIN + "EditJonasServer.do?select=jonas:j2eeType=J2EEServer,name=jonas"; 251 252 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 254 255 WebResponse treeFrame = wc.getFrameContents(FRAME_TREE); 257 258 WebLink link = treeFrame.getLinkWith("Domain"); 260 link.click(); 261 262 WebResponse wr = wc.getFrameContents(FRAME_CONTENT); 264 265 link = wr.getLinks()[0]; 267 String actualLink = link.getAttribute("href"); 268 actualLink = HttpUnitUtils.decode(actualLink); 269 assertEquals("The link of the JonasAdmin's server is wrong.", expectedLink, actualLink); 270 } 271 272 277 public void testOtherServers() throws Exception { 278 279 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 281 282 WebResponse treeFrame = wc.getFrameContents(FRAME_TREE); 284 285 WebLink link = treeFrame.getLinkWith("Domain"); 287 link.click(); 288 289 WebResponse wr = wc.getFrameContents(FRAME_CONTENT); 291 292 WebTable wt = wr.getTableStartingWith(TITLE_OTHERSERVERS); 294 TableCell cell = wt.getTableCell(1, 0); 295 String content = cell.getText(); 296 if (content.indexOf("No other server in this domain!") == -1) { 297 WebLink[] wl = wr.getLinks(); 299 if (wl.length < 2) { 300 fail("No links are found for other servers in domain."); 301 } else { 302 for (int i = 1; i < wt.getRowCount(); i++) { 303 cell = wt.getTableCell(i, 0); 304 if (!(cell.getLinks().length > 0)) { 305 fail("A link doesn't exist for a server"); 306 } 307 } 308 } 309 } 310 } 311 312 } | Popular Tags |