1 19 20 package org.netbeans.modules.viewmodel; 21 22 import java.awt.event.ActionEvent ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.Action ; 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 42 public class YardaTest extends NbTestCase { 43 44 45 public YardaTest (String s) { 46 super (s); 47 } 48 49 public void testSubsequentRequest () throws Exception { 50 doColeasingSimulation (0); 51 } 52 public void testColeasingOfRequests () throws Exception { 53 doColeasingSimulation (1); 54 } 55 56 private void doColeasingSimulation (int type) throws Exception { 57 ArrayList l = new ArrayList (); 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 () { 79 public void run () {} 80 }).waitFinished (); 81 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 94 103 public synchronized int getChildrenCount (Object node) throws UnknownTypeException { 104 count++; 105 notify (); 106 113 return super.getChildrenCount (node); 114 } 115 } 116 } 117 | Popular Tags |