KickJava   Java API By Example, From Geeks To Geeks.

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


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.status.StatusCommand;
29 import org.netbeans.lib.cvsclient.connection.Connection;
30 import org.netbeans.lib.cvsclient.connection.PServerConnection;
31 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
32
33 /**
34  * Tescase covering handling network unreliability and
35  * known server protocol errors (library contains workarounds).
36  *
37  * @author Petr Kuzel
38  */

39 public class ErrorHandlingTest extends TestCase {
40
41     /**
42      * Test how client workarounds [server abort] signals.
43      * <p>
44      * Uses fake PseudoCvsServer.
45      */

46     public void test56552() throws Exception JavaDoc {
47
48         File JavaDoc tmpDir = TestKit.createTmpFolder("serverAbortTest");
49         String JavaDoc protocolLog = new File JavaDoc(tmpDir, "protocol").getAbsolutePath();
50         System.setProperty("cvsClientLog", protocolLog);
51         System.out.println(protocolLog);
52
53         InputStream JavaDoc in = getClass().getResourceAsStream("protocol/iz56552.in");
54         final PseudoCvsServer cvss = new PseudoCvsServer(in);
55         new Thread JavaDoc(cvss).start();
56
57         String JavaDoc cvsRoot = cvss.getCvsRoot();
58         CVSRoot root = CVSRoot.parse(cvsRoot);
59         final GlobalOptions gtx = new GlobalOptions();
60         gtx.setCVSRoot(cvsRoot);
61         Connection connection = new PServerConnection(root);
62         final Client client = new Client(connection, new StandardAdminHandler());
63         client.setLocalPath(tmpDir.getAbsolutePath());
64
65         final StatusCommand status = new StatusCommand();
66         File JavaDoc[] files = new File JavaDoc[] {new File JavaDoc(tmpDir, "placeholder")};
67         status.setFiles(files);
68
69         final Exception JavaDoc testException[] = new Exception JavaDoc[1];
70         final boolean completedFlag[] = new boolean[] {false};
71         Runnable JavaDoc run = new Runnable JavaDoc() {
72             public void run() {
73                 try {
74                     try {
75                         client.executeCommand(status, gtx);
76                         synchronized(completedFlag) {
77                             completedFlag[0] = true;
78                             completedFlag.notifyAll();
79                         }
80                     } finally {
81                         cvss.stop();
82                     }
83                 } catch (Exception JavaDoc ex) {
84                     testException[0] = ex;
85                 }
86             }
87         };
88
89         // test mus finish in reasonable time (compare to blocking forever that'd be a bug)
90

91         Thread JavaDoc t = new Thread JavaDoc(run);
92         t.start();
93         synchronized(completedFlag) {
94             if (completedFlag[0] == false) {
95                 completedFlag.wait(1000); // 'INFINITE' TIMEOUT
96
}
97         }
98         t.interrupt();
99         if (testException[0] != null) {
100             throw testException[0];
101         }
102         assertTrue(completedFlag[0]);
103
104         TestKit.deleteRecursively(tmpDir);
105     }
106
107
108 }
109
Popular Tags