KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > qa > form > beans > AddAndRemoveBeansTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.qa.form.beans;
21
22 import java.awt.Component JavaDoc;
23 import org.netbeans.qa.form.*;
24 import org.netbeans.qa.form.visualDevelopment.*;
25 import org.netbeans.junit.NbTestSuite;
26 import org.netbeans.jellytools.actions.*;
27 import org.netbeans.jellytools.*;
28 import org.netbeans.qa.form.ExtJellyTestCase;
29 import java.util.*;
30 import org.netbeans.jellytools.modules.form.ComponentPaletteOperator;
31 import org.netbeans.jemmy.operators.JListOperator;
32 import org.netbeans.jemmy.operators.JTreeOperator;
33 import org.netbeans.jemmy.operators.Operator;
34
35 /**
36  * Tests adding and removing beans into/from palette
37  *
38  * @author Jiri Vagner
39  */

40 public class AddAndRemoveBeansTest extends ExtJellyTestCase {
41     public static String JavaDoc VISUAL_BEAN_NAME = "TestVisualBean"; // NOI18N
42
public static String JavaDoc NONVISUAL_BEAN_NAME = "TestNonVisualBean"; // NOI18N
43
public static String JavaDoc TESTED_BEAN_TEXT = "Lancia Lybra"; // NOI18N
44
public static String JavaDoc TESTED_BEAN_POWER = "140"; // NOI18N
45

46     
47     /**
48      * Constructor required by JUnit
49      */

50     public AddAndRemoveBeansTest(String JavaDoc testName) {
51         super(testName);
52     }
53     
54     /**
55      * Method allowing to execute test directly from IDE.
56      */

57     public static void main(java.lang.String JavaDoc[] args) {
58         junit.textui.TestRunner.run(suite());
59     }
60     
61     /**
62      * Creates suite from particular test cases.
63      */

64     public static NbTestSuite suite() {
65         NbTestSuite suite = new NbTestSuite();
66         
67         suite.addTest(new AddAndRemoveBeansTest("testAddingBeans")); // NOI18N
68
suite.addTest(new AddAndRemoveBeansTest("testRemovingBeans")); // NOI18N
69

70         return suite;
71     }
72     
73     /**
74      * Tests "Add Bean" dialog
75      */

76     public void testAddingBeans() {
77         addBean( VISUAL_BEAN_NAME + ".java"); // NOI18N
78
addBean( NONVISUAL_BEAN_NAME + ".java"); // NOI18N
79
}
80     
81     /**
82      * Tests removing bean using Palette Manager
83      */

84     public void testRemovingBeans() {
85         new ActionNoBlock("Tools|Palette Manager|Swing/AWT Components", null).perform(); // NOI18N
86

87         PaletteManagerOperator manOp = new PaletteManagerOperator();
88         JTreeOperator treeOp = manOp.treePaletteContentsTree();
89         
90         treeOp.clickOnPath( treeOp.findPath("Beans|" + VISUAL_BEAN_NAME,"|")); // NOI18N
91
manOp.remove();
92         new NbDialogOperator("Confirm").yes(); // NOI18N
93

94         treeOp.clickOnPath( treeOp.findPath("Beans|" + NONVISUAL_BEAN_NAME,"|")); // NOI18N
95
manOp.remove();
96         new NbDialogOperator("Confirm").yes(); // NOI18N
97

98         manOp.close();
99     }
100     
101     /**
102      * Tests removing beans using popup menu from palette
103      */

104     public void testRemovingBeansFromPalette() {
105         openFile("clear_Frame.java");
106         
107         ComponentPaletteOperator palette = new ComponentPaletteOperator();
108         palette.expandBeans();
109         palette.collapseSwingContainers();
110         palette.collapseSwingMenus();
111         palette.collapseSwingWindows();
112         palette.collapseAWT();
113         palette.collapseSwingControls();
114         
115         JListOperator list = palette.lstComponents();
116         list.clickOnItem(NONVISUAL_BEAN_NAME, new Operator.DefaultStringComparator(true, false));
117         
118         // TODO: I'm not able to invoke popup menu :(
119
int i = list.findItemIndex(NONVISUAL_BEAN_NAME, new Operator.DefaultStringComparator(true, false));
120         p(i);
121         
122         Component JavaDoc[] comps = list.getComponents();
123         p(comps.length);
124         for (Component JavaDoc comp : comps) {
125             p(comp.toString());
126         }
127     }
128     
129 }
130
Popular Tags