1 5 package org.exoplatform.test.web; 6 7 import com.meterware.httpunit.*; 8 9 15 public class Util { 16 public static WebLink findLink(WebResponse response, WebTable block, 17 String text) throws Exception { 18 WebLink link = null ; 19 if(block != null) { 20 for(int i = 0 ; i < block.getRowCount(); i++) { 21 for(int j = 0; j < block.getColumnCount(); j++) { 22 TableCell cell = block.getTableCell(i, j) ; 23 link = cell.getFirstMatchingLink( WebLink.MATCH_TEXT, text); 24 if(link != null) return link ; 25 } 26 } 27 28 } else { 29 link = response.getFirstMatchingLink(WebLink.MATCH_TEXT, text); 30 if(link != null) return link ; 31 } 32 return null ; 33 } 34 35 public static WebLink[] findLinks(WebResponse response, WebTable block, 36 String text) throws Exception { 37 WebLink[] links = null ; 38 if(block != null) { 39 for(int i = 0 ; i < block.getRowCount(); i++) { 40 for(int j = 0; j < block.getColumnCount(); j++) { 41 TableCell cell = block.getTableCell(i, j) ; 42 links = cell.getMatchingLinks(WebLink.MATCH_TEXT , text); 43 if(links.length > 0) return links ; 44 } 45 } 46 47 } else { 48 return response.getMatchingLinks(WebLink.MATCH_TEXT , text); 49 } 50 return new WebLink[0] ; 51 52 } 53 public static WebLink findLinkWithText(WebResponse response, WebTable block, 55 String text) throws Exception { 56 WebLink link = null ; 57 if(block != null) { 58 for(int i = 0 ; i < block.getRowCount(); i++) { 59 for(int j = 0; j < block.getColumnCount(); j++) { 60 TableCell cell = block.getTableCell(i, j) ; 61 link = cell.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, text); 62 if(link != null) return link ; 63 } 64 } 65 66 } else { 67 link = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, text); 68 if(link != null) return link ; 69 } 70 return null ; 71 } 72 73 public static WebLink[] findLinksWithText(WebResponse response, WebTable block, 74 String text) throws Exception { 75 WebLink[] links = null ; 76 if(block != null) { 77 for(int i = 0 ; i < block.getRowCount(); i++) { 78 for(int j = 0; j < block.getColumnCount(); j++) { 79 TableCell cell = block.getTableCell(i, j) ; 80 links = cell.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT , text); 81 if(links.length > 0) return links ; 82 } 83 } 84 85 } else { 86 return response.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT , text); 87 } 88 return new WebLink[0] ; 89 } 90 public static WebLink findLinkWithURL(WebResponse response, WebTable block, 92 String url) throws Exception { 93 WebLink link = null ; 94 if(block != null) { 95 for(int i = 0 ; i < block.getRowCount(); i++) { 96 for(int j = 0; j < block.getColumnCount(); j++) { 97 TableCell cell = block.getTableCell(i, j) ; 98 link = cell.getFirstMatchingLink( WebLink.MATCH_URL_STRING, url); 99 if(link != null) return link ; 100 } 101 } 102 103 } else { 104 link = response.getFirstMatchingLink( WebLink.MATCH_URL_STRING, url); 105 if(link != null) return link ; 106 } 107 return null ; 108 } 109 110 public static WebLink[] findLinksWithURL(WebResponse response, WebTable block, 111 String partOfURL) throws Exception { 112 WebLink[] links = null ; 113 if(block != null) { 114 for(int i = 0 ; i < block.getRowCount(); i++) { 115 for(int j = 0; j < block.getColumnCount(); j++) { 116 TableCell cell = block.getTableCell(i, j) ; 117 links = cell.getMatchingLinks(WebLink.MATCH_URL_STRING, partOfURL) ; 118 if(links.length > 0) return links ; 119 } 120 } 121 122 } else { 123 return response.getMatchingLinks(WebLink.MATCH_URL_STRING, partOfURL) ; 124 } 125 return new WebLink[0] ; 126 } 127 128 public static WebForm findFormWithName(WebResponse response, WebTable block, 129 String name) throws Exception { 130 WebForm form = null ; 131 if(block != null) { 132 for(int i = 0 ; i < block.getRowCount(); i++) { 133 for(int j = 0; j < block.getColumnCount(); j++) { 134 TableCell cell = block.getTableCell(i, j) ; 135 form = cell.getFormWithName(name) ; 136 if(form != null) return form ; 137 } 138 } 139 140 } else { 141 form = response.getFormWithName(name) ; 142 if(form != null) return form ; 143 } 144 return null ; 145 } 146 } | Popular Tags |