KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > viewmodel > YardaTest


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.modules.viewmodel;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.AbstractAction JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.modules.viewmodel.TreeModelNode;
29 import org.netbeans.modules.viewmodel.TreeModelRoot;
30 import org.netbeans.modules.viewmodel.TreeTable;
31 import org.netbeans.spi.viewmodel.*;
32 import org.openide.nodes.Node;
33 import org.openide.util.RequestProcessor;
34
35
36
37 /**
38  * Tests the JPDABreakpointEvent.resume() functionality.
39  *
40  * @author Maros Sandor, Jan Jancura
41  */

42 public class YardaTest extends NbTestCase {
43
44
45     public YardaTest (String JavaDoc s) {
46         super (s);
47     }
48
49     public void testSubsequentRequest () throws Exception JavaDoc {
50         doColeasingSimulation (0);
51     }
52     public void testColeasingOfRequests () throws Exception JavaDoc {
53         doColeasingSimulation (1);
54     }
55     
56     private void doColeasingSimulation (int type) throws Exception JavaDoc {
57         ArrayList JavaDoc l = new ArrayList JavaDoc ();
58         CompoundModel1 cm1 = new CompoundModel1 ();
59         l.add (cm1);
60         TreeTable tt = (TreeTable) Models.createView
61             (Models.createCompoundModel (l));
62         Node n = tt.getExplorerManager ().
63             getRootContext ();
64         synchronized (cm1) {
65             n.getChildren ().getNodes ();
66             cm1.wait ();
67             assertEquals ("Model caled", 1, cm1.count);
68             cm1.fire ();
69             n.getChildren ().getNodes ();
70             
71             if (type == 1) {
72                 cm1.fire ();
73                 n.getChildren ().getNodes ();
74             }
75             
76             cm1.notifyAll ();
77         }
78         TreeModelNode.getRequestProcessor ().post (new Runnable JavaDoc () {
79             public void run () {}
80         }).waitFinished ();
81         //System.err.println("Child = "+n.getChildren().getNodes()[0]);
82
// TODO: Broken, there's a Please wait... node!
83
assertEquals ("Computation has finished in RP", 3, n.getChildren ().getNodes ().length);
84         assertEquals ("Model caled", 2, cm1.count);
85     }
86     
87     public final class CompoundModel1 extends BasicTest.CompoundModel {
88         
89         public int count = 0;
90
91
92         // init ....................................................................
93

94         /**
95          * Returns number of children for given node.
96          *
97          * @param node the parent node
98          * @throws UnknownTypeException if this TreeModel implementation is not
99          * able to resolve children for given node type
100          *
101          * @return true if node is leaf
102          */

103         public synchronized int getChildrenCount (Object JavaDoc node) throws UnknownTypeException {
104             count++;
105             notify ();
106             /*
107             try {
108                 wait (2000); // We must not wait here, otherwise we get a "Please wait..." node
109             } catch (InterruptedException ex) {
110                 ex.printStackTrace();
111             }
112              */

113             return super.getChildrenCount (node);
114         }
115     }
116 }
117
Popular Tags