Index: unit/src/org/openide/WizardDescTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/WizardDescTest.java,v retrieving revision 1.6 diff -u -r1.6 WizardDescTest.java --- unit/src/org/openide/WizardDescTest.java 28 Jul 2004 14:34:18 -0000 1.6 +++ unit/src/org/openide/WizardDescTest.java 11 May 2005 12:14:07 -0000 @@ -7,7 +7,7 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide; @@ -26,6 +26,8 @@ import javax.swing.event.ChangeListener; import org.netbeans.junit.NbTestCase; import org.openide.WizardDescriptor; +import org.openide.WizardDescriptor.ValidatingPanel; +import org.openide.WizardDescriptor.AsynchronousValidatingPanel; import org.openide.util.*; import org.openide.util.HelpCtx; @@ -58,6 +60,10 @@ //d.show(); } + public boolean runInEQ () { + return true; + } + public void testNextOption () throws Exception { exceptedValue = "NEXT_OPTION"; log ("Do click Next button."); @@ -162,6 +168,101 @@ mfp.validateMsg = null; mfp.failedMsg = null; wd.doFinishClick (); + assertNull ("Validation on Finish passes", mfp.failedMsg); + assertNull ("Finish was clicked, no initialization either", panels[2].component); + assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ()); + } + + public void testAsynchronousLazyValidation () throws Exception { + Panel panels[] = new Panel[3]; + + class MyPanel extends Panel implements WizardDescriptor.AsynchronousValidatingPanel { + public String validateMsg; + public String failedMsg; + public boolean running; + + public MyPanel () { + super ("enhanced panel"); + } + + public void prepareValidation () { + running = true; + } + + public void validate () throws WizardValidationException { + running = false; + if (validateMsg != null) { + failedMsg = validateMsg; + throw new WizardValidationException (null, "MyPanel.validate() failed.", validateMsg); + } + return; + } + } + + class MyFinishPanel extends MyPanel implements WizardDescriptor.FinishablePanel { + public boolean isFinishPanel () { + return true; + } + } + + MyPanel mp = new MyPanel (); + MyFinishPanel mfp = new MyFinishPanel (); + panels[0] = mp; + panels[1] = mfp; + panels[2] = new Panel ("Last one"); + wd = new WizardDescriptor(panels); + + assertNull ("Component has not been yet initialized", panels[1].component); + mp.failedMsg = null; + mp.validateMsg = "xtest-fail-without-msg"; + assertTrue ("Next button must be enabled.", wd.isNextEnabled ()); + wd.doNextClick (); + assertTrue ("Validation runs.", mp.running); + assertFalse ("Wizard is not valid now.", wd.isValid ()); + // let's wait till wizard is valid + while (mp.running) { + assertFalse ("Wizard is not valid during validation.", wd.isValid ()); + Thread.sleep (10); + } + assertFalse ("Wizard is not valid when validation fails.", wd.isValid ()); + assertEquals ("The lazy validation failed on Next.", mp.validateMsg, mp.failedMsg); + assertNull ("The lazy validation failed, still no initialiaation", panels[1].component); + assertNull ("The lazy validation failed, still no initialiaation", panels[2].component); + mp.failedMsg = null; + mp.validateMsg = null; + wd.doNextClick (); + assertTrue ("Validation runs.", mp.running); + while (mp.running) { + assertFalse ("Wizard is not valid during validation.", wd.isValid ()); + Thread.sleep (10); + } + assertTrue ("Wizard is valid when validation passes.", wd.isValid ()); + assertNull ("Validation on Next passes", mp.failedMsg); + assertNotNull ("Now we switched to another panel", panels[1].component); + assertNull ("The lazy validation failed, still no initialiaation", panels[2].component); + + // remember previous state + Object state = wd.getValue(); + mfp.validateMsg = "xtest-fail-without-msg"; + mfp.failedMsg = null; + wd.doFinishClick(); + while (mfp.running) { + assertFalse ("Wizard is not valid during validation.", wd.isValid ()); + Thread.sleep (10); + } + assertFalse ("Wizard is not valid when validation fails.", wd.isValid ()); + assertEquals ("The lazy validation failed on Finish.", mfp.validateMsg, mfp.failedMsg); + assertNull ("The validation failed, still no initialiaation", panels[2].component); + assertEquals ("State has not changed", state, wd.getValue ()); + + mfp.validateMsg = null; + mfp.failedMsg = null; + wd.doFinishClick (); + while (mfp.running) { + assertFalse ("Wizard is not valid during validation.", wd.isValid ()); + Thread.sleep (10); + } + assertTrue ("Wizard is valid when validation passes.", wd.isValid ()); assertNull ("Validation on Finish passes", mfp.failedMsg); assertNull ("Finish was clicked, no initialization either", panels[2].component); assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ());