1 19 20 package org.netbeans.test.cvsmodule; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import junit.textui.TestRunner; 26 import org.netbeans.jellytools.EditorOperator; 27 import org.netbeans.jellytools.JellyTestCase; 28 import org.netbeans.jellytools.NbDialogOperator; 29 import org.netbeans.jellytools.OutputOperator; 30 import org.netbeans.jellytools.OutputTabOperator; 31 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator; 32 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator; 33 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator; 34 import org.netbeans.jellytools.modules.javacvs.TagOperator; 35 import org.netbeans.jellytools.nodes.Node; 36 import org.netbeans.jellytools.nodes.SourcePackagesNode; 37 import org.netbeans.jemmy.JemmyProperties; 38 import org.netbeans.jemmy.QueueTool; 39 import org.netbeans.jemmy.TimeoutExpiredException; 40 import org.netbeans.jemmy.operators.JButtonOperator; 41 import org.netbeans.jemmy.operators.JProgressBarOperator; 42 import org.netbeans.jemmy.operators.Operator; 43 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 44 import org.netbeans.junit.NbTestSuite; 45 import org.netbeans.junit.ide.ProjectSupport; 46 50 public class TagTest extends JellyTestCase { 51 52 String os_name; 53 static String sessionCVSroot; 54 boolean unix = false; 55 final String projectName = "ForImport"; 56 final String pathToMain = "forimport|Main.java"; 57 final String PROTOCOL_FOLDER = "protocol"; 58 Operator.DefaultStringComparator comOperator; 59 Operator.DefaultStringComparator oldOperator; 60 61 62 public TagTest(String name) { 63 super(name); 64 } 65 66 protected void setUp() throws Exception { 67 68 os_name = System.getProperty("os.name"); 69 System.out.println("### "+getName()+" ###"); 71 72 } 73 74 protected boolean isUnix() { 75 boolean unix = false; 76 if (os_name.indexOf("Windows") == -1) { 77 unix = true; 78 } 79 return unix; 80 } 81 82 public static void main(String [] args) { 83 TestRunner.run(suite()); 85 } 86 87 public static NbTestSuite suite() { 88 NbTestSuite suite = new NbTestSuite(); 89 suite.addTest(new TagTest("testCheckOutProject")); 90 suite.addTest(new TagTest("testTagDialogUI")); 91 suite.addTest(new TagTest("testCreateNewTag")); 92 suite.addTest(new TagTest("testCreateTagOnModified")); 93 suite.addTest(new TagTest("testOnNonVersioned")); 94 suite.addTest(new TagTest("removeAllData")); 95 return suite; 98 } 99 100 public void testCheckOutProject() throws Exception { 101 TestKit.closeProject(projectName); 104 OutputOperator oo = OutputOperator.invoke(); 105 comOperator = new Operator.DefaultStringComparator(true, true); 106 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 107 Operator.setDefaultStringComparator(comOperator); 108 CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke(); 109 Operator.setDefaultStringComparator(oldOperator); 110 CVSRootStepOperator crso = new CVSRootStepOperator(); 111 crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs"); 113 116 InputStream in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in"); 119 PseudoCvsServer cvss = new PseudoCvsServer(in); 120 new Thread (cvss).start(); 121 cvss.ignoreProbe(); 122 String CVSroot = cvss.getCvsRoot(); 123 sessionCVSroot = CVSroot; 124 crso.setCVSRoot(CVSroot); 125 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot); 126 crso.next(); 127 128 try { 129 JProgressBarOperator progress = new JProgressBarOperator(crso); 130 JButtonOperator btnStop = new JButtonOperator(crso); 131 } catch (TimeoutExpiredException e) { 132 throw e; 133 } 134 135 138 File tmp = new File ("/tmp"); File work = new File (tmp, "" + File.separator + System.currentTimeMillis()); 140 tmp.mkdirs(); 141 work.mkdirs(); 142 tmp.deleteOnExit(); 143 ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator(); 144 cvss.stop(); 145 in.close(); 146 moduleCheck.setModule("ForImport"); 147 moduleCheck.setLocalFolder(work.getAbsolutePath()); 149 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in"); 151 cvss = new PseudoCvsServer(in); 152 new Thread (cvss).start(); 153 CVSroot = cvss.getCvsRoot(); 154 156 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot); 159 cwo.finish(); 160 161 162 OutputTabOperator oto = new OutputTabOperator(sessionCVSroot); 165 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 166 oto.waitText("Checking out finished"); 167 cvss.stop(); 168 in.close(); 169 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 170 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 171 open.push(); 172 173 ProjectSupport.waitScanFinished(); 174 new QueueTool().waitEmpty(1000); 175 ProjectSupport.waitScanFinished(); 176 177 TestKit.createNewElements(projectName); 179 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 180 } 181 182 public void testTagDialogUI() throws Exception { 183 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 184 TagOperator to = TagOperator.invoke(node); 185 to.setTagName("TagTest"); 186 187 JButtonOperator btnTag = new JButtonOperator(to, "Tag"); 189 JButtonOperator btnHelp = new JButtonOperator(to, "Help"); 190 JButtonOperator btnCancel = new JButtonOperator(to, "Cancel"); 191 192 to.checkAvoidTaggingLocallyModifiedFiles(false); 193 assertFalse(to.cbAvoidTaggingLocallyModifiedFiles().isSelected()); 195 to.checkAvoidTaggingLocallyModifiedFiles(true); 197 assertTrue(to.cbAvoidTaggingLocallyModifiedFiles().isSelected()); 198 to.checkMoveExistingTag(false); 200 assertFalse(to.cbMoveExistingTag().isSelected()); 201 to.checkMoveExistingTag(true); 203 assertTrue(to.cbMoveExistingTag().isSelected()); 204 to.cancel(); 205 } 206 207 public void testCreateNewTag() throws Exception { 208 PseudoCvsServer cvss; 211 InputStream in; 212 213 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 214 TagOperator to = TagOperator.invoke(node); 215 to.setTagName("MyNewTag"); 216 217 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "create_new_tag.in"); 218 cvss = new PseudoCvsServer(in); 219 new Thread (cvss).start(); 220 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 221 JButtonOperator btnTag = new JButtonOperator(to, "Tag"); 222 btnTag.push(); 223 224 OutputTabOperator oto = new OutputTabOperator(sessionCVSroot); 226 oto.waitText("Tagging \"Main.java\"... finished"); 227 cvss.stop(); 228 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 229 } 230 231 public void testCreateTagOnModified() throws Exception { 232 PseudoCvsServer cvss; 235 InputStream in; 236 237 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 238 node.performPopupAction("Open"); 239 EditorOperator eo = new EditorOperator("Main.java"); 240 eo.insert("//Comment\n"); 241 eo.save(); 242 Thread.sleep(1000); 243 244 TagOperator to = TagOperator.invoke(node); 245 to.setTagName("MyNewTag"); 246 to.checkAvoidTaggingLocallyModifiedFiles(false); 247 248 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "create_new_tag_on_modified.in"); 249 cvss = new PseudoCvsServer(in); 250 new Thread (cvss).start(); 251 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 252 JButtonOperator btnTag = new JButtonOperator(to, "Tag"); 253 btnTag.push(); 254 255 OutputTabOperator oto = new OutputTabOperator(sessionCVSroot); 257 oto.waitText("cvs server: Main.java is locally modified"); 258 oto.waitText("correct the above errors first!"); 259 cvss.stop(); 260 261 NbDialogOperator nbd = new NbDialogOperator("Command Failed"); 262 JButtonOperator btnOk = new JButtonOperator(nbd, "OK"); 263 btnOk.push(); 264 oto.waitText("Tagging \"Main.java\"... finished"); 265 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 266 } 267 268 public void testOnNonVersioned() throws Exception { 269 274 TimeoutExpiredException tee = null; 275 try { 276 Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java"); 277 TagOperator bo = TagOperator.invoke(node); 278 } catch (Exception e) { 279 tee = (TimeoutExpiredException) e; 280 } 281 assertNotNull(tee); 282 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 283 } 284 285 public void removeAllData() throws Exception { 286 TestKit.closeProject(projectName); 287 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 288 } 289 } 290 | Popular Tags |