KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > LoaderPoolNodeTest


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.core;
21
22 import java.io.*;
23 import java.util.*;
24 import org.openide.filesystems.*;
25 import org.openide.actions.*;
26 import org.openide.util.actions.SystemAction;
27
28
29 /**
30  *
31  * @author Jaroslav Tulach
32  */

33 public class LoaderPoolNodeTest extends org.netbeans.junit.NbTestCase {
34     private OldStyleLoader oldL;
35     private NewStyleLoader newL;
36
37     public LoaderPoolNodeTest (String JavaDoc testName) {
38         super (testName);
39     }
40
41     protected void setUp () throws java.lang.Exception JavaDoc {
42         LoaderPoolNode.installationFinished();
43
44         oldL = (OldStyleLoader)OldStyleLoader.getLoader (OldStyleLoader.class);
45         newL = (NewStyleLoader)NewStyleLoader.getLoader (NewStyleLoader.class);
46         LoaderPoolNode.doAdd (oldL, null);
47         LoaderPoolNode.doAdd (newL, null);
48         LoaderPoolNode.waitFinished();
49     }
50
51     protected void tearDown () throws java.lang.Exception JavaDoc {
52         LoaderPoolNode.remove (oldL);
53         LoaderPoolNode.remove (newL);
54     }
55
56     public void testOldLoaderThatChangesActionsBecomesModified () throws Exception JavaDoc {
57         assertFalse ("Not modified at begining", LoaderPoolNode.isModified (oldL));
58         Object JavaDoc actions = oldL.getActions ();
59         assertNotNull ("Some actions there", actions);
60         assertTrue ("Default actions called", oldL.defaultActionsCalled);
61         assertFalse ("Still not modified", LoaderPoolNode.isModified (oldL));
62         
63         ArrayList list = new ArrayList ();
64         list.add (OpenAction.get (OpenAction.class));
65         list.add (NewAction.get (NewAction.class));
66         oldL.setActions ((SystemAction[])list.toArray (new SystemAction[0]));
67         
68         assertTrue ("Now it is modified", LoaderPoolNode.isModified (oldL));
69         List l = Arrays.asList (oldL.getActions ());
70         assertEquals ("Actions are the same", list, l);
71     }
72     
73     public void testNewLoaderThatChangesActionsBecomesModified () throws Exception JavaDoc {
74         assertFalse ("Not modified at begining", LoaderPoolNode.isModified (newL));
75         Object JavaDoc actions = newL.getActions ();
76         assertNotNull ("Some actions there", actions);
77         assertTrue ("Default actions called", newL.defaultActionsCalled);
78         assertFalse ("Still not modified", LoaderPoolNode.isModified (newL));
79         
80         ArrayList list = new ArrayList ();
81         list.add (OpenAction.get (OpenAction.class));
82         list.add (NewAction.get (NewAction.class));
83         newL.setActions ((SystemAction[])list.toArray (new SystemAction[0]));
84         
85         assertFalse ("Even if we changed actions, it is not modified", LoaderPoolNode.isModified (newL));
86         List l = Arrays.asList (newL.getActions ());
87         assertEquals ("But actions are changed", list, l);
88     }
89     
90     public static class OldStyleLoader extends org.openide.loaders.UniFileLoader {
91         boolean defaultActionsCalled;
92         
93         public OldStyleLoader () {
94             super (org.openide.loaders.MultiDataObject.class);
95         }
96         
97         protected org.openide.loaders.MultiDataObject createMultiObject (FileObject fo) throws IOException {
98             throw new IOException ("Not implemented");
99         }
100
101         protected SystemAction[] defaultActions () {
102             defaultActionsCalled = true;
103             SystemAction[] retValue;
104             
105             retValue = super.defaultActions();
106             return retValue;
107         }
108         
109         
110     }
111     
112     public static final class NewStyleLoader extends OldStyleLoader {
113         protected String JavaDoc actionsContext () {
114             return "Loaders/IamTheNewBeggining";
115         }
116     }
117 }
118
Popular Tags