KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > DragAndDropDataNodeTest


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.openide.loaders;
21
22 import java.awt.datatransfer.DataFlavor JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.List JavaDoc;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.nodes.Children;
31 import org.netbeans.junit.*;
32 import org.openide.filesystems.LocalFileSystem;
33
34 public class DragAndDropDataNodeTest extends NbTestCase {
35
36     private LocalFileSystem testFileSystem;
37
38     public DragAndDropDataNodeTest(String JavaDoc name) {
39         super(name);
40     }
41
42     protected void setUp() throws Exception JavaDoc {
43         clearWorkDir();
44         
45         testFileSystem = new LocalFileSystem();
46         testFileSystem.setRootDirectory( getWorkDir() );
47     }
48
49     public void testClipboardCopy() throws IOException JavaDoc, ClassNotFoundException JavaDoc, UnsupportedFlavorException JavaDoc {
50         DataFlavor JavaDoc uriListFlavor = new DataFlavor JavaDoc("text/uri-list;class=java.lang.String");
51
52         FileObject fo = FileUtil.createData( testFileSystem.getRoot(), "dndtest.txt" );
53         File JavaDoc tmpFile = FileUtil.toFile( fo );
54
55         DataObject dob = DataObject.find( fo );
56         DataNode node = new DataNode( dob, Children.LEAF );
57
58         Transferable JavaDoc t = node.clipboardCopy();
59         assertTrue( t.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) );
60         List JavaDoc fileList = (List JavaDoc) t.getTransferData( DataFlavor.javaFileListFlavor );
61         assertNotNull( fileList );
62         assertEquals( 1, fileList.size() );
63         assertTrue( fileList.contains( tmpFile ) );
64
65         assertTrue( t.isDataFlavorSupported( uriListFlavor ) );
66         String JavaDoc uriList = (String JavaDoc) t.getTransferData( uriListFlavor );
67         assertEquals( tmpFile.toURI()+"\r\n", uriList );
68     }
69
70     public void testClipboardCut() throws ClassNotFoundException JavaDoc, IOException JavaDoc, UnsupportedFlavorException JavaDoc {
71         DataFlavor JavaDoc uriListFlavor = new DataFlavor JavaDoc("text/uri-list;class=java.lang.String");
72
73         FileObject fo = FileUtil.createData( testFileSystem.getRoot(), "dndtest.txt" );
74         File JavaDoc tmpFile = FileUtil.toFile( fo );
75
76         DataObject dob = DataObject.find( fo );
77         DataNode node = new DataNode( dob, Children.LEAF );
78
79         Transferable JavaDoc t = node.clipboardCopy();
80         assertTrue( t.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) );
81         List JavaDoc fileList = (List JavaDoc) t.getTransferData( DataFlavor.javaFileListFlavor );
82         assertNotNull( fileList );
83         assertEquals( 1, fileList.size() );
84         assertTrue( fileList.contains( tmpFile ) );
85
86         assertTrue( t.isDataFlavorSupported( uriListFlavor ) );
87         String JavaDoc uriList = (String JavaDoc) t.getTransferData( uriListFlavor );
88         assertEquals( tmpFile.toURI()+"\r\n", uriList );
89     }
90 }
91
Popular Tags