KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > RlogTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
33  * Rlog command testcase.
34  *
35  * @author Petr Kuzel
36  */

37 public class RlogTest extends TestCase {
38
39     /**
40      * Tests rlog wire format.
41      */

42     public void test57365() throws Exception JavaDoc {
43
44         final File tmpDir = TestKit.createTmpFolder("rlogTest");
45         String JavaDoc 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 JavaDoc testException[] = new Exception JavaDoc[1];
58         final boolean completedFlag[] = new boolean[] {false};
59         Runnable JavaDoc run = new Runnable JavaDoc() {
60             public void run() {
61                 try {
62                     PseudoCvsServer cvss = new PseudoCvsServer(in);
63                     cvss.logRequests(new FileOutputStream(requestsLog));
64                     try {
65                         new Thread JavaDoc(cvss).start();
66
67                         String JavaDoc 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 JavaDoc ex) {
88                     testException[0] = ex;
89                 }
90             }
91         };
92
93         Thread JavaDoc t = new Thread JavaDoc(run);
94         t.start();
95         synchronized(completedFlag) {
96             if (completedFlag[0] == false) {
97                 completedFlag.wait(1000); // 'INFINITE' TIMEOUT
98
}
99         }
100         t.interrupt();
101         if (testException[0] != null) {
102             throw testException[0];
103         }
104
105         // check send data
106

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 JavaDoc line = lineReader.readLine();
112         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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