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-2007 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.uml.core.eventframework;
043:
044: import org.netbeans.modules.uml.core.AbstractUMLTestCase;
045: import org.netbeans.modules.uml.core.eventframework.EventBlocker;
046: import org.netbeans.modules.uml.core.eventframework.EventContext;
047: import org.netbeans.modules.uml.core.eventframework.EventDispatchController;
048: import org.netbeans.modules.uml.core.eventframework.EventDispatcher;
049: import org.netbeans.modules.uml.core.eventframework.EventPayload;
050:
051: public class StopBlockingProductEventsTestCase extends
052: AbstractUMLTestCase {
053:
054: EventContext context;
055: EventPayload payload;
056: EventDispatcher eventDispather;
057: EventDispatchController eventDispContlr;
058: IEventDispatchController prodDispCntrlr;
059:
060: protected void setUp() {
061: // Initializes the EventDispatcher, EventContext, EventPayload
062: // and EventDispatchController
063: eventDispather = new EventBlockerTestDispatcher();
064: context = new EventContext();
065: payload = new EventPayload();
066: // Storing the event dispatcher controller object already associated with this product
067: prodDispCntrlr = product.getEventDispatchController();
068: eventDispContlr = new EventDispatchController();
069: }
070:
071: public void testStopBlockingProductEvents() {
072: // Add the EventDispatcher to EventDispatchController
073: eventDispContlr.addDispatcher("UtilDispatcher", eventDispather);
074:
075: // Set the EventDispatcher to the product
076: product.setEventDispatchController(eventDispContlr);
077:
078: // Get the EventDispatcher and fire the event
079: product.getEventDispatchController().retrieveDispatcher(
080: "UtilDispatcher").fireEventContextPopped(context,
081: payload);
082:
083: // Make sure that the event is fired correctly
084: assertTrue(EventBlockerTestDispatcher.isCalled);
085: EventBlockerTestDispatcher.isCalled = false;
086:
087: // Block all the events
088: EventBlocker.startBlocking();
089:
090: // Get the EventDispatcher and try to fire the event
091: // Test that the event is not fired
092: product.getEventDispatchController().retrieveDispatcher(
093: "UtilDispatcher").fireEventContextPopped(context,
094: payload);
095: assertFalse(EventBlockerTestDispatcher.isCalled);
096:
097: // Stop blocking all the events
098: EventBlocker.stopBlocking(false);
099:
100: // Make sure that the event is fired correctly
101: product.getEventDispatchController().retrieveDispatcher(
102: "UtilDispatcher").fireEventContextPopped(context,
103: payload);
104: assertTrue(EventBlockerTestDispatcher.isCalled);
105: }
106:
107: public void tearDown() {
108: // Sets back the original EventDispatchController to the product
109: product.setEventDispatchController(prodDispCntrlr);
110: }
111:
112: }
|