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.api.debugger;
043:
044: import org.netbeans.api.debugger.test.TestDebuggerManagerListener;
045: import java.beans.PropertyChangeEvent;
046: import java.util.List;
047:
048: /**
049: * Tests DebuggerManager's Watches management.
050: *
051: * @author Maros Sandor
052: */
053: public class WatchesTest extends DebuggerApiTestBase {
054:
055: public WatchesTest(String s) {
056: super (s);
057: }
058:
059: public void testWatches() throws Exception {
060: DebuggerManager dm = DebuggerManager.getDebuggerManager();
061: TestDebuggerManagerListener dml = new TestDebuggerManagerListener();
062:
063: dm.addDebuggerListener(dml);
064:
065: initWatches(dm, dml);
066: Watch w1 = addWatch(dm, dml);
067: Watch w2 = addWatch(dm, dml);
068: Watch w3 = addWatch(dm, dml);
069: removeWatch(dm, w2, dml);
070: removeWatch(dm, w3, dml);
071: Watch w4 = addWatch(dm, dml);
072: removeWatch(dm, w1, dml);
073: Watch w5 = addWatch(dm, dml);
074: removeWatch(dm, w5, dml);
075: removeWatch(dm, w4, dml);
076:
077: dm.removeDebuggerListener(dml);
078: }
079:
080: private void initWatches(DebuggerManager dm,
081: TestDebuggerManagerListener dml) {
082: dm.getWatches(); // trigger the "watchesInit" property change
083: TestDebuggerManagerListener.Event event;
084: List events = dml.getEvents();
085: assertEquals("Wrong PCS", 1, events.size());
086: event = (TestDebuggerManagerListener.Event) events.get(0);
087: assertEquals("Wrong PCS", "propertyChange", event.getName());
088: PropertyChangeEvent pce = (PropertyChangeEvent) event
089: .getParam();
090: assertEquals("Wrong PCE name", "watchesInit", pce
091: .getPropertyName());
092: }
093:
094: private void removeWatch(DebuggerManager dm, Watch w,
095: TestDebuggerManagerListener dml) {
096: List events;
097: TestDebuggerManagerListener.Event event;
098: Watch[] watches = dm.getWatches();
099:
100: dm.removeWatch(w);
101: events = dml.getEvents();
102: assertEquals("Wrong PCS", 2, events.size());
103: assertTrue("Wrong PCS", events
104: .remove(new TestDebuggerManagerListener.Event(
105: "watchRemoved", w)));
106: event = (TestDebuggerManagerListener.Event) events.get(0);
107: assertEquals("Wrong PCS", "propertyChange", event.getName());
108: PropertyChangeEvent pce = (PropertyChangeEvent) event
109: .getParam();
110: assertEquals("Wrong PCE name", "watches", pce.getPropertyName());
111: Watch[] newWatches = dm.getWatches();
112: for (int i = 0; i < newWatches.length; i++) {
113: assertNotSame("Watch was not removed", newWatches[i], w);
114: }
115: assertEquals("Wrong number of installed watches",
116: watches.length - 1, newWatches.length);
117: }
118:
119: private Watch addWatch(DebuggerManager dm,
120: TestDebuggerManagerListener dml) {
121: List events;
122: TestDebuggerManagerListener.Event event;
123:
124: int watchesSize = dm.getWatches().length;
125: Watch newWatch = dm.createWatch("watch");
126: events = dml.getEvents();
127: assertEquals("Wrong PCS", 2, events.size());
128: assertTrue("Wrong PCS", events
129: .remove(new TestDebuggerManagerListener.Event(
130: "watchAdded", newWatch)));
131: event = (TestDebuggerManagerListener.Event) events.get(0);
132: assertEquals("Wrong PCS", "propertyChange", event.getName());
133: PropertyChangeEvent pce = (PropertyChangeEvent) event
134: .getParam();
135: assertEquals("Wrong PCE name", "watches", pce.getPropertyName());
136: Watch[] watches = dm.getWatches();
137: assertEquals("Wrong number of installed watches",
138: watchesSize + 1, watches.length);
139: return newWatch;
140: }
141:
142: }
|