mylyn-suite/depends-on-bugzilla/test/unit/src/org/apidesign/netbinox/test/mylyn/InvokeAllActionsTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Wed Dec 30 14:38:40 2009 +0100
changeset 33 bf08331873fe
parent 25 df15d54ca5fe
child 35 9c83a6ac50fd
permissions -rw-r--r--
Disabling event queue timeout checks during the validation test
     1 /*
     2  *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3  *
     4  *  This program is free software; you can redistribute it and/or
     5  *  modify it under the terms of the GNU General Public License
     6  *  as published by the Free Software Foundation; version 2
     7  *  of the License.
     8  *
     9  *  This program is distributed in the hope that it will be useful,
    10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  *  GNU General Public License for more details.
    13  *
    14  *  You should have received a copy of the GNU General Public License
    15  *  along with this program; if not, write to the Free Software
    16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    17  */
    18 
    19 package org.apidesign.netbinox.test.mylyn;
    20 
    21 import java.awt.EventQueue;
    22 import java.awt.event.ActionEvent;
    23 import java.util.logging.Level;
    24 import javax.swing.Action;
    25 import junit.framework.Test;
    26 import org.netbeans.junit.NbModuleSuite;
    27 import org.netbeans.junit.NbTestCase;
    28 import org.openide.util.Lookup;
    29 import org.openide.util.lookup.Lookups;
    30 
    31 /**
    32  *
    33  * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    34  */
    35 public class InvokeAllActionsTest extends NbTestCase {
    36     public InvokeAllActionsTest(String name) {
    37         super(name);
    38     }
    39 
    40     public static Test suite() {
    41         System.setProperty("org.netbeans.core.TimableEventQueue.level", "OFF");
    42         return NbModuleSuite.create(
    43             NbModuleSuite.emptyConfiguration().
    44             addTest(InvokeAllActionsTest.class).
    45             clusters("cluster.*|eclipse.*").
    46             enableModules("org.apidesign.*").
    47             enableClasspathModules(false).
    48 //            honorAutoloadEager(true).
    49             failOnException(Level.INFO).
    50             failOnMessage(Level.WARNING)
    51         );
    52     }
    53 
    54     public void testInvokeAllActionsInFileMenu() throws Exception {
    55         Lookup menuFile = Lookups.forPath("Menu/File");
    56         int cnt = 0;
    57         for (final Action a : menuFile.lookupAll(Action.class)) {
    58             if (!Boolean.TRUE.equals(getValue(a, "org.apidesign.netbinox.test.mylyn"))) {
    59                 continue;
    60             }
    61 
    62             EventQueue.invokeLater(new Runnable() {
    63                 public void run() {
    64                     a.actionPerformed(new ActionEvent(this, 0, ""));
    65                 }
    66             });
    67             Thread.sleep(1000);
    68 
    69             cnt++;
    70         }
    71         assertEquals("There are two actions provided by this sample", 2, cnt);
    72     }
    73 
    74     private Object getValue(final Action a, final String key) throws Exception {
    75         class C implements Runnable {
    76             Object ret;
    77 
    78             public void run() {
    79                 ret = a.getValue(key);
    80             }
    81         }
    82         C c = new C();
    83 
    84         EventQueue.invokeAndWait(c);
    85         return c.ret;
    86     }
    87 }