package org.netbeans.jellytools.examples; import java.awt.event.KeyEvent; import java.io.File; import org.netbeans.jellytools.Bundle; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.MainWindowOperator; import org.netbeans.jellytools.NbDialogOperator; import org.netbeans.jellytools.NewWizardOperator; import org.netbeans.jellytools.OutputWindowOperator; import org.netbeans.jellytools.NewObjectNameStepOperator; import org.netbeans.jellytools.nodes.JavaNode; import org.netbeans.jellytools.nodes.FilesystemNode; import org.netbeans.jemmy.operators.JEditorPaneOperator; import org.netbeans.junit.NbTestSuite; //requires that /sampledir/HelloWorld des not exists. public class I18NTest extends JellyTestCase { //constructor required by JUnit public I18NTest(java.lang.String testName) { super(testName); } //method allowing to execute test directly //from IDE for debugging public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } //method required by JUnit public static junit.framework.Test suite() { return new NbTestSuite(I18NTest.class); } //method to define test scenario public void testCreateClass() { //create a node for the sampledir directory FilesystemNode tmpNode = new FilesystemNode( System.getProperty("netbeans.user") + File.separator + "sampledir"); //invoke wizard on the node NewWizardOperator wizard = NewWizardOperator.invoke(tmpNode, "Java Classes|" + Bundle.getString("org.openide.src.nodes.Bundle", "CTL_Class")); //type class name new NewObjectNameStepOperator().setName("HelloWorld"); //push finish wizard.finish(); //create a node for the source JavaNode clNode = new JavaNode(tmpNode, "HelloWorld"); //find editor EditorOperator editor = new EditorOperator("HelloWorld"); //get reference to editing component JEditorPaneOperator txtOper = editor.txtEditorPane(); //put caret at the beginning of "public class HelloWorld" line txtOper.setCaretPosition( txtOper.getPositionByText("public class HelloWorld")); //move caret 1 line down editor.setCaretPositionToLine(editor.getLineNumber() + 1); //push Enter txtOper.pushKey(KeyEvent.VK_ENTER); //push up arrow editor.pushUpArrowKey(); //pust Tab editor.pushTabKey(); //type first line txtOper.typeText("public static void main(String[] argv) {\n"); //type second line txtOper.typeText("System.out.println(\"Hello, world!\");\n"); //type third line // closing brace is generated automatically // txtOper.typeText("}\n"); //executing clNode.execute(); //wait for a status in main window footer MainWindowOperator.getDefault(). waitStatusText(Bundle.getStringTrimmed("org.netbeans.core.compiler.Bundle", "MSG_CompilationSuccessful")); //create an operator for output window OutputWindowOperator output = OutputWindowOperator.invoke(); //select "HelloWorld" page and get a terminal from it //wait "Hello, world!" to be displayed output.getTerm("HelloWorld").waitText("Hello, world!"); //select "Compiler" page output.selectCompilerPage(); //check that "Finished" text displayed if(output.getText(). indexOf(Bundle.getStringTrimmed("org.netbeans.core.compiler.Bundle", "MSG_CompilationSuccessful")) == -1) { fail(); } //deletion clNode.delete(); //close confirmation dialog new NbDialogOperator("Confirm Object Deletion").yes(); } }