|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| BaseFindTagHandler.java | 87.5% | 97.8% | 100% | 97.1% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit.finder;
|
|
| 2 |
|
|
| 3 |
import junit.extensions.jfcunit.TestHelper;
|
|
| 4 |
import junit.extensions.jfcunit.tools.Operator;
|
|
| 5 |
import junit.extensions.jfcunit.xml.JFCXMLConstants;
|
|
| 6 |
|
|
| 7 |
import junit.extensions.xml.IXMLTestCase;
|
|
| 8 |
import junit.extensions.xml.XMLException;
|
|
| 9 |
import junit.extensions.xml.elements.AbstractTagHandler;
|
|
| 10 |
|
|
| 11 |
import org.w3c.dom.Element;
|
|
| 12 |
|
|
| 13 |
import java.awt.Component;
|
|
| 14 |
import java.awt.Container;
|
|
| 15 |
import java.awt.Window;
|
|
| 16 |
|
|
| 17 |
import javax.swing.Icon;
|
|
| 18 |
import javax.swing.ImageIcon;
|
|
| 19 |
import javax.swing.JMenu;
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
/**
|
|
| 23 |
* This class provides the basic handling for all of the FindTagHandler
|
|
| 24 |
* implementations.
|
|
| 25 |
*
|
|
| 26 |
* <H3>Optional Attributes:</H3>
|
|
| 27 |
* <pre>
|
|
| 28 |
* operation - match, equals, startswith, endswith, contains
|
|
| 29 |
* show - show the candidate items by moving the cursor
|
|
| 30 |
* to each item passing the finder. A Message dialog
|
|
| 31 |
* will show the current index.
|
|
| 32 |
* </pre>
|
|
| 33 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
| 34 |
* @author Kevin Wilson
|
|
| 35 |
*/
|
|
| 36 |
public abstract class BaseFindTagHandler extends AbstractTagHandler |
|
| 37 |
implements JFCXMLConstants {
|
|
| 38 |
/**
|
|
| 39 |
* Constructor for FindTagHandler.
|
|
| 40 |
*
|
|
| 41 |
* @param element The element to be processed.
|
|
| 42 |
* @param testCase The IXMLTestCase that uses this element.
|
|
| 43 |
*/
|
|
| 44 | 161 |
public BaseFindTagHandler(final Element element, final IXMLTestCase testCase) {
|
| 45 | 161 |
super(element, testCase);
|
| 46 |
} |
|
| 47 |
|
|
| 48 |
/**
|
|
| 49 |
* @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
|
|
| 50 |
*/
|
|
| 51 |
public abstract void processElement() throws XMLException; |
|
| 52 |
|
|
| 53 |
/**
|
|
| 54 |
* @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
|
|
| 55 |
*/
|
|
| 56 | 161 |
public void validateElement() throws XMLException { |
| 57 |
// do the default validations from the super class
|
|
| 58 | 161 |
super.validateElement();
|
| 59 |
|
|
| 60 |
// check the element tag name
|
|
| 61 | 161 |
checkElementTagName(FIND); |
| 62 |
|
|
| 63 |
// reqd attribute: id
|
|
| 64 | 161 |
checkRequiredAttribute(ID); |
| 65 |
|
|
| 66 |
// reqd attribute: index
|
|
| 67 | 161 |
checkRequiredAttribute(INDEX); |
| 68 |
} |
|
| 69 |
|
|
| 70 |
/**
|
|
| 71 |
* Returns the value of the CASEINDEPENDENT attribute for this element.
|
|
| 72 |
* @return boolean The value of the CASEINDEPENDENT attribute.
|
|
| 73 |
*/
|
|
| 74 | 30 |
protected final boolean getCaseIndependent() { |
| 75 | 30 |
return getBoolean(CASEINDEPENDENT);
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
/**
|
|
| 79 |
* Returns the value of the CLASS attribute for this element.
|
|
| 80 |
* @return String The value of the CLASS attribute.
|
|
| 81 |
*/
|
|
| 82 | 133 |
protected final String getClassName() {
|
| 83 | 133 |
return getString(CLASS);
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/**
|
|
| 87 |
* Returns the value of the CONTAINER attribute for this element.
|
|
| 88 |
* @return String The value of the CONTAINER attribute.
|
|
| 89 |
*/
|
|
| 90 | 151 |
protected final String getContainerId() {
|
| 91 | 151 |
return getString(CONTAINER);
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/**
|
|
| 95 |
* Returns the Icon described by the ICONFILE and ICONDESCRIPTION attributes for this element.
|
|
| 96 |
* @return Icon The ImageIcon described by the value of the ICONFILE and ICONDESCRIPTION
|
|
| 97 |
* attributes.
|
|
| 98 |
*/
|
|
| 99 | 16 |
protected final Icon getIcon() {
|
| 100 | 16 |
Icon icon = null;
|
| 101 | 16 |
String file = getString(ICONFILE); |
| 102 | 16 |
String desc = getString(ICONDESCRIPTION); |
| 103 |
|
|
| 104 | 16 |
if ((file != null) && !file.equals("")) { |
| 105 | 4 |
icon = new ImageIcon(file, desc);
|
| 106 |
} |
|
| 107 |
|
|
| 108 | 16 |
return icon;
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
/**
|
|
| 112 |
* Returns the value of the ID attribute for this element.
|
|
| 113 |
* @return String The value of the ID attribute.
|
|
| 114 |
*/
|
|
| 115 | 159 |
protected final String getId() {
|
| 116 | 159 |
return getString(ID);
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
/**
|
|
| 120 |
* Returns the value of the INDEX attribute for this element. Defaults to 0 (zero) if not found.
|
|
| 121 |
* @return int The value of the parsed INDEX attribute, zero if not found.
|
|
| 122 |
*/
|
|
| 123 | 151 |
protected final int getIndex() { |
| 124 | 151 |
return getInt(INDEX, 0);
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/**
|
|
| 128 |
* Returns the value of the LABEL attribute for this element.
|
|
| 129 |
* @return String The value of the LABEL attribute.
|
|
| 130 |
*/
|
|
| 131 | 20 |
protected final String getLabel() {
|
| 132 | 20 |
return getString(LABEL);
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
/**
|
|
| 136 |
* Returns the value of the NAME attribute for this element.
|
|
| 137 |
* @return String The value of the NAME attribute.
|
|
| 138 |
*/
|
|
| 139 | 2 |
protected final String getName() {
|
| 140 | 2 |
return getString(NAME);
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
/**
|
|
| 144 |
* Get the operation as a string and
|
|
| 145 |
* translate to a OP code.
|
|
| 146 |
*
|
|
| 147 |
* @return Finder.OP_code
|
|
| 148 |
*/
|
|
| 149 | 159 |
protected final int getOperation() { |
| 150 | 159 |
String op = super.getString(OPERATION);
|
| 151 |
|
|
| 152 | 159 |
if ((op == null) || (op.length() == 0)) { |
| 153 | 156 |
return Finder.OP_MATCH;
|
| 154 |
} |
|
| 155 |
|
|
| 156 | 3 |
return Operator.Operation.getOperation(op);
|
| 157 |
} |
|
| 158 |
|
|
| 159 |
/**
|
|
| 160 |
* Get the value of the show attribute.
|
|
| 161 |
* @return true if the finder is to show the
|
|
| 162 |
* candidate items.
|
|
| 163 |
*/
|
|
| 164 | 151 |
protected final boolean getShow() { |
| 165 | 151 |
return getBoolean(SHOW, false); |
| 166 |
} |
|
| 167 |
|
|
| 168 |
/**
|
|
| 169 |
* Retrun the value of the TITLE attribute for this element.
|
|
| 170 |
* @return String The value of the TITLE attribute.
|
|
| 171 |
*/
|
|
| 172 | 8 |
protected final String getTitle() {
|
| 173 | 8 |
return getString(TITLE);
|
| 174 |
} |
|
| 175 |
|
|
| 176 |
/**
|
|
| 177 |
* Get the Wait time for the finder.
|
|
| 178 |
* @return Duration for the Finder to try again until the
|
|
| 179 |
* object is found.
|
|
| 180 |
*/
|
|
| 181 | 151 |
protected int getWait() { |
| 182 | 151 |
return super.getInt(WAIT, 5); |
| 183 |
} |
|
| 184 |
|
|
| 185 |
/**
|
|
| 186 |
* Execute the common find on the TestHelper.
|
|
| 187 |
* @param finder Finder to be used to locate the object.
|
|
| 188 |
*/
|
|
| 189 | 151 |
protected void find(final Finder finder) { |
| 190 | 151 |
int index = getIndex();
|
| 191 |
|
|
| 192 | 151 |
finder.setWait(getWait()); |
| 193 | 151 |
finder.setShowDebug(getShow()); |
| 194 |
|
|
| 195 | 151 |
String containerRefId = getContainerId(); |
| 196 | 151 |
finder.setOperation(getOperation()); |
| 197 |
|
|
| 198 | 151 |
Component comp; |
| 199 |
|
|
| 200 | 151 |
if (containerRefId != null) { |
| 201 | 29 |
Container cont = (Container) getXMLTestCase().getProperty(containerRefId); |
| 202 |
|
|
| 203 | 29 |
if (cont instanceof JMenu) { |
| 204 | 0 |
cont = ((JMenu) cont).getPopupMenu(); |
| 205 |
} |
|
| 206 |
|
|
| 207 | 29 |
comp = finder.find(cont, index); |
| 208 |
} else {
|
|
| 209 | 122 |
comp = finder.find(index); |
| 210 |
} |
|
| 211 |
|
|
| 212 | 151 |
String id = getId(); |
| 213 | 151 |
getXMLTestCase().addProperty(id, comp); |
| 214 |
} |
|
| 215 |
|
|
| 216 |
/**
|
|
| 217 |
* Execute the common findWindow on the TestHelper.
|
|
| 218 |
* @param wfinder Finder to be used to locate the object.
|
|
| 219 |
*/
|
|
| 220 | 8 |
protected void findWindow(final AbstractWindowFinder wfinder) { |
| 221 | 8 |
Window w = null;
|
| 222 | 8 |
wfinder.setWait(getWait()); |
| 223 | 8 |
wfinder.setOperation(getOperation()); |
| 224 | 8 |
w = TestHelper.getWindow(wfinder); |
| 225 |
|
|
| 226 | 8 |
String id = getId(); |
| 227 | 8 |
getXMLTestCase().addProperty(id, w); |
| 228 |
} |
|
| 229 |
} |
|
| 230 |
|
|
||||||||||