KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
25 import java.io.InputStream JavaDoc;
26
27 import org.netbeans.lib.cvsclient.command.GlobalOptions;
28 import org.netbeans.lib.cvsclient.command.CommandException;
29 import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
30 import org.netbeans.lib.cvsclient.connection.Connection;
31 import org.netbeans.lib.cvsclient.connection.PServerConnection;
32 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
33
34 /**
35  * Checkout test suite. Works at C/S protocol wire level.
36  *
37  * @author Petr Kuzel
38  */

39 public class CheckoutTest extends TestCase {
40
41     /**
42      * Test how client handles unxpected IOException caused
43      * by line drop from checkout command.
44      * <p>
45      * Uses fake PseudoCvsServer.
46      */

47     public void test56552_21126() throws Exception JavaDoc {
48
49         final File JavaDoc tmpDir = TestKit.createTmpFolder("checkoutDropTest");
50         String JavaDoc protocolLog = new File JavaDoc(tmpDir, "protocol").getAbsolutePath();
51         System.setProperty("cvsClientLog", protocolLog);
52         System.out.println(protocolLog);
53
54         final InputStream JavaDoc in = getClass().getResourceAsStream("protocol/iz56552_21126.in");
55         if (in == null) {
56             System.err.println(getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm());
57             in.markSupported();
58         }
59
60         // command exception expected
61
// infinite *1s) blocking is a failure
62
// other exception is test failre
63

64         final Exception JavaDoc expectedException[] = new Exception JavaDoc [1];
65         final Exception JavaDoc testException[] = new Exception JavaDoc[1];
66         Runnable JavaDoc run = new Runnable JavaDoc() {
67             public void run() {
68                 try {
69                     PseudoCvsServer cvss = new PseudoCvsServer(in);
70                     try {
71                         cvss.simulateNetworkFailure(1000, -1);
72                         new Thread JavaDoc(cvss).start();
73
74                         String JavaDoc cvsRoot = cvss.getCvsRoot();
75                         CVSRoot root = CVSRoot.parse(cvsRoot);
76                         GlobalOptions gtx = new GlobalOptions();
77                         gtx.setCVSRoot(cvsRoot);
78                         Connection connection = new PServerConnection(root);
79                         Client client = new Client(connection, new StandardAdminHandler());
80                         client.setLocalPath(tmpDir.getAbsolutePath());
81
82                         CheckoutCommand checkout = new CheckoutCommand();
83                         checkout.setModule("a11y");
84
85                         client.executeCommand(checkout, gtx);
86                         expectedException.notify();
87                     } catch (CommandException ex) {
88                         // expected expected, infinite wait would be a bug
89
synchronized(expectedException) {
90                             expectedException[0] = ex;
91                             expectedException.notify();
92                         }
93                     } finally {
94                         cvss.stop();;
95                     }
96                 } catch (Exception JavaDoc ex) {
97                     testException[0] = ex;
98                 }
99             }
100         };
101
102         Thread JavaDoc t = new Thread JavaDoc(run);
103         t.start();
104         synchronized(expectedException) {
105             if (expectedException[0] == null) {
106                 expectedException.wait(1000); // 'INFINITE' TIMEOUT
107
}
108         }
109         t.interrupt();
110         if (testException[0] != null) {
111             throw testException[0];
112         }
113         assertTrue(expectedException[0] != null);
114         TestKit.deleteRecursively(tmpDir);
115
116     }
117
118
119
120 }
121
Popular Tags