1 19 20 package org.netbeans.lib.cvsclient; 21 22 import junit.framework.TestCase; 23 24 import java.io.*; 25 import java.util.Date ; 26 27 import org.netbeans.lib.cvsclient.admin.Entry; 28 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; 29 import org.netbeans.lib.cvsclient.command.GlobalOptions; 30 import org.netbeans.lib.cvsclient.command.commit.CommitCommand; 31 import org.netbeans.lib.cvsclient.connection.Connection; 32 import org.netbeans.lib.cvsclient.connection.PServerConnection; 33 34 39 public class CommitTest extends TestCase { 40 41 48 public void test36288() throws Exception { 49 File tmpDir = TestKit.createTmpFolder("commitConflictTest"); 50 String protocolLog = new File(tmpDir, "protocol").getAbsolutePath(); 51 System.setProperty("cvsClientLog", protocolLog); 52 System.out.println(protocolLog); 53 54 File CVSdir = new File(tmpDir, "CVS"); 56 CVSdir.mkdirs(); 57 File entries = new File(CVSdir, "Entries"); 58 OutputStream out = new FileOutputStream(entries); 59 String dateString = "Thu Mar 24 15:14:27 2005"; 60 String data = "/conflict.txt/1.2/Result of merge+" + dateString + "//\nD"; 61 out.write(data.getBytes("utf8")); 62 out.flush(); 63 out.close(); 64 65 File conflict_txt = new File(tmpDir, "conflict.txt"); 66 out = new FileOutputStream(conflict_txt); 67 data = "AAA\n" + 68 "BBB\n" + 69 "<<<<<<< conflict.txt\n" + 70 "YYY <= fix\n" + 71 "=======\n" + 72 "222 <= fix\n" + 73 ">>>>>>> 1.2\n" + 74 "DDD\n" + 75 "EEE\n"; 76 out.write(data.getBytes("utf8")); 77 out.flush(); 78 out.close(); 79 Date date = Entry.getLastModifiedDateFormatter().parse(dateString); 80 conflict_txt.setLastModified(date.getTime()); 81 82 InputStream in = getClass().getResourceAsStream("protocol/iz36288.in"); 83 if (in == null) { 84 System.err.println(getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm()); 85 in.markSupported(); 86 } 87 PseudoCvsServer cvss = new PseudoCvsServer(in); 88 89 File requestsLog = File.createTempFile("requests", null, tmpDir); 90 cvss.logRequests(new FileOutputStream(requestsLog)); 91 new Thread (cvss).start(); 92 String cvsRoot = cvss.getCvsRoot(); 93 94 File root = new File(CVSdir, "Root"); 95 out = new FileOutputStream(root); 96 out.write(cvsRoot.getBytes("utf8")); 97 out.flush(); 98 out.close(); 99 100 File repo = new File(CVSdir, "Repository"); 101 out = new FileOutputStream(repo); 102 out.write("/cvs".getBytes("utf8")); 103 out.flush(); 104 out.close(); 105 106 CVSRoot CvsRoot = CVSRoot.parse(cvsRoot); 108 GlobalOptions gtx = new GlobalOptions(); 109 gtx.setCVSRoot(cvsRoot); 110 Connection connection = new PServerConnection(CvsRoot); 111 Client client = new Client(connection, new StandardAdminHandler()); 112 client.setLocalPath(tmpDir.getAbsolutePath()); 113 114 CommitCommand commit = new CommitCommand(); 115 File[] files = new File[] {new File(tmpDir, "conflict.txt")}; 116 commit.setFiles(files); 117 118 client.executeCommand(commit, gtx); 119 cvss.stop(); 120 121 123 InputStream actual = new FileInputStream(requestsLog); 124 LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(actual, "utf8")); 125 boolean foundConflictLine = false; 126 String line = lineReader.readLine(); 127 StringBuffer sb = new StringBuffer (); 128 while (foundConflictLine == false && line != null) { 129 sb.append(line + "\n"); 130 foundConflictLine |= "Entry /conflict.txt/1.2/+=//".equals(line); 131 line = lineReader.readLine(); 132 } 133 assertTrue("Missing 'Entry /conflict.txt/1.2/+=//' in:\n" + sb.toString(), foundConflictLine); 134 135 TestKit.deleteRecursively(tmpDir); 136 } 137 138 } 139 | Popular Tags |