1 19 20 package org.netbeans.modules.j2ee.deployment.impl; 21 22 import junit.framework.*; 23 import org.netbeans.junit.*; 24 import org.openide.filesystems.*; 25 import org.openide.util.Lookup; 26 import org.openide.util.lookup.InstanceContent; 27 import org.openide.util.lookup.Lookups; 28 import org.openide.util.lookup.ProxyLookup; 29 import java.util.*; 30 import java.io.*; 31 import java.util.logging.*; 32 33 37 public class ServerRegistryTestBase extends NbTestCase { 38 static { 39 System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); 40 } 41 42 protected ServerRegistryTestBase (String name) { 43 super (name); 44 } 45 46 public static final class Lkp extends ProxyLookup { 47 public Lkp() { 48 super(new Lookup[] { 49 Lookups.fixed(new Object [] {"repo"}, new Conv()), 50 Lookups.metaInfServices(Lkp.class.getClassLoader()), 51 Lookups.singleton(Lkp.class.getClassLoader()), 52 }); 53 } 54 private static final class Conv implements InstanceContent.Convertor { 55 public Conv() {} 56 public Object convert(Object obj) { 57 assert obj == "repo"; 58 try { 59 return new Repo(); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 return null; 63 } 64 } 65 public String displayName(Object obj) { 66 return obj.toString(); 67 } 68 public String id(Object obj) { 69 return obj.toString(); 70 } 71 public Class type(Object obj) { 72 assert obj == "repo"; 73 return Repository.class; 74 } 75 } 76 } 77 private File scratchF; 78 79 private void mkdir(String path) { 80 new File(scratchF, path.replace('/', File.separatorChar)).mkdirs(); 82 } 83 protected boolean runInEQ() { 84 return true; 85 } 86 protected void setUp() throws Exception { 87 super.setUp(); 88 clearWorkDir(); 89 scratchF = getWorkDir(); 90 mkdir("system/J2EE/InstalledServers"); 91 mkdir("system/J2EE/DeploymentPlugins"); 92 System.setProperty("SYSTEMDIR", new File(scratchF, "system").getAbsolutePath()); 93 FileObject sfs = Repository.getDefault().getDefaultFileSystem().getRoot(); 94 assertNotNull("no default FS", sfs); 95 FileObject j2eeFolder = sfs.getFileObject("J2EE"); 96 assertNotNull("have J2EE", j2eeFolder); 97 } 103 104 private static final class Repo extends Repository { 105 106 public Repo() throws Exception { 107 super(mksystem()); 108 } 109 110 private static FileSystem mksystem() throws Exception { 111 LocalFileSystem lfs = new LocalFileSystem(); 112 lfs.setRootDirectory(new File(System.getProperty("SYSTEMDIR"))); 113 java.net.URL layerFile = Repo.class.getClassLoader().getResource ("org/netbeans/tests/j2eeserver/plugin/layer.xml"); 114 assert layerFile != null; 115 XMLFileSystem layer = new XMLFileSystem (layerFile); 116 FileSystem layers [] = new FileSystem [] {lfs, layer}; 117 MultiFileSystem mfs = new MultiFileSystem (layers); 118 return mfs; 119 } 120 121 } 122 123 } 124 | Popular Tags |