KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > debugger > DebuggerActionsTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.debugger;
21
22 import org.netbeans.api.debugger.test.TestDICookie;
23 import org.netbeans.api.debugger.test.TestActionsManagerListener;
24 import org.netbeans.api.debugger.test.TestLazyActionsManagerListener;
25
26 import java.util.*;
27
28 /**
29  * Tests invocations of debugger actions.
30  *
31  * @author Maros Sandor
32  */

33 public class DebuggerActionsTest extends DebuggerApiTestBase {
34
35     public DebuggerActionsTest(String JavaDoc s) {
36         super(s);
37     }
38
39     public void testLookup() throws Exception JavaDoc {
40
41         DebuggerManager dm = DebuggerManager.getDebuggerManager();
42         Map args = new HashMap();
43         TestDICookie tdi = TestDICookie.create(args);
44
45         Object JavaDoc [] services = new Object JavaDoc[] { tdi, this };
46         DebuggerInfo di = DebuggerInfo.create(TestDICookie.ID, services);
47
48         DebuggerEngine engines [] = dm.startDebugging(di);
49         assertEquals("Wrong number of engines started", 1, engines.length);
50         DebuggerEngine debugger = engines[0];
51
52         ActionsManager am = debugger.getActionsManager();
53         TestActionsManagerListener tam = new TestActionsManagerListener();
54         am.addActionsManagerListener(tam);
55
56         TestLazyActionsManagerListener laml = (TestLazyActionsManagerListener) debugger.lookupFirst(null, LazyActionsManagerListener.class);
57         assertNotNull("Lazy actions manager listener not loaded", laml);
58
59         am.doAction(ActionsManager.ACTION_CONTINUE);
60         am.doAction(ActionsManager.ACTION_FIX);
61         am.doAction(ActionsManager.ACTION_MAKE_CALLEE_CURRENT);
62         am.doAction(ActionsManager.ACTION_MAKE_CALLER_CURRENT);
63         am.doAction(ActionsManager.ACTION_PAUSE);
64         am.doAction(ActionsManager.ACTION_POP_TOPMOST_CALL);
65         am.doAction(ActionsManager.ACTION_RESTART);
66         am.doAction(ActionsManager.ACTION_RUN_INTO_METHOD);
67         am.doAction(ActionsManager.ACTION_RUN_TO_CURSOR);
68         am.doAction(ActionsManager.ACTION_STEP_INTO);
69         am.doAction(ActionsManager.ACTION_STEP_OUT);
70         am.doAction(ActionsManager.ACTION_STEP_OVER);
71         am.doAction(ActionsManager.ACTION_TOGGLE_BREAKPOINT);
72         dm.getCurrentSession().kill();
73
74         am.removeActionsManagerListener(tam);
75
76         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_START));
77         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_CONTINUE));
78         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_FIX));
79         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_MAKE_CALLEE_CURRENT));
80         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_MAKE_CALLER_CURRENT));
81         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_PAUSE));
82         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_POP_TOPMOST_CALL));
83         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_RESTART));
84         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_RUN_INTO_METHOD));
85         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_RUN_TO_CURSOR));
86         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_STEP_INTO));
87         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_STEP_OUT));
88         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_STEP_OVER));
89         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_TOGGLE_BREAKPOINT));
90         assertTrue("Action was not performed", tdi.hasInfo(ActionsManager.ACTION_KILL));
91
92         testReceivedEvents(tam.getPerformedActions(), false);
93         testReceivedEvents(laml.getPerformedActions(), true);
94     }
95
96     private void testReceivedEvents(List eventActions, boolean expectStartAction) {
97         if (expectStartAction) assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_START));
98         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_CONTINUE));
99         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_FIX));
100         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_MAKE_CALLEE_CURRENT));
101         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_MAKE_CALLER_CURRENT));
102         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_PAUSE));
103         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_POP_TOPMOST_CALL));
104         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_RESTART));
105         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_RUN_INTO_METHOD));
106         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_RUN_TO_CURSOR));
107         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_STEP_INTO));
108         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_STEP_OUT));
109         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_STEP_OVER));
110         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_TOGGLE_BREAKPOINT));
111         assertTrue("ActionListener was not notified", eventActions.remove(ActionsManager.ACTION_KILL));
112         assertEquals("ActionListener notification failed", eventActions.size(), 0);
113     }
114 }
115
Popular Tags