001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.viewmodel;
043:
044: import java.awt.event.ActionEvent;
045: import java.util.ArrayList;
046: import java.util.List;
047: import javax.swing.AbstractAction;
048: import javax.swing.Action;
049: import org.netbeans.junit.NbTestCase;
050: import org.netbeans.modules.viewmodel.TreeModelNode;
051: import org.netbeans.modules.viewmodel.TreeModelRoot;
052: import org.netbeans.modules.viewmodel.TreeTable;
053: import org.netbeans.spi.viewmodel.*;
054: import org.openide.nodes.Node;
055: import org.openide.util.RequestProcessor;
056:
057: /**
058: * Tests the JPDABreakpointEvent.resume() functionality.
059: *
060: * @author Maros Sandor, Jan Jancura
061: */
062: public class YardaTest extends NbTestCase {
063:
064: public YardaTest(String s) {
065: super (s);
066: }
067:
068: public void testSubsequentRequest() throws Exception {
069: doColeasingSimulation(0);
070: }
071:
072: public void testColeasingOfRequests() throws Exception {
073: doColeasingSimulation(1);
074: }
075:
076: private void doColeasingSimulation(int type) throws Exception {
077: ArrayList l = new ArrayList();
078: CompoundModel1 cm1 = new CompoundModel1();
079: l.add(cm1);
080: TreeTable tt = (TreeTable) Models.createView(Models
081: .createCompoundModel(l));
082: Node n = tt.getExplorerManager().getRootContext();
083: synchronized (cm1) {
084: n.getChildren().getNodes();
085: cm1.wait();
086: assertEquals("Model caled", 1, cm1.count);
087: cm1.fire();
088: n.getChildren().getNodes();
089:
090: if (type == 1) {
091: cm1.fire();
092: n.getChildren().getNodes();
093: }
094:
095: cm1.notifyAll();
096: }
097: TreeModelNode.getRequestProcessor().post(new Runnable() {
098: public void run() {
099: }
100: }).waitFinished();
101: //System.err.println("Child = "+n.getChildren().getNodes()[0]);
102: // TODO: Broken, there's a Please wait... node!
103: assertEquals("Computation has finished in RP", 3, n
104: .getChildren().getNodes().length);
105: assertEquals("Model caled", 2, cm1.count);
106: }
107:
108: public final class CompoundModel1 extends BasicTest.CompoundModel {
109:
110: public int count = 0;
111:
112: // init ....................................................................
113:
114: /**
115: * Returns number of children for given node.
116: *
117: * @param node the parent node
118: * @throws UnknownTypeException if this TreeModel implementation is not
119: * able to resolve children for given node type
120: *
121: * @return true if node is leaf
122: */
123: public synchronized int getChildrenCount(Object node)
124: throws UnknownTypeException {
125: count++;
126: notify();
127: /*
128: try {
129: wait (2000); // We must not wait here, otherwise we get a "Please wait..." node
130: } catch (InterruptedException ex) {
131: ex.printStackTrace();
132: }
133: */
134: return super.getChildrenCount(node);
135: }
136: }
137: }
|