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.core;
043:
044: import java.io.*;
045: import java.util.*;
046: import org.openide.filesystems.*;
047: import org.openide.actions.*;
048: import org.openide.loaders.DataLoader;
049: import org.openide.loaders.MultiDataObject;
050: import org.openide.loaders.UniFileLoader;
051: import org.openide.util.actions.SystemAction;
052:
053: /**
054: *
055: * @author Jaroslav Tulach
056: */
057: public class LoaderPoolNodeTest extends org.netbeans.junit.NbTestCase {
058: private OldStyleLoader oldL;
059: private NewStyleLoader newL;
060:
061: public LoaderPoolNodeTest(String testName) {
062: super (testName);
063: }
064:
065: protected void setUp() throws java.lang.Exception {
066: LoaderPoolNode.installationFinished();
067:
068: oldL = DataLoader.getLoader(OldStyleLoader.class);
069: newL = DataLoader.getLoader(NewStyleLoader.class);
070: LoaderPoolNode.doAdd(oldL, null);
071: LoaderPoolNode.doAdd(newL, null);
072: LoaderPoolNode.waitFinished();
073: }
074:
075: protected void tearDown() throws java.lang.Exception {
076: LoaderPoolNode.remove(oldL);
077: LoaderPoolNode.remove(newL);
078: }
079:
080: public void testOldLoaderThatChangesActionsBecomesModified()
081: throws Exception {
082: assertFalse("Not modified at begining", LoaderPoolNode
083: .isModified(oldL));
084: Object actions = oldL.getActions();
085: assertNotNull("Some actions there", actions);
086: assertTrue("Default actions called", oldL.defaultActionsCalled);
087: assertFalse("Still not modified", LoaderPoolNode
088: .isModified(oldL));
089:
090: List<SystemAction> list = new ArrayList<SystemAction>();
091: list.add(SystemAction.get(OpenAction.class));
092: list.add(SystemAction.get(NewAction.class));
093: oldL.setActions(list.toArray(new SystemAction[0]));
094:
095: assertTrue("Now it is modified", LoaderPoolNode
096: .isModified(oldL));
097: List l = Arrays.asList(oldL.getActions());
098: assertEquals("Actions are the same", list, l);
099: }
100:
101: public void testNewLoaderThatChangesActionsBecomesModified()
102: throws Exception {
103: assertFalse("Not modified at begining", LoaderPoolNode
104: .isModified(newL));
105: Object actions = newL.getActions();
106: assertNotNull("Some actions there", actions);
107: assertTrue("Default actions called", newL.defaultActionsCalled);
108: assertFalse("Still not modified", LoaderPoolNode
109: .isModified(newL));
110:
111: List<SystemAction> list = new ArrayList<SystemAction>();
112: list.add(SystemAction.get(OpenAction.class));
113: list.add(SystemAction.get(NewAction.class));
114: newL.setActions(list.toArray(new SystemAction[0]));
115:
116: assertFalse("Even if we changed actions, it is not modified",
117: LoaderPoolNode.isModified(newL));
118: List l = Arrays.asList(newL.getActions());
119: assertEquals("But actions are changed", list, l);
120: }
121:
122: public static class OldStyleLoader extends UniFileLoader {
123: boolean defaultActionsCalled;
124:
125: public OldStyleLoader() {
126: super (MultiDataObject.class.getName());
127: }
128:
129: protected MultiDataObject createMultiObject(FileObject fo)
130: throws IOException {
131: throw new IOException("Not implemented");
132: }
133:
134: protected SystemAction[] defaultActions() {
135: defaultActionsCalled = true;
136: SystemAction[] retValue;
137:
138: retValue = super .defaultActions();
139: return retValue;
140: }
141:
142: }
143:
144: public static final class NewStyleLoader extends OldStyleLoader {
145: protected String actionsContext() {
146: return "Loaders/IamTheNewBeggining";
147: }
148: }
149: }
|