001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.lib.cvsclient;
043:
044: import junit.framework.TestCase;
045:
046: import java.io.*;
047:
048: import org.netbeans.lib.cvsclient.command.GlobalOptions;
049: import org.netbeans.lib.cvsclient.command.add.AddCommand;
050: import org.netbeans.lib.cvsclient.connection.Connection;
051: import org.netbeans.lib.cvsclient.connection.PServerConnection;
052: import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
053:
054: /**
055: * Add command test suite.
056: *
057: * @author Petr Kuzel
058: */
059: public class AddTest extends TestCase {
060:
061: /**
062: * Tests cvswrappers compliance.
063: * <p>
064: * Uses fake PseudoCvsServer.
065: */
066: public void test36289() throws Exception {
067:
068: File tmpDir = TestKit.createTmpFolder("serverAbortTest");
069: String protocolLog = new File(tmpDir, "protocol")
070: .getAbsolutePath();
071: System.setProperty("cvsClientLog", protocolLog);
072: System.setProperty("Env-CVSWRAPPERS", "*.wrap -k 'b'");
073: System.out.println(protocolLog);
074:
075: InputStream in = getClass().getResourceAsStream(
076: "protocol/iz36289.in");
077: final PseudoCvsServer cvss = new PseudoCvsServer(in);
078: File requestsLog = File
079: .createTempFile("requests", null, tmpDir);
080: cvss.logRequests(new FileOutputStream(requestsLog));
081: new Thread(cvss).start();
082:
083: String cvsRoot = cvss.getCvsRoot();
084: CVSRoot root = CVSRoot.parse(cvsRoot);
085: final GlobalOptions gtx = new GlobalOptions();
086: gtx.setCVSRoot(cvsRoot);
087: Connection connection = new PServerConnection(root);
088: final Client client = new Client(connection,
089: new StandardAdminHandler());
090: client.setLocalPath(tmpDir.getAbsolutePath());
091:
092: // prepare working directory
093: File CVSdir = new File(tmpDir, "CVS");
094: CVSdir.mkdirs();
095:
096: OutputStream out;
097: File rootFile = new File(CVSdir, "Root");
098: out = new FileOutputStream(rootFile);
099: out.write(cvsRoot.getBytes("utf8"));
100: out.flush();
101: out.close();
102:
103: File repo = new File(CVSdir, "Repository");
104: out = new FileOutputStream(repo);
105: out.write("/cvs".getBytes("utf8"));
106: out.flush();
107: out.close();
108:
109: // execute the command
110:
111: AddCommand add = new AddCommand();
112: File wrap = new File(tmpDir, "test.wrap");
113: File txt = new File(tmpDir, "test.txt");
114: if (wrap.createNewFile() == false) {
115: throw new IOException("Can not create " + wrap);
116: }
117: if (txt.createNewFile() == false) {
118: throw new IOException("Can not create " + txt);
119: }
120: File[] files = new File[] { wrap, txt };
121: add.setFiles(files);
122:
123: client.executeCommand(add, gtx);
124: cvss.stop();
125:
126: // check test matching golden file (here critical line from issue #36289)
127:
128: InputStream actual = new FileInputStream(requestsLog);
129: LineNumberReader lineReader = new LineNumberReader(
130: new InputStreamReader(actual, "utf8"));
131: String line = lineReader.readLine();
132: StringBuffer sb = new StringBuffer();
133: while (line != null) {
134: sb.append(line + "\n");
135: line = lineReader.readLine();
136: }
137: String requests = sb.toString();
138: assertTrue(requests, requests.indexOf("Kopt -kb\n"
139: + "Is-modified test.wrap") != -1);
140:
141: TestKit.deleteRecursively(tmpDir);
142:
143: }
144:
145: }
|