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.spi.palette;
043:
044: import java.io.FileNotFoundException;
045: import junit.framework.TestCase;
046: import org.openide.filesystems.FileObject;
047: import org.openide.filesystems.FileSystem;
048: import org.openide.filesystems.Repository;
049: import org.openide.nodes.Node;
050:
051: /**
052: *
053: * @author Stanislav Aubrecht
054: */
055: public class PaletteFactoryTest extends TestCase {
056:
057: private FileObject paletteRootFolder;
058: private static final String PALETTE_ROOT_FOLDER_NAME = "test_palette_folder";
059:
060: public PaletteFactoryTest(String testName) {
061: super (testName);
062: }
063:
064: protected void setUp() throws Exception {
065: FileSystem fs = Repository.getDefault().getDefaultFileSystem();
066: paletteRootFolder = fs.findResource(PALETTE_ROOT_FOLDER_NAME);
067: if (null != paletteRootFolder)
068: paletteRootFolder.delete();
069: paletteRootFolder = fs.getRoot().createFolder(
070: PALETTE_ROOT_FOLDER_NAME);
071: }
072:
073: protected void tearDown() throws Exception {
074: FileSystem fs = Repository.getDefault().getDefaultFileSystem();
075: paletteRootFolder = fs.findResource(PALETTE_ROOT_FOLDER_NAME);
076: if (null != paletteRootFolder)
077: paletteRootFolder.delete();
078: }
079:
080: /**
081: * Test of createPalette method, of class org.netbeans.modules.palette.api.PaletteFactory.
082: */
083: public void testCreatePaletteNulls() throws Exception {
084: try {
085: PaletteFactory.createPalette((String) null,
086: new DummyActions());
087: fail("Palette factory accepts null as folder name.");
088: } catch (IllegalArgumentException e) {
089: //that's what we want
090: } catch (Throwable t) {
091: fail("Invalid exception thrown.");
092: }
093:
094: try {
095: PaletteFactory.createPalette((Node) null,
096: new DummyActions());
097: fail("Palette factory accepts null as root Node.");
098: } catch (IllegalArgumentException e) {
099: //that's what we want
100: } catch (Throwable t) {
101: fail("Invalid exception thrown.");
102: }
103:
104: try {
105: PaletteFactory.createPalette(DummyPalette
106: .createPaletteRoot(), null);
107: fail("Palette factory accepts null for palette actions.");
108: } catch (IllegalArgumentException e) {
109: //that's what we want
110: } catch (Throwable t) {
111: fail("Invalid exception thrown.");
112: }
113: }
114:
115: public void testCreatePaletteFolder() throws Exception {
116: try {
117: PaletteFactory.createPalette("non_existent_folder",
118: new DummyActions());
119: fail("Palette factory accepts non-existent folders.");
120: } catch (FileNotFoundException fnfE) {
121: //that's what we want
122: } catch (Throwable e) {
123: fail("Invalid exception thrown.");
124: }
125:
126: PaletteActions actions = new DummyActions();
127: PaletteController controller = PaletteFactory.createPalette(
128: PALETTE_ROOT_FOLDER_NAME, actions);
129: Node rootNode = (Node) controller.getRoot().lookup(Node.class);
130: assertNotNull(rootNode);
131: assertEquals(actions, controller.getRoot().lookup(
132: PaletteActions.class));
133: }
134:
135: public void testCreatePaletteNodes() throws Exception {
136: PaletteActions actions = new DummyActions();
137: Node rootNode = DummyPalette.createPaletteRoot();
138: PaletteController controller = PaletteFactory.createPalette(
139: rootNode, actions);
140: assertEquals(rootNode.getName(), controller.getRoot().lookup(
141: Node.class).getName());
142: assertEquals(actions, controller.getRoot().lookup(
143: PaletteActions.class));
144: }
145:
146: }
|