001: package org.netbeans.test.junit4;
002:
003: import java.util.ArrayList;
004: import java.util.Hashtable;
005: import javax.swing.ListModel;
006: import org.netbeans.jellytools.EditorOperator;
007: import org.netbeans.jellytools.NbDialogOperator;
008: import org.netbeans.jellytools.NewProjectWizardOperator;
009: import org.netbeans.jellytools.ProjectsTabOperator;
010: import org.netbeans.jellytools.actions.Action;
011: import org.netbeans.jellytools.actions.ActionNoBlock;
012: import org.netbeans.jellytools.actions.OpenAction;
013: import org.netbeans.jellytools.nodes.Node;
014: import org.netbeans.jellytools.nodes.ProjectRootNode;
015: import org.netbeans.jemmy.operators.JButtonOperator;
016: import org.netbeans.jemmy.operators.JListOperator;
017: import org.netbeans.jemmy.operators.JRadioButtonOperator;
018: import org.netbeans.jemmy.operators.JTextFieldOperator;
019: import org.netbeans.jemmy.operators.Operator;
020: import org.netbeans.junit.NbTestSuite;
021:
022: public class CreateProjectTest extends ExtJellyTestCase {
023:
024: public CreateProjectTest(String testName) {
025: super (testName);
026: }
027:
028: public static void main(java.lang.String[] args) {
029: junit.textui.TestRunner.run(suite());
030: }
031:
032: public static NbTestSuite suite() {
033: NbTestSuite suite = new NbTestSuite();
034: suite.addTest(new CreateProjectTest("testCreateJUnit4Project")); // NOI18N
035: suite.addTest(new CreateProjectTest("testAddLibrary")); // NOI18N
036: suite.addTest(new CreateProjectTest(
037: "testGeneratedRootSuiteFile")); // NOI18N
038: suite.addTest(new CreateProjectTest(
039: "testGeneratedProjectSuiteFile")); // NOI18N
040: suite
041: .addTest(new CreateProjectTest(
042: "testGeneratedMainTestFile")); // NOI18N
043: return suite;
044: }
045:
046: public void testCreateJUnit4Project() {
047: // create anagram project
048: new Action("File|New Project", null).perform();
049: NewProjectWizardOperator newOp = new NewProjectWizardOperator();
050: newOp.selectCategory("Java");
051: newOp.selectProject("Java Application");
052: newOp.next();
053: new JTextFieldOperator(newOp, 0).typeText(TEST_PROJECT_NAME);
054: newOp.finish();
055:
056: // select source packages node
057: ProjectsTabOperator pto = new ProjectsTabOperator();
058: ProjectRootNode prn = pto.getProjectRootNode(TEST_PROJECT_NAME);
059: prn.select();
060: Node node = new Node(prn, "Source Packages"); // NOI18N
061: node.setComparator(new Operator.DefaultStringComparator(true,
062: false));
063: node.select();
064:
065: // create test
066: new ActionNoBlock(null, "Tools|Create JUnit Test")
067: .perform(node);
068:
069: // select junit version
070: NbDialogOperator versionOp = new NbDialogOperator(
071: "Select jUnit Version");
072: new JRadioButtonOperator(versionOp, 1).setSelected(true);
073: new JButtonOperator(versionOp, "Select").clickMouse();
074:
075: NbDialogOperator newTestOp = new NbDialogOperator(
076: "Create Tests");
077: new JButtonOperator(newTestOp, "OK").clickMouse();
078:
079: new Action("Window|Close All Documents", null).perform();
080: }
081:
082: public void testAddLibrary() {
083: // useless method while executing this test internally
084: // but there is a missing libraty while executing this test on external IDE
085: ProjectRootNode prn = new ProjectsTabOperator()
086: .getProjectRootNode(TEST_PROJECT_NAME);
087: Node libNode = new Node(prn, "Test Libraries");
088: new ActionNoBlock(null, "Add Library").perform(libNode);
089: NbDialogOperator libDialog = new NbDialogOperator("Add Library");
090: JListOperator listOp = new JListOperator(libDialog, 0);
091: listOp.clickOnItem("junit",
092: new Operator.DefaultStringComparator(true, false));
093: new JButtonOperator(libDialog, "Add Library").push();
094: }
095:
096: public void testGeneratedRootSuiteFile() {
097: ProjectRootNode prn = new ProjectsTabOperator()
098: .getProjectRootNode(TEST_PROJECT_NAME);
099: OpenAction openAc = new OpenAction();
100:
101: // testing RootSuite.java
102: openAc.perform(new Node(prn,
103: "Test Packages|<default package>|RootSuite.java"));
104:
105: ArrayList<String> lines = new ArrayList<String>();
106: lines.add("import org.junit.");
107: lines.add("@RunWith(Suite.class)");
108: lines
109: .add("@Suite.SuiteClasses({Junit4testprojectSuite.class})");
110: lines
111: .add("public static void tearDownClass() throws Exception");
112: lines.add("@Before");
113:
114: findInCode(lines, new EditorOperator("RootSuite.java"));
115: }
116:
117: public void testGeneratedProjectSuiteFile() {
118: ProjectRootNode prn = new ProjectsTabOperator()
119: .getProjectRootNode(TEST_PROJECT_NAME);
120: OpenAction openAc = new OpenAction();
121:
122: // testing Junit4testprojectSuite.java
123: openAc
124: .perform(new Node(prn,
125: "Test Packages|junit4testproject|Junit4testprojectSuite.java"));
126:
127: ArrayList<String> lines = new ArrayList<String>();
128: lines.add("import org.junit.");
129: lines.add("@Suite.SuiteClasses({MainTest.class})");
130: lines.add("@RunWith(Suite.class)");
131: lines
132: .add("public static void tearDownClass() throws Exception");
133: lines.add("@Before");
134:
135: findInCode(lines, new EditorOperator(
136: "Junit4testprojectSuite.java"));
137: }
138:
139: public void testGeneratedMainTestFile() {
140: ProjectRootNode prn = new ProjectsTabOperator()
141: .getProjectRootNode(TEST_PROJECT_NAME);
142: OpenAction openAc = new OpenAction();
143:
144: // testing MainTest.java
145: openAc.perform(new Node(prn,
146: "Test Packages|junit4testproject|MainTest.java"));
147:
148: ArrayList<String> lines = new ArrayList<String>();
149: lines.add("import org.junit.");
150: lines.add("import static org.junit.Assert.*;");
151: lines.add("@Test");
152: lines.add("@BeforeClass");
153: lines.add("@AfterClass");
154:
155: findInCode(lines, new EditorOperator("MainTest.java"));
156: }
157: }
|