KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > palette > PaletteFactoryTest


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.spi.palette;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import junit.framework.TestCase;
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileSystem;
26 import org.openide.filesystems.Repository;
27 import org.openide.nodes.Node;
28
29 /**
30  *
31  * @author Stanislav Aubrecht
32  */

33 public class PaletteFactoryTest extends TestCase {
34
35     private FileObject paletteRootFolder;
36     private static final String JavaDoc PALETTE_ROOT_FOLDER_NAME = "test_palette_folder";
37
38     public PaletteFactoryTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     protected void setUp() throws Exception JavaDoc {
43         FileSystem fs = Repository.getDefault().getDefaultFileSystem();
44         paletteRootFolder = fs.findResource( PALETTE_ROOT_FOLDER_NAME );
45         if( null != paletteRootFolder )
46             paletteRootFolder.delete();
47         paletteRootFolder = fs.getRoot().createFolder( PALETTE_ROOT_FOLDER_NAME );
48     }
49
50     protected void tearDown() throws Exception JavaDoc {
51         FileSystem fs = Repository.getDefault().getDefaultFileSystem();
52         paletteRootFolder = fs.findResource( PALETTE_ROOT_FOLDER_NAME );
53         if( null != paletteRootFolder )
54             paletteRootFolder.delete();
55     }
56
57     /**
58      * Test of createPalette method, of class org.netbeans.modules.palette.api.PaletteFactory.
59      */

60     public void testCreatePaletteNulls() throws Exception JavaDoc {
61         try {
62             PaletteFactory.createPalette( (String JavaDoc)null, new DummyActions() );
63             fail( "Palette factory accepts null as folder name." );
64         } catch( IllegalArgumentException JavaDoc e ) {
65             //that's what we want
66
} catch( Throwable JavaDoc t ) {
67             fail( "Invalid exception thrown." );
68         }
69         
70         try {
71             PaletteFactory.createPalette( (Node)null, new DummyActions() );
72             fail( "Palette factory accepts null as root Node." );
73         } catch( IllegalArgumentException JavaDoc e ) {
74             //that's what we want
75
} catch( Throwable JavaDoc t ) {
76             fail( "Invalid exception thrown." );
77         }
78         
79         try {
80             PaletteFactory.createPalette( DummyPalette.createPaletteRoot(), null );
81             fail( "Palette factory accepts null for palette actions." );
82         } catch( IllegalArgumentException JavaDoc e ) {
83             //that's what we want
84
} catch( Throwable JavaDoc t ) {
85             fail( "Invalid exception thrown." );
86         }
87     }
88     
89     public void testCreatePaletteFolder() throws Exception JavaDoc {
90         try {
91             PaletteFactory.createPalette( "non_existent_folder", new DummyActions() );
92             fail( "Palette factory accepts non-existent folders." );
93         } catch( FileNotFoundException JavaDoc fnfE ) {
94             //that's what we want
95
} catch( Throwable JavaDoc e ) {
96             fail( "Invalid exception thrown." );
97         }
98         
99         PaletteActions actions = new DummyActions();
100         PaletteController controller = PaletteFactory.createPalette( PALETTE_ROOT_FOLDER_NAME, actions );
101         Node rootNode = (Node)controller.getRoot().lookup( Node.class );
102         assertNotNull( rootNode );
103         assertEquals( actions, controller.getRoot().lookup( PaletteActions.class ) );
104     }
105     
106     public void testCreatePaletteNodes() throws Exception JavaDoc {
107         PaletteActions actions = new DummyActions();
108         Node rootNode = DummyPalette.createPaletteRoot();
109         PaletteController controller = PaletteFactory.createPalette( rootNode, actions );
110         assertEquals( rootNode.getName(), controller.getRoot().lookup( Node.class ).getName() );
111         assertEquals( actions, controller.getRoot().lookup( PaletteActions.class ) );
112     }
113     
114 }
115
Popular Tags