1 19 20 package org.netbeans.upgrade; 21 import java.io.File ; 22 import java.net.URL ; 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 39 public final class AutoUpgradeTest extends org.netbeans.junit.NbTestCase { 40 public AutoUpgradeTest (String name) { 41 super (name); 42 } 43 44 protected void setUp() throws java.lang.Exception { 45 super.setUp(); 46 } 47 48 49 public void testDoUpgrade() throws Exception { 50 File wrkDir = getWorkDir(); 51 clearWorkDir(); 52 File old = new File (wrkDir, "old"); 53 old.mkdir(); 54 File config = new File (old, "config"); 55 config.mkdir(); 56 57 LocalFileSystem lfs = new LocalFileSystem(); 58 lfs.setRootDirectory(config); 59 lfs.getRoot().createFolder("test"); 61 62 String oldVersion = "foo"; 63 64 URL 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 fooBar = "/foo/bar"; 72 73 FileObject fooBarFO = mfs.findResource(fooBar); 74 String attrName = "color"; 75 String attrValue = "black"; 76 fooBarFO.setAttribute(attrName, attrValue); 77 78 System.setProperty("netbeans.user", new File (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 |