3568 |
18 Jul 07 |
martin |
1 |
/** |
3568 |
18 Jul 07 |
martin |
$Id$ |
3568 |
18 Jul 07 |
martin |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg, Martin Svensson |
3568 |
18 Jul 07 |
martin |
5 |
|
3568 |
18 Jul 07 |
martin |
This file is part of BASE - BioArray Software Environment. |
3568 |
18 Jul 07 |
martin |
Available at http://base.thep.lu.se/ |
3568 |
18 Jul 07 |
martin |
8 |
|
3568 |
18 Jul 07 |
martin |
BASE is free software; you can redistribute it and/or modify it |
3568 |
18 Jul 07 |
martin |
under the terms of the GNU General Public License as published by |
4480 |
05 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
3568 |
18 Jul 07 |
martin |
(at your option) any later version. |
3568 |
18 Jul 07 |
martin |
13 |
|
3568 |
18 Jul 07 |
martin |
BASE is distributed in the hope that it will be useful, but |
3568 |
18 Jul 07 |
martin |
WITHOUT ANY WARRANTY; without even the implied warranty of |
3568 |
18 Jul 07 |
martin |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3568 |
18 Jul 07 |
martin |
General Public License for more details. |
3568 |
18 Jul 07 |
martin |
18 |
|
3568 |
18 Jul 07 |
martin |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
3568 |
18 Jul 07 |
martin |
21 |
*/ |
3568 |
18 Jul 07 |
martin |
22 |
|
3568 |
18 Jul 07 |
martin |
23 |
import net.sf.basedb.core.BaseException; |
3568 |
18 Jul 07 |
martin |
24 |
import net.sf.basedb.core.DbControl; |
3646 |
09 Aug 07 |
nicklas |
25 |
import net.sf.basedb.core.Directory; |
3568 |
18 Jul 07 |
martin |
26 |
import net.sf.basedb.core.File; |
3568 |
18 Jul 07 |
martin |
27 |
import net.sf.basedb.core.Item; |
3646 |
09 Aug 07 |
nicklas |
28 |
import net.sf.basedb.core.ItemContext; |
3568 |
18 Jul 07 |
martin |
29 |
import net.sf.basedb.core.Job; |
3568 |
18 Jul 07 |
martin |
30 |
import net.sf.basedb.core.ParameterType; |
3568 |
18 Jul 07 |
martin |
31 |
import net.sf.basedb.core.Path; |
3568 |
18 Jul 07 |
martin |
32 |
import net.sf.basedb.core.Permission; |
3646 |
09 Aug 07 |
nicklas |
33 |
import net.sf.basedb.core.PluginConfiguration; |
3568 |
18 Jul 07 |
martin |
34 |
import net.sf.basedb.core.PluginConfigurationRequest; |
3568 |
18 Jul 07 |
martin |
35 |
import net.sf.basedb.core.PluginDefinition; |
3568 |
18 Jul 07 |
martin |
36 |
import net.sf.basedb.core.PluginParameter; |
3568 |
18 Jul 07 |
martin |
37 |
import net.sf.basedb.core.PluginResponse; |
3568 |
18 Jul 07 |
martin |
38 |
import net.sf.basedb.core.RequestInformation; |
3646 |
09 Aug 07 |
nicklas |
39 |
import net.sf.basedb.core.SessionControl; |
3646 |
09 Aug 07 |
nicklas |
40 |
import net.sf.basedb.core.plugin.GuiContext; |
3568 |
18 Jul 07 |
martin |
41 |
import net.sf.basedb.core.plugin.Response; |
3568 |
18 Jul 07 |
martin |
42 |
|
3646 |
09 Aug 07 |
nicklas |
43 |
import java.io.InputStream; |
3568 |
18 Jul 07 |
martin |
44 |
import java.util.ArrayList; |
3568 |
18 Jul 07 |
martin |
45 |
import java.util.List; |
3568 |
18 Jul 07 |
martin |
46 |
import java.util.zip.GZIPInputStream; |
3568 |
18 Jul 07 |
martin |
47 |
import java.util.zip.ZipEntry; |
3568 |
18 Jul 07 |
martin |
48 |
import java.util.zip.ZipInputStream; |
3568 |
18 Jul 07 |
martin |
49 |
|
3646 |
09 Aug 07 |
nicklas |
50 |
import org.apache.tools.bzip2.CBZip2InputStream; |
3646 |
09 Aug 07 |
nicklas |
51 |
|
3568 |
18 Jul 07 |
martin |
52 |
import com.ice.tar.TarEntry; |
3568 |
18 Jul 07 |
martin |
53 |
import com.ice.tar.TarInputStream; |
3568 |
18 Jul 07 |
martin |
54 |
|
3568 |
18 Jul 07 |
martin |
55 |
public class TestPackedFileExporter |
3568 |
18 Jul 07 |
martin |
56 |
{ |
3568 |
18 Jul 07 |
martin |
57 |
static boolean ok = true; |
3568 |
18 Jul 07 |
martin |
58 |
|
3568 |
18 Jul 07 |
martin |
59 |
/** |
3568 |
18 Jul 07 |
martin |
@param args |
3568 |
18 Jul 07 |
martin |
61 |
*/ |
3568 |
18 Jul 07 |
martin |
62 |
public static void main(String[] args) |
3568 |
18 Jul 07 |
martin |
63 |
{ |
3568 |
18 Jul 07 |
martin |
64 |
TestUtil.checkArgs(args); |
3568 |
18 Jul 07 |
martin |
65 |
TestUtil.begin(); |
3568 |
18 Jul 07 |
martin |
66 |
ok = test_all(); |
3568 |
18 Jul 07 |
martin |
67 |
TestUtil.stop(); |
3568 |
18 Jul 07 |
martin |
68 |
} |
3568 |
18 Jul 07 |
martin |
69 |
|
3568 |
18 Jul 07 |
martin |
70 |
static boolean test_all() |
3568 |
18 Jul 07 |
martin |
71 |
{ |
3568 |
18 Jul 07 |
martin |
72 |
write("++Testing TestPackedFileExporter"); |
3568 |
18 Jul 07 |
martin |
73 |
String packedDir = "packedFiles"; |
3646 |
09 Aug 07 |
nicklas |
// Directory where packed files are created |
3568 |
18 Jul 07 |
martin |
75 |
int packedDirId = TestDirectory.test_create(true, packedDir); |
3646 |
09 Aug 07 |
nicklas |
76 |
|
3646 |
09 Aug 07 |
nicklas |
// Upload zip file to '/unpackzip' |
3568 |
18 Jul 07 |
martin |
78 |
int dirId = TestDirectory.test_create(true, "unpackzip"); |
3568 |
18 Jul 07 |
martin |
79 |
TestFile.test_unpack_zip("data/test.unpack.zip", dirId); |
3646 |
09 Aug 07 |
nicklas |
80 |
|
3646 |
09 Aug 07 |
nicklas |
// Files and directories to pack |
3568 |
18 Jul 07 |
martin |
82 |
List<String> filePaths = new ArrayList<String>(); |
3646 |
09 Aug 07 |
nicklas |
83 |
List<String> directoryPaths = new ArrayList<String>(); |
3568 |
18 Jul 07 |
martin |
84 |
filePaths.add("/unpackzip/index.html"); |
3571 |
19 Jul 07 |
martin |
85 |
directoryPaths.add("/unpackzip/images"); |
3646 |
09 Aug 07 |
nicklas |
86 |
set_selected(filePaths, directoryPaths); |
3568 |
18 Jul 07 |
martin |
87 |
|
3646 |
09 Aug 07 |
nicklas |
88 |
int pluginId = TestPluginDefinition.test_get("net.sf.basedb.plugins.PackedFileExporter"); |
3646 |
09 Aug 07 |
nicklas |
89 |
|
3568 |
18 Jul 07 |
martin |
// Create job to zip files |
3646 |
09 Aug 07 |
nicklas |
91 |
int zipConfig = test_create_config(pluginId, "Zip", "net.sf.basedb.util.zip.ZipFilePacker"); |
3646 |
09 Aug 07 |
nicklas |
92 |
Path zip = new Path("/" + packedDir + "/test.compressed.file.zip", Path.Type.FILE); |
3646 |
09 Aug 07 |
nicklas |
93 |
int zipJobId = test_create_job(zipConfig, dirId, zip.toString()); |
5319 |
20 Apr 10 |
nicklas |
94 |
ok = TestJob.test_execute(zipJobId, false) && ok; |
3646 |
09 Aug 07 |
nicklas |
95 |
test_read_zip(zip); |
3646 |
09 Aug 07 |
nicklas |
96 |
|
3646 |
09 Aug 07 |
nicklas |
// Create job to pack files in tar |
3646 |
09 Aug 07 |
nicklas |
98 |
int tarConfig = test_create_config(pluginId, "Tar", "net.sf.basedb.util.zip.TarFilePacker"); |
3646 |
09 Aug 07 |
nicklas |
99 |
Path tar = new Path("/" + packedDir + "/test.compressed.file.tar", Path.Type.FILE); |
3646 |
09 Aug 07 |
nicklas |
100 |
int tarJobId = test_create_job(tarConfig, dirId, tar.toString()); |
5319 |
20 Apr 10 |
nicklas |
101 |
ok = TestJob.test_execute(tarJobId, false) && ok; |
3646 |
09 Aug 07 |
nicklas |
102 |
test_read_tar(tar, false, false); |
3568 |
18 Jul 07 |
martin |
103 |
|
3568 |
18 Jul 07 |
martin |
// Create job to pack files in tar.gz |
3646 |
09 Aug 07 |
nicklas |
105 |
int tarGzConfig = test_create_config(pluginId, "Tar.gz", "net.sf.basedb.util.zip.GzipFilePacker"); |
3646 |
09 Aug 07 |
nicklas |
106 |
Path tarGz = new Path("/" + packedDir + "/test.compressed.file.tar.gz", Path.Type.FILE); |
3646 |
09 Aug 07 |
nicklas |
107 |
int tarGzJobId = test_create_job(tarGzConfig, dirId, tarGz.toString()); |
5319 |
20 Apr 10 |
nicklas |
108 |
ok = TestJob.test_execute(tarGzJobId, false) && ok; |
3646 |
09 Aug 07 |
nicklas |
109 |
test_read_tar(tarGz, true, false); |
3568 |
18 Jul 07 |
martin |
110 |
|
3646 |
09 Aug 07 |
nicklas |
// Create job to pack files in tar.bz2 |
3646 |
09 Aug 07 |
nicklas |
112 |
int tarBz2Config = test_create_config(pluginId, "Tar.bz2", "net.sf.basedb.util.zip.Bzip2FilePacker"); |
3646 |
09 Aug 07 |
nicklas |
113 |
Path tarBz2 = new Path("/" + packedDir + "/test.compressed.file.tar.bz2", Path.Type.FILE); |
3646 |
09 Aug 07 |
nicklas |
114 |
int tarBz2JobId = test_create_job(tarBz2Config, dirId, tarBz2.toString()); |
5319 |
20 Apr 10 |
nicklas |
115 |
ok = TestJob.test_execute(tarBz2JobId, false) && ok; |
3646 |
09 Aug 07 |
nicklas |
116 |
test_read_tar(tarBz2, false, true); |
3646 |
09 Aug 07 |
nicklas |
117 |
|
3568 |
18 Jul 07 |
martin |
// Clean up |
3568 |
18 Jul 07 |
martin |
119 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
3571 |
19 Jul 07 |
martin |
120 |
TestJob.test_delete(zipJobId); |
3571 |
19 Jul 07 |
martin |
121 |
TestJob.test_delete(tarJobId); |
3646 |
09 Aug 07 |
nicklas |
122 |
TestJob.test_delete(tarGzJobId); |
3646 |
09 Aug 07 |
nicklas |
123 |
TestJob.test_delete(tarBz2JobId); |
3646 |
09 Aug 07 |
nicklas |
124 |
TestPluginConfiguration.test_delete(zipConfig); |
3646 |
09 Aug 07 |
nicklas |
125 |
TestPluginConfiguration.test_delete(tarConfig); |
3646 |
09 Aug 07 |
nicklas |
126 |
TestPluginConfiguration.test_delete(tarGzConfig); |
3646 |
09 Aug 07 |
nicklas |
127 |
TestPluginConfiguration.test_delete(tarBz2Config); |
3646 |
09 Aug 07 |
nicklas |
128 |
TestDirectory.test_delete(packedDirId, true); |
3571 |
19 Jul 07 |
martin |
129 |
TestDirectory.test_delete(dirId, true); |
3568 |
18 Jul 07 |
martin |
130 |
|
3568 |
18 Jul 07 |
martin |
131 |
write("++Testing PackedFileExporter "+(ok ? "OK" : "Failed")+"\n"); |
3568 |
18 Jul 07 |
martin |
132 |
return ok; |
3568 |
18 Jul 07 |
martin |
133 |
} |
3568 |
18 Jul 07 |
martin |
134 |
|
3646 |
09 Aug 07 |
nicklas |
135 |
static int test_create_config(int pluginId, String name, String packerClass) |
3568 |
18 Jul 07 |
martin |
136 |
{ |
3646 |
09 Aug 07 |
nicklas |
137 |
if (pluginId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLUGINCONFIGURATION)) return 0; |
3568 |
18 Jul 07 |
martin |
138 |
int id = 0; |
3568 |
18 Jul 07 |
martin |
139 |
DbControl dc = null; |
3568 |
18 Jul 07 |
martin |
140 |
try |
3568 |
18 Jul 07 |
martin |
141 |
{ |
3568 |
18 Jul 07 |
martin |
142 |
dc = TestUtil.getDbControl(); |
3646 |
09 Aug 07 |
nicklas |
143 |
|
3646 |
09 Aug 07 |
nicklas |
144 |
PluginDefinition pd = PluginDefinition.getById(dc, pluginId); |
3646 |
09 Aug 07 |
nicklas |
145 |
PluginConfiguration pc = pd.newPluginConfiguration(); |
3646 |
09 Aug 07 |
nicklas |
146 |
pc.setName(name); |
3568 |
18 Jul 07 |
martin |
147 |
|
3646 |
09 Aug 07 |
nicklas |
148 |
PluginConfigurationRequest request = pc.configure(); |
3568 |
18 Jul 07 |
martin |
149 |
write_request_information(request.getRequestInformation()); |
3646 |
09 Aug 07 |
nicklas |
150 |
request.setParameterValue("packer", packerClass); |
3646 |
09 Aug 07 |
nicklas |
151 |
|
3646 |
09 Aug 07 |
nicklas |
152 |
PluginResponse response = request.invoke(); |
3646 |
09 Aug 07 |
nicklas |
153 |
if (response.getStatus() == Response.Status.DONE) |
3568 |
18 Jul 07 |
martin |
154 |
{ |
3646 |
09 Aug 07 |
nicklas |
155 |
response.saveParameters(dc); |
3646 |
09 Aug 07 |
nicklas |
156 |
dc.saveItem(pc); |
3646 |
09 Aug 07 |
nicklas |
157 |
dc.commit(); |
3568 |
18 Jul 07 |
martin |
158 |
} |
3646 |
09 Aug 07 |
nicklas |
159 |
else |
3646 |
09 Aug 07 |
nicklas |
160 |
{ |
3646 |
09 Aug 07 |
nicklas |
161 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
3646 |
09 Aug 07 |
nicklas |
162 |
} |
3646 |
09 Aug 07 |
nicklas |
163 |
id = pc.getId(); |
3646 |
09 Aug 07 |
nicklas |
164 |
write("--Create configuration for " + name + " file export OK"); |
3646 |
09 Aug 07 |
nicklas |
165 |
} |
3646 |
09 Aug 07 |
nicklas |
166 |
catch (Throwable ex) |
3646 |
09 Aug 07 |
nicklas |
167 |
{ |
3646 |
09 Aug 07 |
nicklas |
168 |
write("--Create configuration for " + name + " file export FAILED"); |
3646 |
09 Aug 07 |
nicklas |
169 |
ex.printStackTrace(); |
3646 |
09 Aug 07 |
nicklas |
170 |
ok = false; |
3646 |
09 Aug 07 |
nicklas |
171 |
} |
3646 |
09 Aug 07 |
nicklas |
172 |
finally |
3646 |
09 Aug 07 |
nicklas |
173 |
{ |
3646 |
09 Aug 07 |
nicklas |
174 |
if (dc != null) dc.close(); |
3646 |
09 Aug 07 |
nicklas |
175 |
} |
3646 |
09 Aug 07 |
nicklas |
176 |
return id; |
3646 |
09 Aug 07 |
nicklas |
177 |
} |
3646 |
09 Aug 07 |
nicklas |
178 |
|
3646 |
09 Aug 07 |
nicklas |
179 |
static void set_selected(List<String> filePaths, List<String> dirPaths) |
3646 |
09 Aug 07 |
nicklas |
180 |
{ |
3646 |
09 Aug 07 |
nicklas |
181 |
DbControl dc = null; |
3646 |
09 Aug 07 |
nicklas |
182 |
try |
3646 |
09 Aug 07 |
nicklas |
183 |
{ |
3646 |
09 Aug 07 |
nicklas |
184 |
dc = TestUtil.getDbControl(); |
3646 |
09 Aug 07 |
nicklas |
185 |
SessionControl sc = TestUtil.getSessionControl(); |
3646 |
09 Aug 07 |
nicklas |
186 |
ItemContext fileCC = sc.getCurrentContext(Item.FILE); |
3646 |
09 Aug 07 |
nicklas |
187 |
ItemContext dirCC = sc.getCurrentContext(Item.DIRECTORY); |
3646 |
09 Aug 07 |
nicklas |
188 |
|
3646 |
09 Aug 07 |
nicklas |
189 |
for (String path : filePaths) |
3646 |
09 Aug 07 |
nicklas |
190 |
{ |
3646 |
09 Aug 07 |
nicklas |
191 |
File f = File.getByPath(dc, new Path(path, Path.Type.FILE), false); |
3646 |
09 Aug 07 |
nicklas |
192 |
fileCC.getSelected().add(f.getId()); |
3646 |
09 Aug 07 |
nicklas |
193 |
} |
3646 |
09 Aug 07 |
nicklas |
194 |
for (String path : dirPaths) |
3646 |
09 Aug 07 |
nicklas |
195 |
{ |
3646 |
09 Aug 07 |
nicklas |
196 |
Directory d = Directory.getByPath(dc, new Path(path, Path.Type.DIRECTORY)); |
3646 |
09 Aug 07 |
nicklas |
197 |
dirCC.getSelected().add(d.getId()); |
3646 |
09 Aug 07 |
nicklas |
198 |
} |
3646 |
09 Aug 07 |
nicklas |
199 |
|
3646 |
09 Aug 07 |
nicklas |
200 |
write("--Set selected files and directories OK"); |
3646 |
09 Aug 07 |
nicklas |
201 |
} |
3646 |
09 Aug 07 |
nicklas |
202 |
catch (Throwable ex) |
3646 |
09 Aug 07 |
nicklas |
203 |
{ |
3646 |
09 Aug 07 |
nicklas |
204 |
write("--Set selected files and directories FAILED"); |
3646 |
09 Aug 07 |
nicklas |
205 |
ex.printStackTrace(); |
3646 |
09 Aug 07 |
nicklas |
206 |
ok = false; |
3646 |
09 Aug 07 |
nicklas |
207 |
} |
3646 |
09 Aug 07 |
nicklas |
208 |
finally |
3646 |
09 Aug 07 |
nicklas |
209 |
{ |
3646 |
09 Aug 07 |
nicklas |
210 |
if (dc != null) dc.close(); |
3646 |
09 Aug 07 |
nicklas |
211 |
} |
3646 |
09 Aug 07 |
nicklas |
212 |
} |
3646 |
09 Aug 07 |
nicklas |
213 |
|
3646 |
09 Aug 07 |
nicklas |
214 |
static int test_create_job(int configId, int rootDirId, String saveAs) |
3646 |
09 Aug 07 |
nicklas |
215 |
{ |
3646 |
09 Aug 07 |
nicklas |
216 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.JOB) || configId == 0) return 0; |
3646 |
09 Aug 07 |
nicklas |
217 |
int id = 0; |
3646 |
09 Aug 07 |
nicklas |
218 |
DbControl dc = null; |
3646 |
09 Aug 07 |
nicklas |
219 |
try |
3646 |
09 Aug 07 |
nicklas |
220 |
{ |
3646 |
09 Aug 07 |
nicklas |
221 |
dc = TestUtil.getDbControl(); |
3646 |
09 Aug 07 |
nicklas |
222 |
PluginDefinition pd = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.PackedFileExporter"); |
3646 |
09 Aug 07 |
nicklas |
223 |
|
3646 |
09 Aug 07 |
nicklas |
224 |
PluginConfiguration config = PluginConfiguration.getById(dc, configId); |
3646 |
09 Aug 07 |
nicklas |
225 |
|
4254 |
28 Apr 08 |
nicklas |
226 |
Job job = Job.getNew(dc, pd, config, null); |
3646 |
09 Aug 07 |
nicklas |
227 |
job.setName("Test " + config.getName()); |
3646 |
09 Aug 07 |
nicklas |
228 |
job.setSendMessage(false); |
3646 |
09 Aug 07 |
nicklas |
229 |
PluginConfigurationRequest request = job.configure(new GuiContext(Item.FILE, GuiContext.Type.LIST)); |
3646 |
09 Aug 07 |
nicklas |
230 |
|
3646 |
09 Aug 07 |
nicklas |
231 |
request.setParameterValue("root", Directory.getById(dc, rootDirId)); |
3568 |
18 Jul 07 |
martin |
232 |
request.setParameterValue("overwrite", true); |
3646 |
09 Aug 07 |
nicklas |
233 |
request.setParameterValue("saveAs", saveAs); |
3568 |
18 Jul 07 |
martin |
234 |
request.setParameterValue("removeItems", false); |
3568 |
18 Jul 07 |
martin |
235 |
|
3568 |
18 Jul 07 |
martin |
236 |
write_request_information(request.getRequestInformation()); |
3646 |
09 Aug 07 |
nicklas |
237 |
PluginResponse response = request.invoke(); |
3568 |
18 Jul 07 |
martin |
238 |
|
3646 |
09 Aug 07 |
nicklas |
239 |
if (response.getStatus() == Response.Status.DONE) |
3568 |
18 Jul 07 |
martin |
240 |
{ |
3646 |
09 Aug 07 |
nicklas |
241 |
response.saveParameters(dc); |
3568 |
18 Jul 07 |
martin |
242 |
dc.saveItem(job); |
3568 |
18 Jul 07 |
martin |
243 |
dc.commit(); |
3568 |
18 Jul 07 |
martin |
244 |
} |
3568 |
18 Jul 07 |
martin |
245 |
else |
3568 |
18 Jul 07 |
martin |
246 |
{ |
3646 |
09 Aug 07 |
nicklas |
247 |
throw new BaseException("Status: " + response.getStatus() +"\n" + response.getMessage(), response.getErrorList().get(0)); |
3568 |
18 Jul 07 |
martin |
248 |
} |
3568 |
18 Jul 07 |
martin |
249 |
id = job.getId(); |
3646 |
09 Aug 07 |
nicklas |
250 |
write("--Create job for PackedFileExporter OK"); |
3568 |
18 Jul 07 |
martin |
251 |
} |
3568 |
18 Jul 07 |
martin |
252 |
catch (Throwable ex) |
3568 |
18 Jul 07 |
martin |
253 |
{ |
3646 |
09 Aug 07 |
nicklas |
254 |
write("--Create job for PackedFileExporter FAILED"); |
3568 |
18 Jul 07 |
martin |
255 |
ex.printStackTrace(); |
3568 |
18 Jul 07 |
martin |
256 |
ok = false; |
3568 |
18 Jul 07 |
martin |
257 |
} |
3568 |
18 Jul 07 |
martin |
258 |
finally |
3568 |
18 Jul 07 |
martin |
259 |
{ |
3568 |
18 Jul 07 |
martin |
260 |
if (dc != null) dc.close(); |
3568 |
18 Jul 07 |
martin |
261 |
} |
3568 |
18 Jul 07 |
martin |
262 |
|
3568 |
18 Jul 07 |
martin |
263 |
return id; |
3568 |
18 Jul 07 |
martin |
264 |
} |
3568 |
18 Jul 07 |
martin |
265 |
|
3568 |
18 Jul 07 |
martin |
266 |
static void write(String message) |
3568 |
18 Jul 07 |
martin |
267 |
{ |
3568 |
18 Jul 07 |
martin |
268 |
System.out.println(message); |
3568 |
18 Jul 07 |
martin |
269 |
} |
3568 |
18 Jul 07 |
martin |
270 |
|
3568 |
18 Jul 07 |
martin |
271 |
static void write_request_information(RequestInformation ri) |
3568 |
18 Jul 07 |
martin |
272 |
{ |
3568 |
18 Jul 07 |
martin |
273 |
if (TestUtil.getSilent()) return; |
3568 |
18 Jul 07 |
martin |
274 |
|
3568 |
18 Jul 07 |
martin |
275 |
write("Request information for command: "+ri.getCommand()); |
3568 |
18 Jul 07 |
martin |
276 |
write("\tTitle:\t"+ri.getTitle()); |
3568 |
18 Jul 07 |
martin |
277 |
write("\tDescription:\t"+ri.getDescription()); |
3568 |
18 Jul 07 |
martin |
278 |
for (PluginParameter<?> pp : ri.getParameters()) |
3568 |
18 Jul 07 |
martin |
279 |
{ |
6875 |
20 Apr 15 |
nicklas |
280 |
ParameterType<?> pt = pp.getParameterType(); |
3568 |
18 Jul 07 |
martin |
281 |
System.out.println("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
3568 |
18 Jul 07 |
martin |
282 |
} |
3568 |
18 Jul 07 |
martin |
283 |
} |
3568 |
18 Jul 07 |
martin |
284 |
|
3568 |
18 Jul 07 |
martin |
285 |
/** |
3568 |
18 Jul 07 |
martin |
Test to read a zip file located in BASE's file system |
3568 |
18 Jul 07 |
martin |
The content of the zip file is listed if not silent. |
3616 |
01 Aug 07 |
nicklas |
@param zipPath The path to the zip-file that should read |
3568 |
18 Jul 07 |
martin |
289 |
*/ |
3568 |
18 Jul 07 |
martin |
290 |
static void test_read_zip(Path zipPath) |
3568 |
18 Jul 07 |
martin |
291 |
{ |
3568 |
18 Jul 07 |
martin |
292 |
if (!TestUtil.hasPermission(Permission.READ, Item.FILE)) return; |
3568 |
18 Jul 07 |
martin |
293 |
DbControl dc = null; |
3568 |
18 Jul 07 |
martin |
294 |
ZipEntry entry = null; |
3568 |
18 Jul 07 |
martin |
295 |
try |
3568 |
18 Jul 07 |
martin |
296 |
{ |
3568 |
18 Jul 07 |
martin |
297 |
dc = TestUtil.getDbControl(); |
3568 |
18 Jul 07 |
martin |
298 |
File zipFile = File.getByPath(dc, zipPath, false); |
3568 |
18 Jul 07 |
martin |
299 |
ZipInputStream zios = new ZipInputStream(zipFile.getDownloadStream(0)); |
3646 |
09 Aug 07 |
nicklas |
300 |
if (!TestUtil.getSilent()) write ("--Contents in: " + zipFile.getName()); |
3568 |
18 Jul 07 |
martin |
301 |
while ((entry = zios.getNextEntry()) != null) |
3568 |
18 Jul 07 |
martin |
302 |
{ |
3568 |
18 Jul 07 |
martin |
303 |
if (!TestUtil.getSilent()) |
3568 |
18 Jul 07 |
martin |
304 |
{ |
3568 |
18 Jul 07 |
martin |
305 |
write("--Entry in zipfile: " + entry.getName()); |
3568 |
18 Jul 07 |
martin |
306 |
} |
3568 |
18 Jul 07 |
martin |
307 |
} |
3646 |
09 Aug 07 |
nicklas |
308 |
write ("--Read zip-file OK: " + zipPath.toString()); |
3568 |
18 Jul 07 |
martin |
309 |
} |
3646 |
09 Aug 07 |
nicklas |
310 |
catch (Throwable t) |
3568 |
18 Jul 07 |
martin |
311 |
{ |
3646 |
09 Aug 07 |
nicklas |
312 |
write ("--Read zip-file FAILED: " + zipPath.toString()); |
3646 |
09 Aug 07 |
nicklas |
313 |
t.printStackTrace(); |
3568 |
18 Jul 07 |
martin |
314 |
ok = false; |
3568 |
18 Jul 07 |
martin |
315 |
} |
3568 |
18 Jul 07 |
martin |
316 |
finally |
3568 |
18 Jul 07 |
martin |
317 |
{ |
3568 |
18 Jul 07 |
martin |
318 |
if (dc != null) dc.close(); |
3568 |
18 Jul 07 |
martin |
319 |
} |
3568 |
18 Jul 07 |
martin |
320 |
} |
3568 |
18 Jul 07 |
martin |
321 |
|
3568 |
18 Jul 07 |
martin |
322 |
/** |
3646 |
09 Aug 07 |
nicklas |
Test to read a tar-file and write the files to prompt. |
3568 |
18 Jul 07 |
martin |
@param tarPath A Path to the file that should be read. |
3568 |
18 Jul 07 |
martin |
325 |
*/ |
3646 |
09 Aug 07 |
nicklas |
326 |
static void test_read_tar(Path tarPath, boolean isGzip, boolean isBzip) |
3568 |
18 Jul 07 |
martin |
327 |
{ |
3568 |
18 Jul 07 |
martin |
328 |
if (!TestUtil.hasPermission(Permission.READ, Item.FILE)) return; |
3568 |
18 Jul 07 |
martin |
329 |
DbControl dc = null; |
3568 |
18 Jul 07 |
martin |
330 |
TarEntry entry = null; |
3568 |
18 Jul 07 |
martin |
331 |
try |
3568 |
18 Jul 07 |
martin |
332 |
{ |
3568 |
18 Jul 07 |
martin |
333 |
dc = TestUtil.getDbControl(); |
3646 |
09 Aug 07 |
nicklas |
334 |
File tarFile = File.getByPath(dc, tarPath, false); |
3646 |
09 Aug 07 |
nicklas |
335 |
InputStream download = tarFile.getDownloadStream(0); |
3646 |
09 Aug 07 |
nicklas |
336 |
if (isGzip) download = new GZIPInputStream(download); |
3646 |
09 Aug 07 |
nicklas |
337 |
if (isBzip) |
3646 |
09 Aug 07 |
nicklas |
338 |
{ |
3646 |
09 Aug 07 |
nicklas |
339 |
download.read(); // 'B' |
3646 |
09 Aug 07 |
nicklas |
340 |
download.read(); // 'Z' |
3646 |
09 Aug 07 |
nicklas |
341 |
download = new CBZip2InputStream(download); |
3646 |
09 Aug 07 |
nicklas |
342 |
} |
3646 |
09 Aug 07 |
nicklas |
343 |
TarInputStream tos = new TarInputStream(download); |
3646 |
09 Aug 07 |
nicklas |
344 |
if (!TestUtil.getSilent()) write ("--Contents in: " + tarFile.getName()); |
3568 |
18 Jul 07 |
martin |
345 |
while ((entry = tos.getNextEntry()) != null) |
3568 |
18 Jul 07 |
martin |
346 |
{ |
3568 |
18 Jul 07 |
martin |
347 |
if (!TestUtil.getSilent()) |
3568 |
18 Jul 07 |
martin |
348 |
{ |
3568 |
18 Jul 07 |
martin |
349 |
write ("--Entry in tarfile: " + entry.getName()); |
3568 |
18 Jul 07 |
martin |
350 |
} |
3568 |
18 Jul 07 |
martin |
351 |
} |
3568 |
18 Jul 07 |
martin |
352 |
tos.close(); |
3646 |
09 Aug 07 |
nicklas |
353 |
write ("--Read tar-file OK: " + tarPath.toString()); |
3568 |
18 Jul 07 |
martin |
354 |
} |
3646 |
09 Aug 07 |
nicklas |
355 |
catch (Throwable t) |
3568 |
18 Jul 07 |
martin |
356 |
{ |
3646 |
09 Aug 07 |
nicklas |
357 |
write ("--Read tar-file FAILED: " + tarPath.toString()); |
3646 |
09 Aug 07 |
nicklas |
358 |
t.printStackTrace(); |
3568 |
18 Jul 07 |
martin |
359 |
ok = false; |
3568 |
18 Jul 07 |
martin |
360 |
} |
3568 |
18 Jul 07 |
martin |
361 |
finally |
3568 |
18 Jul 07 |
martin |
362 |
{ |
3568 |
18 Jul 07 |
martin |
363 |
if (dc != null) dc.close(); |
3568 |
18 Jul 07 |
martin |
364 |
} |
3646 |
09 Aug 07 |
nicklas |
365 |
} |
3646 |
09 Aug 07 |
nicklas |
366 |
|
3568 |
18 Jul 07 |
martin |
367 |
} |