KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > upgrade > AutoUpgradeTest


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.upgrade;
21 import java.io.File JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.*;
24
25 import org.openide.filesystems.FileObject;
26
27 import org.openide.filesystems.FileSystem;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.filesystems.LocalFileSystem;
30 import org.openide.filesystems.MultiFileSystem;
31 import org.openide.filesystems.Repository;
32 import org.openide.filesystems.XMLFileSystem;
33
34 /** Tests copying of attributes during upgrade when .nbattrs file is stored on the
35  * local filesystem while the respective fileobject is stored on the XML filesystem.
36  *
37  * @author sherold
38  */

39 public final class AutoUpgradeTest extends org.netbeans.junit.NbTestCase {
40     public AutoUpgradeTest (String JavaDoc name) {
41         super (name);
42     }
43     
44     protected void setUp() throws java.lang.Exception JavaDoc {
45         super.setUp();
46     }
47     
48     
49     public void testDoUpgrade() throws Exception JavaDoc {
50         File JavaDoc wrkDir = getWorkDir();
51         clearWorkDir();
52         File JavaDoc old = new File JavaDoc(wrkDir, "old");
53         old.mkdir();
54         File JavaDoc config = new File JavaDoc(old, "config");
55         config.mkdir();
56         
57         LocalFileSystem lfs = new LocalFileSystem();
58         lfs.setRootDirectory(config);
59         // filesystem must not be empty, otherwise .nbattrs file will be deleted :(
60
lfs.getRoot().createFolder("test");
61         
62         String JavaDoc oldVersion = "foo";
63         
64         URL JavaDoc url = AutoUpgradeTest.class.getResource("layer" + oldVersion + ".xml");
65         XMLFileSystem xmlfs = new XMLFileSystem(url);
66         
67         MultiFileSystem mfs = new MultiFileSystem(
68                 new FileSystem[] { lfs, xmlfs }
69         );
70         
71         String JavaDoc fooBar = "/foo/bar";
72         
73         FileObject fooBarFO = mfs.findResource(fooBar);
74         String JavaDoc attrName = "color";
75         String JavaDoc attrValue = "black";
76         fooBarFO.setAttribute(attrName, attrValue);
77         
78         System.setProperty("netbeans.user", new File JavaDoc(wrkDir, "new").getAbsolutePath());
79         
80         AutoUpgrade.doUpgrade(old, oldVersion);
81         
82         FileSystem dfs = Repository.getDefault().getDefaultFileSystem();
83         
84         MultiFileSystem newmfs = new MultiFileSystem(
85                 new FileSystem[] { dfs, xmlfs }
86         );
87         
88         FileObject newFooBarFO = newmfs.findResource(fooBar);
89         assertNotNull(newFooBarFO);
90         assertEquals(attrValue, newFooBarFO.getAttribute(attrName));
91     }
92  }
93
Popular Tags