KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertyType_Icon


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.Property;
23 import org.netbeans.jellytools.properties.PropertySheetOperator;
24
25 import org.netbeans.jellytools.properties.editors.IconCustomEditorOperator;
26
27 import org.netbeans.jemmy.EventTool;
28 import org.netbeans.jemmy.JemmyException;
29
30 import org.netbeans.junit.NbTestSuite;
31
32
33
34 /**
35  * Tests of Icon Property Editor.
36  *
37  * @author Marian.Mirilovic@Sun.Com
38  */

39 public class PropertyType_Icon extends PropertyEditorsTest {
40     
41     public String JavaDoc propertyName_L;
42     public String JavaDoc propertyValue_L;
43     public String JavaDoc propertyValueExpectation_L;
44     
45     private final String JavaDoc FILE = "File: ";
46     private final String JavaDoc CLASSPATH = "Classpath: ";
47     private final String JavaDoc URL = "URL: ";
48     private final String JavaDoc NO_PICTURE = "No Picture";
49     
50     public boolean waitDialog = false;
51     
52     /** Creates a new instance of PropertyType_Icon */
53     public PropertyType_Icon(String JavaDoc testName) {
54         super(testName);
55     }
56     
57     
58     public void setUp(){
59         propertyName_L = "Icon";
60         super.setUp();
61     }
62     
63     public static NbTestSuite suite() {
64         NbTestSuite suite = new NbTestSuite();
65         suite.addTest(new PropertyType_Icon("verifyCustomizer"));
66         suite.addTest(new PropertyType_Icon("testCustomizerCancel"));
67         suite.addTest(new PropertyType_Icon("testCustomizerOkURL"));
68         suite.addTest(new PropertyType_Icon("testCustomizerOkFile"));
69         suite.addTest(new PropertyType_Icon("testCustomizerOkClasspath"));
70         suite.addTest(new PropertyType_Icon("testCustomizerOkNoPicture"));
71         suite.addTest(new PropertyType_Icon("testByInPlace"));
72         suite.addTest(new PropertyType_Icon("testByInPlaceInvalid"));
73         // suite.addTest(new PropertyType_Icon("testCustomizerInvalid"));
74
return suite;
75     }
76     
77     
78     public void testCustomizerOkURL() {
79         propertyValue_L = URL + "http://www.netbeans.org/1.gif";
80         propertyValueExpectation_L = propertyValue_L;
81         waitDialog = false;
82         setByCustomizerOk(propertyName_L, true);
83     }
84     
85     public void testCustomizerOkFile() {
86         propertyValue_L = FILE + "/home/mm119185/samplxxxxeDir.gif";
87         propertyValueExpectation_L = propertyValue_L;
88         waitDialog = false;
89         setByCustomizerOk(propertyName_L, true);
90     }
91     
92     public void testCustomizerOkClasspath() {
93         propertyValue_L = CLASSPATH + "/gui/propertyeditors/data/ColorPreview.gif";
94         propertyValueExpectation_L = propertyValue_L;
95         waitDialog = false;
96         setByCustomizerOk(propertyName_L, true);
97     }
98     
99     public void testCustomizerOkNoPicture() {
100         propertyValue_L = NO_PICTURE;
101         propertyValueExpectation_L = "null";
102         waitDialog = false;
103         setByCustomizerOk(propertyName_L, true);
104     }
105     
106     public void testCustomizerCancel(){
107         propertyValue_L = URL + "http://www.netbeans.org/2.gif";
108         propertyValueExpectation_L = propertyValue_L;
109         waitDialog = false;
110         setByCustomizerCancel(propertyName_L, false);
111     }
112     
113 /* public void testCustomizerInvalid(){
114         propertyValue_L = "xx";
115         propertyValueExpectation_L = "File: "+propertyValue_L;
116         waitDialog = false;
117         setByCustomizerOk(propertyName_L, true);
118     }
119  */

120     public void testByInPlace(){
121         propertyValue_L = CLASSPATH +"/trash/PropertyEditorsTest.java";;
122         propertyValueExpectation_L = "Invalid value " + propertyValue_L;
123         waitDialog = false;
124         setByInPlace(propertyName_L, propertyValue_L, true);
125     }
126     
127     public void testByInPlaceInvalid(){
128         propertyValue_L = "xx";
129         propertyValueExpectation_L = "File: " +propertyValue_L;
130         waitDialog = false;
131         setByInPlace(propertyName_L, propertyValue_L, true);
132     }
133     
134     public void verifyCustomizer() {
135         verifyCustomizer(propertyName_L);
136     }
137     
138     public void setCustomizerValue() {
139         IconCustomEditorOperator customizer = new IconCustomEditorOperator(propertyCustomizer);
140         
141         String JavaDoc type;
142         String JavaDoc path;
143         int delim_index = propertyValue_L.indexOf(": ");
144         
145         if(delim_index>0){
146             type = propertyValue_L.substring(0,delim_index+2);
147             path = propertyValue_L.substring(delim_index+1).trim();
148             
149             if(type.equalsIgnoreCase(NO_PICTURE)){
150                 customizer.noPicture();
151             }else if(type.equalsIgnoreCase(URL)){
152                 customizer.uRL();
153                 customizer.setName(path);
154             }else if(type.equalsIgnoreCase(FILE)){
155                 customizer.file();
156                 customizer.setName(path);
157             }else if(type.equalsIgnoreCase(CLASSPATH)){
158                 customizer.classpath();
159                 //customizer.setName(path); - hack because setName doesn't push Enter on the end of action
160
customizer.txtName().enterText(path);
161                 new EventTool().waitNoEvent(6000);
162             }else {
163                 throw new JemmyException("ERROR: value is (\""+propertyValue_L+"\") - wrong format or unknown source type!!! type=["+type+"]/path=["+path+"]");
164             }
165             
166         }else{
167             customizer.noPicture();
168         }
169         
170     }
171     
172     public void verifyPropertyValue(boolean expectation) {
173         verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
174     }
175     
176     
177     public String JavaDoc getValue(String JavaDoc property) {
178         String JavaDoc returnValue;
179         PropertySheetOperator propertiesTab = new PropertySheetOperator(propertiesWindow);
180         
181         returnValue = new Property(propertiesTab, property).getValue();
182         err.println("X GET VALUE = [" + returnValue + "].");
183         
184         // hack for icon poperty, this action expects, that right value is displayed (with label "Invalid value") as Accessible Name
185
returnValue = new Property(propertiesTab, property).getValue();
186         returnValue = returnValue.substring(returnValue.indexOf(property)+property.length()+2);
187         err.println("X GET VALUE ACCESSIBLE NAME = [" + returnValue + "].");
188         
189         return returnValue;
190     }
191     
192     public void verifyCustomizerLayout() {
193         IconCustomEditorOperator customizer = new IconCustomEditorOperator(propertyCustomizer);
194         customizer.verify();
195         customizer.btOK();
196         customizer.btCancel();
197     }
198     
199     /** Test could be executed internaly in Forte without XTest
200      * @param args arguments from command line
201      */

202     public static void main(String JavaDoc[] args) {
203         //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_Icon.class));
204
junit.textui.TestRunner.run(suite());
205     }
206     
207 }
208
Popular Tags