KickJava   Java API By Example, From Geeks To Geeks.

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


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

37 public class AddTest extends TestCase {
38
39     /**
40      * Tests cvswrappers compliance.
41      * <p>
42      * Uses fake PseudoCvsServer.
43      */

44     public void test36289() throws Exception JavaDoc {
45
46         File tmpDir = TestKit.createTmpFolder("serverAbortTest");
47         String JavaDoc 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 JavaDoc(cvss).start();
57
58         String JavaDoc 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         // prepare working directory
67
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         // execute the command
84

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         // check test matching golden file (here critical line from issue #36289)
101

102         InputStream actual = new FileInputStream(requestsLog);
103         LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(actual, "utf8"));
104         String JavaDoc line = lineReader.readLine();
105         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
106         while (line != null) {
107             sb.append(line + "\n");
108             line = lineReader.readLine();
109         }
110         String JavaDoc 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