001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package gui.propertyeditors;
043:
044: import org.netbeans.jellytools.properties.ColorProperty;
045: import org.netbeans.jellytools.properties.PropertySheetOperator;
046:
047: import org.netbeans.jellytools.properties.editors.ColorCustomEditorOperator;
048:
049: import org.netbeans.junit.NbTestSuite;
050:
051: /**
052: * Tests of Color Property Editor.
053: *
054: * @author Marian.Mirilovic@Sun.Com
055: */
056: public class PropertyType_Color extends PropertyEditorsTest {
057:
058: public String propertyName_L;
059: public String propertyValue_L;
060: public String propertyValueExpectation_L;
061:
062: public boolean waitDialog = false;
063:
064: /** Creates a new instance of PropertyType_Boolean */
065: public PropertyType_Color(String testName) {
066: super (testName);
067: }
068:
069: public void setUp() {
070: propertyName_L = "Color";
071: super .setUp();
072: }
073:
074: public static NbTestSuite suite() {
075: NbTestSuite suite = new NbTestSuite();
076: suite.addTest(new PropertyType_Color("verifyCustomizer"));
077: suite.addTest(new PropertyType_Color("testCustomizerCancel"));
078: suite.addTest(new PropertyType_Color("testCustomizerOk"));
079: suite.addTest(new PropertyType_Color("testByInPlace"));
080: suite.addTest(new PropertyType_Color("testByInPlaceInvalid"));
081: return suite;
082: }
083:
084: public void testCustomizerOk() {
085: propertyValue_L = "50,50,50";
086: propertyValueExpectation_L = "[" + propertyValue_L + "]";
087: waitDialog = false;
088: setByCustomizerOk(propertyName_L, true);
089: }
090:
091: public void testCustomizerCancel() {
092: propertyValue_L = "100,100,100";
093: propertyValueExpectation_L = "[" + propertyValue_L + "]";
094: waitDialog = false;
095: setByCustomizerCancel(propertyName_L, false);
096: }
097:
098: public void testByInPlace() {
099: propertyValue_L = "20,10,100";
100: propertyValueExpectation_L = "[" + propertyValue_L + "]";
101: waitDialog = false;
102: setByInPlace(propertyName_L, propertyValue_L, true);
103: }
104:
105: public void testByInPlaceInvalid() {
106: propertyValue_L = "xx color";
107: propertyValueExpectation_L = propertyValue_L;
108: waitDialog = true;
109: setByInPlace(propertyName_L, propertyValue_L, false);
110: }
111:
112: public void verifyCustomizer() {
113: verifyCustomizer(propertyName_L);
114: }
115:
116: public void setCustomizerValue() {
117: ColorCustomEditorOperator customizer = new ColorCustomEditorOperator(
118: propertyCustomizer);
119:
120: int first_comma = propertyValue_L.indexOf(',');
121: int second_comma = propertyValue_L
122: .indexOf(',', first_comma + 1);
123:
124: int r = new Integer(propertyValue_L.substring(0, first_comma))
125: .intValue();
126: int g = new Integer(propertyValue_L.substring(first_comma + 1,
127: second_comma)).intValue();
128: int b = new Integer(propertyValue_L.substring(second_comma + 1))
129: .intValue();
130:
131: customizer.setRGBValue(r, g, b);
132: }
133:
134: public void verifyPropertyValue(boolean expectation) {
135: verifyExpectationValue(propertyName_L, expectation,
136: propertyValueExpectation_L, propertyValue_L, waitDialog);
137: }
138:
139: public String getValue(String propertyName) {
140: String returnValue;
141: PropertySheetOperator propertiesTab = new PropertySheetOperator(
142: propertiesWindow);
143:
144: returnValue = new ColorProperty(propertiesTab, propertyName_L)
145: .getValue();
146: err.println("GET VALUE = [" + returnValue + "].");
147:
148: // hack for color poperty, this action expects, that right value is displayed as tooltip
149: // returnValue = new Property(propertiesTab, propertyName_L).valueButtonOperator().getToolTipText();
150: // err.println("GET VALUE TOOLTIP = [" + returnValue + "].");
151:
152: return returnValue;
153: }
154:
155: public void verifyCustomizerLayout() {
156: ColorCustomEditorOperator customizer = new ColorCustomEditorOperator(
157: propertyCustomizer);
158: customizer.verify();
159: customizer.btOK();
160: customizer.btCancel();
161: }
162:
163: /** Test could be executed internaly in Forte without XTest
164: * @param args arguments from command line
165: */
166: public static void main(String[] args) {
167: //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_Color.class));
168: junit.textui.TestRunner.run(suite());
169: }
170: }
|