KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ServerRegistryTestBase


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.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 /**
34  *
35  * @author Pavel Buzek
36  */

37 public class ServerRegistryTestBase extends NbTestCase {
38     static {
39         System.setProperty("org.openide.util.Lookup", Lkp.class.getName());
40     }
41     
42     protected ServerRegistryTestBase (String JavaDoc 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 JavaDoc[] {"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 JavaDoc convert(Object JavaDoc obj) {
57                 assert obj == "repo";
58                 try {
59                     return new Repo();
60                 } catch (Exception JavaDoc e) {
61                     e.printStackTrace();
62                     return null;
63                 }
64             }
65             public String JavaDoc displayName(Object JavaDoc obj) {
66                 return obj.toString();
67             }
68             public String JavaDoc id(Object JavaDoc obj) {
69                 return obj.toString();
70             }
71             public Class JavaDoc type(Object JavaDoc obj) {
72                 assert obj == "repo";
73                 return Repository.class;
74             }
75         }
76     }
77     private File scratchF;
78     
79     private void mkdir(String JavaDoc path) {
80 // System.out.println ("mkdir:"+path);
81
new File(scratchF, path.replace('/', File.separatorChar)).mkdirs();
82     }
83     protected boolean runInEQ() {
84         return true;
85     }
86     protected void setUp() throws Exception JavaDoc {
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 // Enumeration enumDest = sfs.getChildren (true);
98
// while (enumDest.hasMoreElements()) {
99
// FileObject f = (FileObject) enumDest.nextElement();
100
// System.out.println (" dest file:" + f.getPath ());
101
// }
102
}
103     
104      private static final class Repo extends Repository {
105         
106         public Repo() throws Exception JavaDoc {
107             super(mksystem());
108         }
109         
110         private static FileSystem mksystem() throws Exception JavaDoc {
111             LocalFileSystem lfs = new LocalFileSystem();
112             lfs.setRootDirectory(new File(System.getProperty("SYSTEMDIR")));
113             java.net.URL JavaDoc 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