KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertyType_StringArray


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.properties.editors.StringArrayCustomEditorOperator;
23
24 import org.netbeans.junit.NbTestSuite;
25
26 /**
27  * Tests of StringArray Property Editor.
28  *
29  * @author Marian.Mirilovic@Sun.Com
30  */

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

176     public static void main(String JavaDoc[] args) {
177         //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_StringArray.class));
178
junit.textui.TestRunner.run(suite());
179     }
180     
181 }
182
Popular Tags