KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > loaderswitcher > ObjectTypeTest


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.modules.loaderswitcher;
21
22 import java.io.IOException JavaDoc;
23 import java.util.logging.Level JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.openide.filesystems.FileObject;
26 import org.openide.filesystems.FileSystem;
27 import org.openide.filesystems.FileUtil;
28 import org.openide.loaders.*;
29
30 /** Checks the functional behaviour of the Object Type Switcher.
31  *
32  * @author Jaroslav Tulach
33  */

34 public class ObjectTypeTest extends NbTestCase
35 implements DataLoader.RecognizedFiles {
36
37     public ObjectTypeTest(String JavaDoc testName) {
38         super(testName);
39     }
40
41     protected Level JavaDoc logLevel() {
42         return Level.ALL;
43     }
44
45     protected void setUp() throws Exception JavaDoc {
46     }
47
48     protected void tearDown() throws Exception JavaDoc {
49     }
50
51     public void testFindAndSwitch() throws Exception JavaDoc {
52         FileSystem fs = FileUtil.createMemoryFileSystem();
53         FileObject fnd = fs.getRoot().createFolder("testFindAndSwitch");
54         
55         DataObject obj = InstanceDataObject.create(DataFolder.findFolder(fnd), "ahoj", java.awt.FlowLayout JavaDoc.class);
56         
57         DataLoader[] x = ObjectType.findPossibleLoaders(obj, this);
58         
59         assertEquals("Two loaders shall be interested", 2, x.length);
60         assertEquals("First one is the actual loader", obj.getLoader(), x[0]);
61
62         assertEquals("Name", "ahoj", obj.getName());
63
64         ObjectType.convertTo(obj, x[1]);
65
66         assertFalse("Old object is invalidated", obj.isValid());
67
68         DataObject n = DataObject.find(obj.getPrimaryFile());
69
70         if (n == obj) {
71             fail("They should be different: " + n);
72         }
73
74         assertEquals("The right loader", x[1], n.getLoader());
75
76
77         assertEquals("Name with extension", "ahoj.instance", n.getName());
78
79         n.rename("kuk.unknown");
80
81         DataLoader[] arr = ObjectType.findPossibleLoaders(n, this);
82         assertEquals("Just one loader now", 1, arr.length);
83         assertEquals("and it is the default loader", n.getLoader(), arr[0]);
84
85     }
86
87     public void markRecognized(FileObject fo) {
88     }
89 }
90
Popular Tags