1 19 20 package org.netbeans.spi.palette; 21 22 import java.io.FileNotFoundException ; 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 33 public class PaletteFactoryTest extends TestCase { 34 35 private FileObject paletteRootFolder; 36 private static final String PALETTE_ROOT_FOLDER_NAME = "test_palette_folder"; 37 38 public PaletteFactoryTest(String testName) { 39 super(testName); 40 } 41 42 protected void setUp() throws Exception { 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 { 51 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 52 paletteRootFolder = fs.findResource( PALETTE_ROOT_FOLDER_NAME ); 53 if( null != paletteRootFolder ) 54 paletteRootFolder.delete(); 55 } 56 57 60 public void testCreatePaletteNulls() throws Exception { 61 try { 62 PaletteFactory.createPalette( (String )null, new DummyActions() ); 63 fail( "Palette factory accepts null as folder name." ); 64 } catch( IllegalArgumentException e ) { 65 } catch( Throwable 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 e ) { 74 } catch( Throwable 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 e ) { 83 } catch( Throwable t ) { 85 fail( "Invalid exception thrown." ); 86 } 87 } 88 89 public void testCreatePaletteFolder() throws Exception { 90 try { 91 PaletteFactory.createPalette( "non_existent_folder", new DummyActions() ); 92 fail( "Palette factory accepts non-existent folders." ); 93 } catch( FileNotFoundException fnfE ) { 94 } catch( Throwable 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 { 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 |