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.log.RlogCommand; 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 RlogTest extends TestCase { 38 39 42 public void test57365() throws Exception { 43 44 final File tmpDir = TestKit.createTmpFolder("rlogTest"); 45 String protocolLog = new File(tmpDir, "protocol").getAbsolutePath(); 46 System.setProperty("cvsClientLog", protocolLog); 47 System.out.println(protocolLog); 48 49 final InputStream in = getClass().getResourceAsStream("protocol/iz57365.in"); 50 if (in == null) { 51 System.err.println(getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm()); 52 in.markSupported(); 53 } 54 55 final File requestsLog = File.createTempFile("requests", null, tmpDir); 56 57 final Exception testException[] = new Exception [1]; 58 final boolean completedFlag[] = new boolean[] {false}; 59 Runnable run = new Runnable () { 60 public void run() { 61 try { 62 PseudoCvsServer cvss = new PseudoCvsServer(in); 63 cvss.logRequests(new FileOutputStream(requestsLog)); 64 try { 65 new Thread (cvss).start(); 66 67 String cvsRoot = cvss.getCvsRoot(); 68 CVSRoot root = CVSRoot.parse(cvsRoot); 69 GlobalOptions gtx = new GlobalOptions(); 70 gtx.setCVSRoot(cvsRoot); 71 Connection connection = new PServerConnection(root); 72 Client client = new Client(connection, new StandardAdminHandler()); 73 client.setLocalPath(tmpDir.getAbsolutePath()); 74 75 RlogCommand rlog = new RlogCommand(); 76 rlog.setModule("folder/file"); 77 78 client.executeCommand(rlog, gtx); 79 synchronized(completedFlag) { 80 completedFlag[0] = true; 81 completedFlag.notifyAll(); 82 } 83 84 } finally { 85 cvss.stop();; 86 } 87 } catch (Exception ex) { 88 testException[0] = ex; 89 } 90 } 91 }; 92 93 Thread t = new Thread (run); 94 t.start(); 95 synchronized(completedFlag) { 96 if (completedFlag[0] == false) { 97 completedFlag.wait(1000); } 99 } 100 t.interrupt(); 101 if (testException[0] != null) { 102 throw testException[0]; 103 } 104 105 107 InputStream actual = new FileInputStream(requestsLog); 108 LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(actual, "utf8")); 109 boolean foundDirectoryLine = false; 110 boolean foundRlog = false; 111 String line = lineReader.readLine(); 112 StringBuffer sb = new StringBuffer (); 113 while (line != null) { 114 sb.append(line + "\n"); 115 foundDirectoryLine |= line.startsWith("Directory"); 116 foundRlog |= line.equals("rlog"); 117 line = lineReader.readLine(); 118 } 119 assertFalse("Local state is irrelevant in:\n" + sb.toString(), foundDirectoryLine); 120 assertTrue("Where is rlog? in:" + sb.toString(), foundRlog); 121 TestKit.deleteRecursively(tmpDir); 122 123 } 124 125 } 126 | Popular Tags |