KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertyType_IdentifierArray


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 gui.propertyeditors;
21
22 import org.netbeans.jellytools.NbDialogOperator;
23 import org.netbeans.jellytools.properties.editors.StringArrayCustomEditorOperator;
24
25 import org.netbeans.jemmy.operators.JTextFieldOperator;
26
27 import org.netbeans.junit.NbTestSuite;
28
29 /**
30  * Tests of Identifier Array Property Editor.
31  *
32  * @author Marian.Mirilovic@Sun.Com
33  */

34 public class PropertyType_IdentifierArray extends PropertyEditorsTest {
35
36     public String JavaDoc propertyName_L;
37     public String JavaDoc propertyValue_L;
38     public String JavaDoc propertyValueExpectation_L;
39
40     public boolean waitDialog = false;
41     
42     private final String JavaDoc ADD = "Add:";
43     private final String JavaDoc REMOVE = "Remove:";
44     private final String JavaDoc EDIT = "Edit:";
45     private final String JavaDoc UP = "Up:";
46     private final String JavaDoc DOWN = "Down:";
47     
48     private final String JavaDoc EE = "; ";
49     
50     /** Creates a new instance of PropertyType_IdentifierArray */
51     public PropertyType_IdentifierArray(String JavaDoc testName) {
52         super(testName);
53     }
54     
55     
56     public void setUp(){
57         propertyName_L = "Identifier []";
58         super.setUp();
59     }
60     
61     public static NbTestSuite suite() {
62         NbTestSuite suite = new NbTestSuite();
63         suite.addTest(new PropertyType_IdentifierArray("testByInPlace"));
64         suite.addTest(new PropertyType_IdentifierArray("verifyCustomizer"));
65         suite.addTest(new PropertyType_IdentifierArray("testCustomizerCancel"));
66         suite.addTest(new PropertyType_IdentifierArray("testCustomizerAdd"));
67         suite.addTest(new PropertyType_IdentifierArray("testCustomizerRemove"));
68         suite.addTest(new PropertyType_IdentifierArray("testCustomizerEdit"));
69         suite.addTest(new PropertyType_IdentifierArray("testCustomizerUp"));
70         suite.addTest(new PropertyType_IdentifierArray("testCustomizerDown"));
71         return suite;
72     }
73     
74     
75     public void testCustomizerAdd() {
76         propertyValue_L = ADD + "add";
77         propertyValueExpectation_L = "remove, down, up, edit, add";
78         waitDialog = false;
79         setByCustomizerOk(propertyName_L, true);
80     }
81     
82     public void testCustomizerRemove() {
83         propertyValue_L = REMOVE + "remove";
84         propertyValueExpectation_L = "down, up, edit, add";
85         waitDialog = false;
86         setByCustomizerOk(propertyName_L, true);
87     }
88     
89     public void testCustomizerEdit() {
90         propertyValue_L = EDIT + "edit" + EE + "newEdit";
91         propertyValueExpectation_L = "down, up, newEdit, add";
92         waitDialog = false;
93         setByCustomizerOk(propertyName_L, true);
94     }
95
96     public void testCustomizerUp() {
97         propertyValue_L = UP + "up";
98         propertyValueExpectation_L = "up, down, newEdit, add";
99         waitDialog = false;
100         setByCustomizerOk(propertyName_L, true);
101     }
102     
103     public void testCustomizerDown() {
104         propertyValue_L = DOWN + "down";
105         propertyValueExpectation_L = "up, newEdit, down, add";
106         waitDialog = false;
107         setByCustomizerOk(propertyName_L, true);
108     }
109     
110     public void testCustomizerCancel(){
111         propertyValue_L = ADD + "cancel";
112         propertyValueExpectation_L = propertyValue_L;
113         waitDialog = false;
114         setByCustomizerCancel(propertyName_L, false);
115     }
116     
117     public void testByInPlace(){
118         propertyValue_L = "remove, down, up, edit";
119         propertyValueExpectation_L = propertyValue_L;
120         waitDialog = false;
121         setByInPlace(propertyName_L, propertyValue_L, true);
122     }
123     
124     public void verifyCustomizer() {
125         verifyCustomizer(propertyName_L);
126     }
127     
128     public void setCustomizerValue() {
129         StringArrayCustomEditorOperator customizer = new StringArrayCustomEditorOperator(propertyCustomizer);
130         
131         if(propertyValue_L.startsWith(ADD)){
132             customizer.btAdd().pushNoBlock();
133             NbDialogOperator dialog = new NbDialogOperator("Enter");
134             new JTextFieldOperator(dialog).setText(getItem(propertyValue_L,ADD));
135             dialog.ok();
136         }
137         
138         if(propertyValue_L.startsWith(REMOVE)){
139             customizer.remove(getItem(propertyValue_L,REMOVE));
140         }
141         
142         if(propertyValue_L.startsWith(EDIT)){
143             customizer.lstItemList().selectItem(getItem(propertyValue_L,EDIT));
144             customizer.btEdit().pushNoBlock();
145             NbDialogOperator dialog = new NbDialogOperator("Enter");
146             new JTextFieldOperator(dialog).setText(getItem(propertyValue_L,EE));
147             dialog.ok();
148         }
149         
150         if(propertyValue_L.startsWith(UP)){
151             customizer.up(getItem(propertyValue_L,UP));
152         }
153         
154         if(propertyValue_L.startsWith(DOWN)){
155             customizer.down(getItem(propertyValue_L,DOWN));
156         }
157         
158     }
159     
160     public void verifyPropertyValue(boolean expectation) {
161         verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
162     }
163     
164     
165     private String JavaDoc getItem(String JavaDoc str, String JavaDoc delim) {
166         int first = str.indexOf(delim);
167         int end = str.indexOf(EE);
168
169         if(end > 0 && !delim.equals(EE)){
170             return str.substring(delim.length(), end);
171         } else {
172             return str.substring(first + delim.length());
173         }
174     }
175     
176     public void verifyCustomizerLayout() {
177         StringArrayCustomEditorOperator customizer = new StringArrayCustomEditorOperator(propertyCustomizer);
178         customizer.btAdd();
179         customizer.btRemove();
180         customizer.btEdit();
181         customizer.btUp();
182         customizer.btDown();
183         customizer.lstItemList();
184         customizer.btOK();
185         customizer.btCancel();
186     }
187     
188     /** Test could be executed internaly in Forte without XTest
189      * @param args arguments from command line
190      */

191     public static void main(String JavaDoc[] args) {
192         //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_IdentifierArray.class));
193
junit.textui.TestRunner.run(suite());
194     }
195     
196 }
197
Popular Tags