KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > execution > ServerExecutorTest


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.execution;
21
22 import junit.framework.*;
23 import org.netbeans.junit.*;
24 import org.netbeans.tests.j2eeserver.devmodule.*;
25 import org.netbeans.modules.j2ee.deployment.impl.*;
26 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
27 import org.openide.filesystems.*;
28 import java.io.*;
29 import java.util.*;
30
31 /**
32  *
33  * @author nn136682
34  */

35 public class ServerExecutorTest extends NbTestCase {
36
37     public ServerExecutorTest(java.lang.String JavaDoc testName) {
38         super(testName);
39     }
40
41     private static ServerExecutorTest instance;
42     private static ServerExecutorTest instance() {
43         if (instance == null)
44             instance = new ServerExecutorTest("testNothing");
45         return instance;
46     }
47     
48     public void testNothing() {
49     }
50     
51     static private DeployTarget dt;
52     static private LocalFileSystem wfs;
53     static FileSystem getWorkFileSystem() {
54         if (wfs != null)
55             return wfs;
56         try {
57             File workdir = instance().getWorkDir();
58             wfs = new LocalFileSystem();
59             wfs.setRootDirectory(workdir);
60             return wfs;
61         } catch (Exception JavaDoc e) {
62             throw new RuntimeException JavaDoc(e);
63         }
64     }
65         
66     public static DeployTarget getDeploymentTarget(ServerString targetServer) {
67         if (dt != null) {
68             dt.setServer(targetServer);
69             return dt;
70         }
71         
72         try {
73             FileObject testJar = FileUtil.createData(getWorkFileSystem().getRoot(),"test.jar");
74             dt = new DeployTarget(new TestJ2eeModule(J2eeModule.EJB, testJar), targetServer);
75         } catch (Exception JavaDoc e) {
76             throw new RuntimeException JavaDoc(e);
77         }
78         return dt;
79     }
80     
81     public static class DeployTarget implements DeploymentTarget {
82         J2eeModule j2eeMod;
83         ServerString target;
84         
85         /** Creates a new instance of TestDeployTarget */
86         public DeployTarget(J2eeModule mod, ServerString target) {
87             j2eeMod = mod;
88             this.target = target;
89         }
90         
91         public boolean doFastDeploy() {
92             return false;
93         }
94         
95         public boolean dontDeploy() {
96             return false;
97         }
98         
99         public java.io.File JavaDoc getConfigurationFile() {
100             return null;
101         }
102         
103         public org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule getModule() {
104             return j2eeMod;
105         }
106         
107         public org.netbeans.modules.j2ee.deployment.impl.ServerString getServer() {
108             return target;
109         }
110         public void setServer(ServerString server) { this.target = server; }
111         
112         public TargetModule[] getTargetModules() {
113             TargetModule.List l = readTargetModule(getName());
114             if (l == null)
115                 return new TargetModule[0];
116             return l.getTargetModules();
117         }
118         
119         public void setTargetModules(TargetModule[] targetModules) {
120             System.out.println("-------------SETTARGETMODULES: name="+getName()+","+Arrays.asList(targetModules));
121                 writeTargetModule(getName(), new TargetModule.List(targetModules));
122         }
123         
124         public void startClient() {
125         }
126         public void startClient(String JavaDoc clientURL) {
127             
128         }
129         
130         String JavaDoc name;
131         public String JavaDoc getName() {
132             try {
133             if (name == null) {
134                 String JavaDoc serverName = this.getServer().getUrl();
135                 serverName = serverName.substring(serverName.lastIndexOf(':')+1);
136                 name = serverName + getModule().getArchive().getName();
137             }
138             } catch(Exception JavaDoc e) {
139                 throw new RuntimeException JavaDoc(e);
140             }
141             return name;
142         }
143         
144         public String JavaDoc getDeploymentName() {
145             return null;
146         }
147
148         public String JavaDoc getClientUrl(String JavaDoc partUrl) {
149             return null;
150         }
151         
152         public org.netbeans.modules.j2ee.deployment.devmodules.api.ModuleChangeReporter getModuleChangeReporter() {
153             return null;
154         }
155         
156         public org.netbeans.modules.j2ee.deployment.execution.DeploymentConfigurationProvider getDeploymentConfigurationProvider() {
157             return null;
158         }
159         
160         public org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider.ConfigSupport getConfigSupport() {
161             return null;
162         }
163         
164     }
165     
166     public static boolean writeTargetModule(String JavaDoc destFile, TargetModule.List tml) {
167         FileLock lock = null;
168         Writer writer = null;
169         try {
170             if (tml == null)
171                 return true;
172             
173             FileObject fo = FileUtil.createData(getWorkFileSystem().getRoot(), destFile+".xml");
174             lock = fo.lock();
175             writer = new OutputStreamWriter(fo.getOutputStream(lock));
176             TargetModuleConverter.create().write(writer, tml);
177             return true;
178             
179         } catch(Exception JavaDoc ioe) {
180             throw new RuntimeException JavaDoc(ioe);
181         }
182         finally {
183             try {
184             if (lock != null) lock.releaseLock();
185             if (writer != null) writer.close();
186             } catch (Exception JavaDoc e) {}
187         }
188     }
189
190     public static TargetModule.List readTargetModule(String JavaDoc fromFile) {
191         Reader reader = null;
192         try {
193             FileObject dir = getWorkFileSystem().getRoot();
194             FileObject fo = dir.getFileObject (fromFile, "xml");
195             if (fo == null) {
196                 System.out.println(Thread.currentThread()+ " readTargetModule: Can't get FO for "+fromFile+".xml from "+dir.getPath());
197                 return null;
198             }
199             reader = new InputStreamReader(fo.getInputStream());
200             return (TargetModule.List) TargetModuleConverter.create().read(reader);
201         } catch(Exception JavaDoc ioe) {
202             throw new RuntimeException JavaDoc(ioe);
203         } finally {
204             try {
205             if (reader != null) reader.close();
206             } catch (Exception JavaDoc e) {}
207         }
208     }
209 }
210
Popular Tags