1 19 20 package org.netbeans.lib.cvsclient; 21 22 import junit.framework.TestCase; 23 24 import java.io.*; 25 26 import org.netbeans.lib.cvsclient.command.GlobalOptions; 27 import org.netbeans.lib.cvsclient.command.add.AddCommand; 28 import org.netbeans.lib.cvsclient.connection.Connection; 29 import org.netbeans.lib.cvsclient.connection.PServerConnection; 30 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; 31 32 37 public class AddTest extends TestCase { 38 39 44 public void test36289() throws Exception { 45 46 File tmpDir = TestKit.createTmpFolder("serverAbortTest"); 47 String protocolLog = new File(tmpDir, "protocol").getAbsolutePath(); 48 System.setProperty("cvsClientLog", protocolLog); 49 System.setProperty("Env-CVSWRAPPERS", "*.wrap -k 'b'"); 50 System.out.println(protocolLog); 51 52 InputStream in = getClass().getResourceAsStream("protocol/iz36289.in"); 53 final PseudoCvsServer cvss = new PseudoCvsServer(in); 54 File requestsLog = File.createTempFile("requests", null, tmpDir); 55 cvss.logRequests(new FileOutputStream(requestsLog)); 56 new Thread (cvss).start(); 57 58 String cvsRoot = cvss.getCvsRoot(); 59 CVSRoot root = CVSRoot.parse(cvsRoot); 60 final GlobalOptions gtx = new GlobalOptions(); 61 gtx.setCVSRoot(cvsRoot); 62 Connection connection = new PServerConnection(root); 63 final Client client = new Client(connection, new StandardAdminHandler()); 64 client.setLocalPath(tmpDir.getAbsolutePath()); 65 66 File CVSdir = new File(tmpDir, "CVS"); 68 CVSdir.mkdirs(); 69 70 OutputStream out; 71 File rootFile = new File(CVSdir, "Root"); 72 out = new FileOutputStream(rootFile); 73 out.write(cvsRoot.getBytes("utf8")); 74 out.flush(); 75 out.close(); 76 77 File repo = new File(CVSdir, "Repository"); 78 out = new FileOutputStream(repo); 79 out.write("/cvs".getBytes("utf8")); 80 out.flush(); 81 out.close(); 82 83 85 AddCommand add = new AddCommand(); 86 File wrap = new File(tmpDir, "test.wrap"); 87 File txt = new File(tmpDir, "test.txt"); 88 if (wrap.createNewFile() == false) { 89 throw new IOException("Can not create " + wrap); 90 } 91 if (txt.createNewFile() == false) { 92 throw new IOException("Can not create " + txt); 93 } 94 File[] files = new File[] {wrap, txt}; 95 add.setFiles(files); 96 97 client.executeCommand(add, gtx); 98 cvss.stop(); 99 100 102 InputStream actual = new FileInputStream(requestsLog); 103 LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(actual, "utf8")); 104 String line = lineReader.readLine(); 105 StringBuffer sb = new StringBuffer (); 106 while (line != null) { 107 sb.append(line + "\n"); 108 line = lineReader.readLine(); 109 } 110 String requests = sb.toString(); 111 assertTrue(requests, requests.indexOf("Kopt -kb\n" + 112 "Is-modified test.wrap") != -1); 113 114 TestKit.deleteRecursively(tmpDir); 115 116 } 117 118 } 119 | Popular Tags |