1 19 20 package org.netbeans.lib.cvsclient; 21 22 import junit.framework.TestCase; 23 import org.netbeans.lib.cvsclient.connection.Connection; 24 import org.netbeans.lib.cvsclient.connection.PServerConnection; 25 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; 26 import org.netbeans.lib.cvsclient.admin.Entry; 27 import org.netbeans.lib.cvsclient.command.status.StatusCommand; 28 import org.netbeans.lib.cvsclient.command.GlobalOptions; 29 import org.netbeans.lib.cvsclient.command.FileInfoContainer; 30 import org.netbeans.lib.cvsclient.command.PipedFileInformation; 31 import org.netbeans.lib.cvsclient.command.CommandException; 32 import org.netbeans.lib.cvsclient.command.log.RlogCommand; 33 import org.netbeans.lib.cvsclient.command.add.AddCommand; 34 import org.netbeans.lib.cvsclient.command.commit.CommitCommand; 35 import org.netbeans.lib.cvsclient.command.update.UpdateCommand; 36 import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand; 37 import org.netbeans.lib.cvsclient.event.*; 38 39 import java.io.*; 40 import java.util.Date ; 41 42 49 public class ClientTest extends TestCase { 50 51 55 public void test50963() throws Exception { 56 File tmpDir = TestKit.createTmpFolder("localFileStatusTest"); 57 File localCheckout = tmpDir; 58 String relativePath = "javacvs" + File.separator + "test" + File.separator + "data" + 59 File.separator + "iz50963" + File.separator + "removed.txt"; 60 String cvsRoot = ":pserver:anoncvs@netbeans.org:/cvs"; 61 62 System.setProperty("cvsClientLog", new File(tmpDir, "protocol").getAbsolutePath()); 63 65 CVSRoot root = CVSRoot.parse(cvsRoot); 66 GlobalOptions gtx = new GlobalOptions(); 67 gtx.setCVSRoot(cvsRoot); 68 69 71 Connection connection = new PServerConnection(root); 72 Client client = new Client(connection, new StandardAdminHandler()); 73 client.setLocalPath(tmpDir.getAbsolutePath()); 74 75 CheckoutCommand checkout = new CheckoutCommand(); 76 checkout.setModule("javacvs/test/data/iz50963"); 77 checkout.setPruneDirectories(true); 78 checkout.setNotShortenPaths(true); 79 checkout.setRecursive(true); 80 81 client.executeCommand(checkout, gtx); 82 83 File localFile = new File(localCheckout, relativePath); 84 if (localFile.createNewFile() == false) { 85 throw new IOException("Cannot create " + localFile); 86 } 87 88 90 connection = new PServerConnection(root); 91 client = new Client(connection, new StandardAdminHandler()); 92 client.setLocalPath(tmpDir.getAbsolutePath()); 93 94 95 StatusCommand status = new StatusCommand(); 96 File[] files = new File[] {new File(localCheckout, relativePath)}; 97 status.setFiles(files); 98 99 client.getEventManager().addCVSListener(new CVSListener() { 100 101 public void messageSent(MessageEvent e) { 102 } 103 104 public void messageSent(BinaryMessageEvent e) { 105 } 106 107 public void fileAdded(FileAddedEvent e) { 108 } 109 110 public void fileToRemove(FileToRemoveEvent e) { 111 } 112 113 public void fileRemoved(FileRemovedEvent e) { 114 } 115 116 public void fileUpdated(FileUpdatedEvent e) { 117 } 118 119 public void fileInfoGenerated(FileInfoEvent e) { 120 FileInfoContainer fic = e.getInfoContainer(); 121 System.err.println("Fic: " + fic); 122 } 123 124 public void commandTerminated(TerminationEvent e) { 125 } 126 127 public void moduleExpanded(ModuleExpansionEvent e) { 128 } 129 }); 130 client.executeCommand(status, gtx); 131 132 134 assertTrue(false); 135 136 138 TestKit.deleteRecursively(tmpDir); 139 140 } 141 142 146 public void test53239() throws Exception { 147 148 String checkoutModule = "javacvs/test/data"; 149 File tmpDir = TestKit.createTmpFolder("pruneTest"); 150 String localCheckout = tmpDir.getAbsolutePath(); 151 String cvsRoot = ":pserver:anoncvs@netbeans.org/cvs"; 152 153 System.setProperty("cvsClientLog", new File(tmpDir, "protocol").getAbsolutePath()); 154 156 CVSRoot root = CVSRoot.parse(cvsRoot); 157 Connection connection = new PServerConnection(root); 158 Client client = new Client(connection, new StandardAdminHandler()); 159 client.setLocalPath(localCheckout); 160 161 CheckoutCommand checkout = new CheckoutCommand(); 162 checkout.setModule(checkoutModule); 163 checkout.setPruneDirectories(true); 164 checkout.setNotShortenPaths(true); 165 checkout.setRecursive(true); 166 167 GlobalOptions gtx = new GlobalOptions(); 168 gtx.setCVSRoot(cvsRoot); 169 client.executeCommand(checkout, gtx); 170 171 173 String relativePath = "javacvs" + File.separator + "test" + File.separator + "data" + 174 File.separator + "CVS" + File.separator + "Entries"; 175 FileReader reader = new FileReader(new File(localCheckout, relativePath)); 176 BufferedReader buffy = new BufferedReader(reader); 177 String line = buffy.readLine(); 178 do { 179 assertTrue(line.indexOf("iz53239") == -1); 180 line = buffy.readLine(); 181 } while (line != null); 182 183 185 TestKit.deleteRecursively(tmpDir); 186 } 187 188 192 public void test56710() throws Exception { 193 File tmpDir = TestKit.createTmpFolder("binaryToStdoutTest"); 194 String relativePath = "javacvs" + File.separator + "test" + File.separator + "data" + 195 File.separator + "iz56710" + File.separator + "binary.out"; 196 197 String localCheckout = tmpDir.getAbsolutePath(); 198 String cvsRoot = ":pserver:anoncvs@netbeans.org/cvs"; 199 200 String protocolLog = new File(tmpDir, "protocol").getAbsolutePath(); 201 System.setProperty("cvsClientLog", protocolLog); 202 204 CVSRoot root = CVSRoot.parse(cvsRoot); 205 Connection connection = new PServerConnection(root); 206 Client client = new Client(connection, new StandardAdminHandler()); 207 client.setLocalPath(localCheckout); 208 209 UpdateCommand update = new UpdateCommand(); 210 update.setPipeToOutput(true); 211 File[] files = new File[] {new File(tmpDir, relativePath)}; 212 update.setFiles(files); 213 214 final File[] pipedTmpFile = new File[1]; 215 client.getEventManager().addCVSListener(new CVSListener() { 216 217 public void messageSent(MessageEvent e) { 218 } 219 220 public void messageSent(BinaryMessageEvent e) { 221 } 222 223 public void fileAdded(FileAddedEvent e) { 224 } 225 226 public void fileToRemove(FileToRemoveEvent e) { 227 } 228 229 public void fileRemoved(FileRemovedEvent e) { 230 } 231 232 public void fileUpdated(FileUpdatedEvent e) { 233 } 234 235 public void fileInfoGenerated(FileInfoEvent e) { 236 PipedFileInformation pfi = (PipedFileInformation) e.getInfoContainer(); 237 pipedTmpFile[0] = pfi.getTempFile(); 238 } 239 240 public void commandTerminated(TerminationEvent e) { 241 } 242 243 public void moduleExpanded(ModuleExpansionEvent e) { 244 } 245 }); 246 GlobalOptions gtx = new GlobalOptions(); 247 gtx.setCVSRoot(cvsRoot); 248 client.executeCommand(update, gtx); 249 250 FileInputStream in = new FileInputStream(pipedTmpFile[0]); 251 byte[] bytes = new byte[257]; 252 int len = in.read(bytes); 253 assertEquals(len, 256); 254 255 for (int i = 0; i<256; i++) { 256 assertEquals(bytes[i], (byte)i); 257 } 258 259 TestKit.deleteRecursively(tmpDir); 260 } 261 262 263 } 264 | Popular Tags |