001: /*
002: * $Id$
003: *
004: * ---------------------------------------------------------------------------
005: *
006: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
007: *
008: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
009: *
010: * The contents of this file are subject to the terms of either the GNU
011: * General Public License Version 2 only ("GPL") or the Common
012: * Development and Distribution License("CDDL") (collectively, the
013: * "License"). You may not use this file except in compliance with the
014: * License. You can obtain a copy of the License at
015: * http://www.netbeans.org/cddl-gplv2.html
016: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
017: * specific language governing permissions and limitations under the
018: * License. When distributing the software, include this License Header
019: * Notice in each file and include the License file at
020: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
021: * particular file as subject to the "Classpath" exception as provided
022: * by Sun in the GPL Version 2 section of the License file that
023: * accompanied this code. If applicable, add the following below the
024: * License Header, with the fields enclosed by brackets [] replaced by
025: * your own identifying information:
026: * "Portions Copyrighted [year] [name of copyright owner]"
027: *
028: * Contributor(s): Manfred Riem (mriem@netbeans.org).
029: *
030: * The Original Software is the Jemmy library. The Initial Developer of the
031: * Original Software is Alexandre Iline. All Rights Reserved.
032: *
033: * If you wish your version of this file to be governed by only the CDDL
034: * or only the GPL Version 2, indicate your decision by adding
035: * "[Contributor] elects to include this software in this distribution
036: * under the [CDDL or GPL Version 2] license." If you do not indicate a
037: * single choice of license, a recipient has the option to distribute
038: * your version of this file under either the CDDL, the GPL Version 2 or
039: * to extend the choice of license to its licensees as provided above.
040: * However, if you add GPL Version 2 code and therefore, elected the GPL
041: * Version 2 license, then the option applies only if the new code is
042: * made subject to such option by the copyright holder.
043: *
044: * ---------------------------------------------------------------------------
045: *
046: */
047: package org.netbeans.jemmy.operators;
048:
049: import javax.swing.JFrame;
050: import javax.swing.JTextArea;
051: import junit.framework.Test;
052: import junit.framework.TestCase;
053: import junit.framework.TestSuite;
054: import org.netbeans.jemmy.JemmyException;
055: import org.netbeans.jemmy.util.NameComponentChooser;
056:
057: /**
058: * A JUnit test for JTextAreaOperator.
059: *
060: * @author Manfred Riem (mriem@netbeans.org)
061: * @version $Revision$
062: */
063: public class JTextAreaOperatorTest extends TestCase {
064: /**
065: * Stores the frame we use.
066: */
067: private JFrame frame;
068:
069: /**
070: * Stores the text area we use.
071: */
072: private JTextArea textArea;
073:
074: /**
075: * Constructor.
076: *
077: * @param testName the name of the test.
078: */
079: public JTextAreaOperatorTest(String testName) {
080: super (testName);
081: }
082:
083: /**
084: * Setup before testing.
085: */
086: protected void setUp() throws Exception {
087: frame = new JFrame();
088: textArea = new JTextArea("JTextAreaOperatorTest");
089: textArea.setName("JTextAreaOperatorTest");
090: frame.getContentPane().add(textArea);
091: frame.pack();
092: frame.setLocationRelativeTo(null);
093: }
094:
095: /**
096: * Cleanup after testing.
097: */
098: protected void tearDown() throws Exception {
099: frame.setVisible(false);
100: }
101:
102: /**
103: * Suite method.
104: */
105: public static Test suite() {
106: TestSuite suite = new TestSuite(JTextAreaOperatorTest.class);
107:
108: return suite;
109: }
110:
111: /**
112: * Test constructor.
113: */
114: public void testConstructor() {
115: frame.setVisible(true);
116:
117: JFrameOperator operator = new JFrameOperator();
118: assertNotNull(operator);
119:
120: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
121: assertNotNull(operator2);
122:
123: JTextAreaOperator operator3 = new JTextAreaOperator(operator,
124: new NameComponentChooser("JTextAreaOperatorTest"));
125: assertNotNull(operator3);
126:
127: JTextAreaOperator operator4 = new JTextAreaOperator(operator,
128: "JTextAreaOperatorTest");
129: assertNotNull(operator4);
130: }
131:
132: /**
133: * Test findJTextArea method.
134: */
135: public void testFindJTextArea() {
136: frame.setVisible(true);
137:
138: JTextArea textArea1 = JTextAreaOperator.findJTextArea(frame,
139: "JTextAreaOperatorTest", false, false);
140: assertNotNull(textArea1);
141:
142: JTextArea textArea2 = JTextAreaOperator.findJTextArea(frame,
143: new NameComponentChooser("JTextAreaOperatorTest"));
144: assertNotNull(textArea2);
145: }
146:
147: /**
148: * Test waitJTextArea method.
149: */
150: public void testWaitJTextArea() {
151: frame.setVisible(true);
152:
153: JTextArea textArea1 = JTextAreaOperator.waitJTextArea(frame,
154: "JTextAreaOperatorTest", false, false);
155: assertNotNull(textArea1);
156:
157: JTextArea textArea2 = JTextAreaOperator.waitJTextArea(frame,
158: new NameComponentChooser("JTextAreaOperatorTest"));
159: assertNotNull(textArea2);
160: }
161:
162: /**
163: * Test usePageNavigationKeys method.
164: */
165: public void testUsePageNavigationKeys() {
166: frame.setVisible(true);
167:
168: JFrameOperator operator = new JFrameOperator();
169: assertNotNull(operator);
170:
171: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
172: assertNotNull(operator2);
173:
174: operator2.usePageNavigationKeys(true);
175: }
176:
177: /**
178: * Test changeCaretRow method.
179: */
180: public void testChangeCaretRow() {
181: frame.setVisible(true);
182:
183: JFrameOperator operator = new JFrameOperator();
184: assertNotNull(operator);
185:
186: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
187: assertNotNull(operator2);
188:
189: operator2.changeCaretRow(0);
190: }
191:
192: /**
193: * Test changeCaretPosition method.
194: */
195: public void testChangeCaretPosition() {
196: frame.setVisible(true);
197:
198: JFrameOperator operator = new JFrameOperator();
199: assertNotNull(operator);
200:
201: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
202: assertNotNull(operator2);
203:
204: operator2.changeCaretPosition(0, 0);
205: }
206:
207: /**
208: * Test typeText method.
209: */
210: public void testTypeText() {
211: frame.setVisible(true);
212:
213: JFrameOperator operator = new JFrameOperator();
214: assertNotNull(operator);
215:
216: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
217: assertNotNull(operator2);
218:
219: operator2.typeText("Booh!", 0, 0);
220: }
221:
222: /**
223: * Test selectText method.
224: */
225: public void testSelectText() {
226: frame.setVisible(true);
227:
228: JFrameOperator operator = new JFrameOperator();
229: assertNotNull(operator);
230:
231: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
232: assertNotNull(operator2);
233:
234: operator2.selectText("JTextAreaOperatorTest");
235: }
236:
237: /**
238: * Test selectLines method.
239: */
240: public void testSelectLines() {
241: frame.setVisible(true);
242:
243: JFrameOperator operator = new JFrameOperator();
244: assertNotNull(operator);
245:
246: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
247: assertNotNull(operator2);
248:
249: operator2.selectLines(0, 0);
250: }
251:
252: /**
253: * Test getDump method.
254: */
255: public void testGetDump() {
256: frame.setVisible(true);
257:
258: JFrameOperator operator = new JFrameOperator();
259: assertNotNull(operator);
260:
261: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
262: assertNotNull(operator2);
263:
264: assertNotNull(operator2.getDump());
265: }
266:
267: /**
268: * Test append method.
269: */
270: public void testAppend() {
271: frame.setVisible(true);
272:
273: JFrameOperator operator = new JFrameOperator();
274: assertNotNull(operator);
275:
276: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
277: assertNotNull(operator2);
278:
279: operator2.append("Booh!");
280: }
281:
282: /**
283: * Test getColumns method.
284: */
285: public void testGetColumns() {
286: frame.setVisible(true);
287:
288: JFrameOperator operator = new JFrameOperator();
289: assertNotNull(operator);
290:
291: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
292: assertNotNull(operator2);
293:
294: operator2.setColumns(2);
295: assertEquals(2, operator2.getColumns());
296: }
297:
298: /**
299: * Test getLineCount method.
300: */
301: public void testGetLineCount() {
302: frame.setVisible(true);
303:
304: JFrameOperator operator = new JFrameOperator();
305: assertNotNull(operator);
306:
307: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
308: assertNotNull(operator2);
309:
310: operator2.getLineCount();
311: }
312:
313: /**
314: * Test getLineWrap method.
315: */
316: public void testGetLineWrap() {
317: frame.setVisible(true);
318:
319: JFrameOperator operator = new JFrameOperator();
320: assertNotNull(operator);
321:
322: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
323: assertNotNull(operator2);
324:
325: operator2.setLineWrap(true);
326: assertTrue(operator2.getLineWrap());
327:
328: operator2.setLineWrap(false);
329: assertTrue(!operator2.getLineWrap());
330: }
331:
332: /**
333: * Test getRows method.
334: */
335: public void testGetRows() {
336: frame.setVisible(true);
337:
338: JFrameOperator operator = new JFrameOperator();
339: assertNotNull(operator);
340:
341: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
342: assertNotNull(operator2);
343:
344: operator2.setRows(1);
345: assertEquals(1, operator2.getRows());
346: }
347:
348: /**
349: * Test getTabSize method.
350: */
351: public void testGetTabSize() {
352: frame.setVisible(true);
353:
354: JFrameOperator operator = new JFrameOperator();
355: assertNotNull(operator);
356:
357: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
358: assertNotNull(operator2);
359:
360: operator2.setTabSize(11);
361: assertEquals(11, operator2.getTabSize());
362: }
363:
364: /**
365: * Test getWrapStyleWord method.
366: */
367: public void testGetWrapStyleWord() {
368: frame.setVisible(true);
369:
370: JFrameOperator operator = new JFrameOperator();
371: assertNotNull(operator);
372:
373: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
374: assertNotNull(operator2);
375:
376: operator2.setWrapStyleWord(true);
377: assertTrue(operator2.getWrapStyleWord());
378:
379: operator2.setWrapStyleWord(false);
380: assertTrue(!operator2.getWrapStyleWord());
381: }
382:
383: /**
384: * Test insert method.
385: */
386: public void testInsert() {
387: frame.setVisible(true);
388:
389: JFrameOperator operator = new JFrameOperator();
390: assertNotNull(operator);
391:
392: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
393: assertNotNull(operator2);
394:
395: operator2.insert("Booh!", 0);
396: }
397:
398: /**
399: * Test replaceRange method.
400: */
401: public void testReplaceRange() {
402: frame.setVisible(true);
403:
404: JFrameOperator operator = new JFrameOperator();
405: assertNotNull(operator);
406:
407: JTextAreaOperator operator2 = new JTextAreaOperator(operator);
408: assertNotNull(operator2);
409:
410: operator2.replaceRange("Booh!", 0, 0);
411: }
412: }
|