1 19 20 package gui.propertyeditors; 21 22 import java.io.PrintStream ; 23 import java.io.PrintWriter ; 24 25 import org.netbeans.jellytools.JellyTestCase; 26 import org.netbeans.jellytools.NbDialogOperator; 27 28 import org.netbeans.jellytools.properties.Property; 29 import org.netbeans.jellytools.properties.PropertySheetOperator; 30 31 import org.netbeans.jemmy.JemmyProperties; 32 import org.netbeans.jemmy.TestOut; 33 import org.netbeans.jemmy.operators.JTableOperator; 34 import org.netbeans.jemmy.operators.Operator; 35 36 37 42 public abstract class PropertyEditorsTest extends JellyTestCase { 43 44 protected static PrintStream err; 45 protected static PrintStream log; 46 47 public String propertyInitialValue; 48 public String propertyValue; 49 50 protected static JTableOperator tableOperator; 51 52 protected static NbDialogOperator propertyCustomizer; 53 54 protected static NbDialogOperator propertiesWindow = null; 55 56 private static final String CAPTION = "\n==========================="; 57 58 59 public PropertyEditorsTest(String testName) { 60 super(testName); 61 } 62 63 64 public void setUp() { 65 err = getLog(); 67 log = getRef(); 68 69 try { 70 JemmyProperties.getProperties().setOutput(new TestOut(null, new PrintWriter (err, true), new PrintWriter (err, true), null)); 71 initializeWorkplace(); 72 }catch(Exception exc) { 73 failTest(exc, "SetUp failed. It seems like initializeWorkplace cause exception:"+exc.getMessage()); 74 } 75 } 76 77 81 public void setByCustomizerOk(String propertyName, boolean expectance){ 82 try { 83 err.println(CAPTION + " Trying to set value by customizer-ok {name="+propertyName+" / value="+propertyValue+"} ."); 84 propertyInitialValue = getValue(propertyName); 85 86 openAndGetPropertyCustomizer(propertyName); 87 setCustomizerValue(); 88 89 if(propertyCustomizer.isShowing()) 90 propertyCustomizer.ok(); 91 92 err.println(CAPTION + " Trying to set value by customizer-ok {name="+propertyName+" / value="+propertyValue+"} - finished."); 93 verifyPropertyValue(expectance); 94 95 }catch(Exception exc) { 96 failTest(exc, "EXCEPTION: setByCustomizer("+propertyName+", "+expectance+") failed and cause exception:"+exc.getMessage()); 97 } 98 } 99 100 104 public void setByCustomizerCancel(String propertyName, boolean expectance) { 105 try { 106 err.println(CAPTION + " Trying to set value by customizer-cancel {name="+propertyName+" / value="+propertyValue+"} ."); 107 propertyInitialValue = getValue(propertyName); 108 openAndGetPropertyCustomizer(propertyName); 109 setCustomizerValue(); 110 111 if(propertyCustomizer.isShowing()) 112 propertyCustomizer.cancel(); 113 114 err.println(CAPTION + " Trying to set value by customizer-cancel {name="+propertyName+" / value="+propertyValue+"} - finished."); 115 verifyPropertyValue(expectance); 116 117 }catch(Exception exc) { 118 failTest(exc, "EXCEPTION: setByCustomizerCancel("+propertyName+", "+expectance+") failed and cause exception:"+exc.getMessage()); 119 } 120 } 121 122 127 public void setByInPlace(String propertyName, String propertyValue, boolean expectance) { 128 try { 129 err.println(CAPTION + " Trying to set value by in-place {name="+propertyName+" / value="+propertyValue+"} ."); 130 propertyInitialValue = getValue(propertyName); 131 132 new PropertySheetOperator(propertiesWindow).tblSheet().changeCellObject(findProperty(propertyName, propertiesWindow).getRow(),1, propertyValue); 134 135 err.println(CAPTION + " Trying to set value by in-place {name="+propertyName+" / value="+propertyValue+"} - finished."); 136 verifyPropertyValue(expectance); 137 138 }catch(Exception exc) { 139 failTest(exc, "EXCEPTION: setByInPlace("+propertyName+", "+propertyValue+", "+expectance+") failed and cause exception:"+exc.getMessage()); 140 } 141 } 142 143 148 public void setByCombo(String propertyName, String propertyValue, boolean expectance) { 149 try { 150 err.println(CAPTION + " Trying to set value by combo box {name="+propertyName+" / value="+propertyValue+"} ."); 151 propertyInitialValue = getValue(propertyName); 152 153 findProperty(propertyName, propertiesWindow).setValue(propertyValue); 154 155 err.println(CAPTION + " Trying to set value by combo box {name="+propertyName+" / value="+propertyValue+"} - finished."); 156 verifyPropertyValue(expectance); 157 158 }catch(Exception exc) { 159 failTest(exc, "EXCEPTION: setByCombo("+propertyName+", "+propertyValue+", "+expectance+") failed and cause exception:"+exc.getMessage()); 160 } 161 } 162 163 168 public void setByCombo(String propertyName, int propertyValueIndex, boolean expectance) { 169 try { 170 err.println(CAPTION + " Trying to set value by combo box {name="+propertyName+" / value="+propertyValueIndex+"} ."); 171 propertyInitialValue = getValue(propertyName); 172 173 findProperty(propertyName, propertiesWindow).setValue(propertyValueIndex); 174 175 err.println(CAPTION + " Trying to set value by combo box {name="+propertyName+" / value="+propertyValueIndex+"} - finished."); 176 verifyPropertyValue(expectance); 177 178 }catch(Exception exc) { 179 failTest(exc, "EXCEPTION: setByCombo("+propertyName+", "+propertyValueIndex+", "+expectance+") failed and cause exception:"+exc.getMessage()); 180 } 181 } 182 183 186 public void verifyCustomizer(String propertyName){ 187 try { 188 err.println(CAPTION + " Trying to verify customizer {name="+propertyName+"} ."); 189 openAndGetPropertyCustomizer(propertyName); 190 verifyCustomizerLayout(); 191 192 if(propertyCustomizer.isShowing()) 193 propertyCustomizer.cancel(); 194 195 err.println(CAPTION + " Trying to verify customizer {name="+propertyName+"} - finished."); 196 197 }catch(Exception exc) { 198 failTest(exc, "EXCEPTION: Verification of Property Customizer Layout for property("+propertyName+") failed and cause exception:"+exc.getMessage()); 199 } 200 } 201 202 206 public static NbDialogOperator openAndGetPropertyCustomizer(String propertyName) { 207 new PropertySheetOperator(propertiesWindow).tblSheet().selectCell(0,0); 209 210 findProperty(propertyName, propertiesWindow).openEditor(); 211 propertyCustomizer = findPropertyCustomizer(propertyName); 212 return propertyCustomizer; 213 } 214 215 218 public NbDialogOperator getPropertyCustomizer() { 219 return propertyCustomizer; 220 } 221 222 225 public NbDialogOperator getInformationDialog() { 226 String title = org.netbeans.jellytools.Bundle.getString("org.openide.Bundle", "NTF_InformationTitle"); 227 228 err.println(CAPTION + " Waiting dialog {"+title+"} ."); 229 NbDialogOperator dialog = new NbDialogOperator(title); 230 err.println(CAPTION + " Waiting dialog {"+title+"} - finished."); 231 return dialog; 232 } 233 234 238 public String getValue(String propertyName) { 239 String returnValue = findProperty(propertyName, propertiesWindow).getValue(); 240 err.println("GET VALUE = [" + returnValue + "]."); 241 return returnValue; 242 } 243 244 248 private static NbDialogOperator findPropertyCustomizer(String propertyName){ 249 return new NbDialogOperator(propertyName); 250 } 251 252 259 public void verifyExpectationValue(String propertyName, boolean expectation, String propertyValueExpectation, String propertyValue, boolean waitDialog){ 260 261 if(waitDialog) { 263 getInformationDialog().ok(); 264 err.println(CAPTION + " Dialog closed by [Ok]."); 265 266 if(propertyCustomizer!=null && propertyCustomizer.isShowing()){ 267 err.println(CAPTION + " Property Customizer is still showing."); 268 propertyCustomizer.cancel(); 269 err.println(CAPTION + " Property Customizer closed by [Cancel]."); 270 } 271 272 } 273 274 String newValue = getValue(propertyName); 275 String log = "Actual value is {"+newValue+"} and initial is{"+propertyInitialValue+"} - set value is {"+propertyValue+"} / expectation value is {"+propertyValueExpectation+"}"; 276 277 err.println(CAPTION + " Trying to verify value ["+log+"]."); 278 279 if(expectation){ 280 if(newValue.equals(propertyValueExpectation) ) { 281 log(log + " --> PASS"); 282 }else { 283 fail(log + " --> FAIL"); 284 } 285 }else { 286 if(newValue.equals(propertyInitialValue)){ 287 log(log + " --> PASS"); 288 }else{ 289 fail(log + " --> FAIL"); 290 } 291 292 } 293 } 294 295 296 297 public static NbDialogOperator reInitializeWorkplace() { 298 propertiesWindow = null; 299 return openPropertySheet(); 300 } 301 302 303 public static NbDialogOperator initializeWorkplace() { 304 return openPropertySheet(); 305 } 306 307 308 private static NbDialogOperator openPropertySheet() { 309 String waitDialogTimeout = "DialogWaiter.WaitDialogTimeout"; 310 long findTimeout = JemmyProperties.getCurrentTimeout(waitDialogTimeout); 311 JemmyProperties.setCurrentTimeout(waitDialogTimeout, 3000); 312 313 try{ 314 propertiesWindow = new NbDialogOperator(org.netbeans.jellytools.Bundle.getString("org.netbeans.core.Bundle", "CTL_FMT_LocalProperties", new Object []{new Integer (1),"TestNode"})); 315 }catch(org.netbeans.jemmy.TimeoutExpiredException exception){ 316 new PropertiesTest(); 317 propertiesWindow = new NbDialogOperator(org.netbeans.jellytools.Bundle.getString("org.netbeans.core.Bundle", "CTL_FMT_LocalProperties", new Object []{new Integer (1),"TestNode"})); 318 } 319 320 JemmyProperties.setCurrentTimeout(waitDialogTimeout, findTimeout); 321 322 return propertiesWindow; 323 } 324 325 326 332 protected static Property findProperty(String propertyName, NbDialogOperator propertiesWindow) { 333 PropertySheetOperator propertySheet = new PropertySheetOperator(propertiesWindow); 334 Property property = new Property(propertySheet, propertyName); 335 336 tableOperator = propertySheet.tblSheet(); 339 tableOperator.makeComponentVisible(); 342 tableOperator.requestFocus(); 343 tableOperator.waitHasFocus(); 344 ((javax.swing.JTable )tableOperator.getSource()).changeSelection(property.getRow(), 0, false, false); 346 return property; 348 } 349 350 public void tearDown() { 351 closeAllModal(); 352 } 353 354 358 protected static void failTest(Exception exc, String message) { 359 err.println("################################"); 360 exc.printStackTrace(err); 361 err.println("################################"); 362 fail(message); 363 } 364 365 368 public static void makeIDEScreenshot(JellyTestCase testCase) { 369 try{ 370 testCase.getWorkDir(); 371 org.netbeans.jemmy.util.PNGEncoder.captureScreen(testCase.getWorkDirPath()+System.getProperty("file.separator")+"IDEscreenshot.png"); 372 }catch(Exception ioexc){ 373 testCase.log("Impossible make IDE screenshot!!! \n" + ioexc.toString()); 374 } 375 } 376 377 public abstract void setCustomizerValue(); 378 379 public abstract void verifyCustomizerLayout(); 380 381 public abstract void verifyPropertyValue(boolean expectation); 382 383 } 384 | Popular Tags |