KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > execution > ExecutionEngineHid


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.openide.execution;
21
22 import java.security.AllPermission JavaDoc;
23 import java.security.CodeSource JavaDoc;
24 import java.security.PermissionCollection JavaDoc;
25 import java.security.Permissions JavaDoc;
26 import junit.framework.TestCase;
27 import org.openide.execution.ExecutionEngine;
28 import org.openide.execution.ExecutorTask;
29 import org.openide.util.Lookup;
30 import org.openide.windows.IOProvider;
31 import org.openide.windows.InputOutput;
32
33 /** A piece of the test compatibility suite for the execution APIs.
34  *
35  * @author Jaroslav Tulach
36  */

37 public class ExecutionEngineHid extends TestCase {
38     
39     public ExecutionEngineHid(String JavaDoc testName) {
40         super(testName);
41     }
42     
43     public void testGetDefault() {
44         ExecutionEngine result = ExecutionEngine.getDefault();
45         assertNotNull(result);
46     }
47     
48     public void testExecuteIsNonBlocking() throws Exception JavaDoc {
49         class Block implements Runnable JavaDoc {
50             public boolean here;
51             
52             
53             public synchronized void run() {
54                 here = true;
55                 notifyAll();
56                 try {
57                     wait();
58                 } catch (InterruptedException JavaDoc ex) {
59                     ex.printStackTrace();
60                 }
61             }
62             
63             public synchronized void waitForRun() throws InterruptedException JavaDoc {
64                 while(!here) {
65                     wait();
66                 }
67                 notifyAll();
68             }
69         }
70         Block block = new Block();
71         
72         
73         ExecutionEngine instance = ExecutionEngine.getDefault();
74         ExecutorTask result = instance.execute("My task", block, InputOutput.NULL);
75         
76         assertFalse("Of course it is not finished, as it is blocked", result.isFinished());
77         block.waitForRun();
78         
79         int r = result.result();
80         assertEquals("Default result is 0", 0, r);
81     }
82     
83 }
84
Popular Tags