1
2
3
4
5
6
7
8
9 package it.imolinfo.jbi4ejb.test;
10
11 import it.imolinfo.jbi4ejb.exception.EJBWSDLGenerationException;
12 import it.imolinfo.jbi4ejb.jbi.wsdl.Jbi4EjbExtension;
13 import it.imolinfo.jbi4ejb.webservice.generator.EJBUtils;
14 import it.imolinfo.jbi4ejb.webservice.generator.JarUtil;
15 import it.imolinfo.jbi4ejb.webservice.generator.WSDLGenerator;
16
17 import java.io.File;
18 import java.io.FileInputStream;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.io.StringWriter;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Properties;
27
28 import javax.wsdl.Definition;
29 import javax.wsdl.WSDLException;
30 import javax.wsdl.extensions.ExtensionRegistry;
31 import javax.wsdl.factory.WSDLFactory;
32 import javax.wsdl.xml.WSDLReader;
33 import javax.wsdl.xml.WSDLWriter;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 public class TestUtils {
39
40
41 public static final String WEBSPHERE_6 = "ws6";
42
43
44 public static final String GLASSFISH_v2 = "gl6";
45
46
47 public static final String JBOSS_V4 = "jboss4";
48
49
50 public static final String BEA_V8 = "bea8";
51
52
53 public static final String JACORB = "jacorb";
54
55
56
57
58 private static Log LOG = LogFactory.getLog(TestUtils.class);
59
60
61
62
63
64
65 public static List<String> getJarFilesName(String xFireVersion) {
66 String repodir = System.getProperty("localRepository");
67 LOG.debug("repodir=" + repodir);
68
69 List<String> jarFilesName = new ArrayList<String>();
70
71
72
73 jarFilesName.add(repodir +
74 "/xfire/xfire-jsr181-api/1.0-M1/xfire-jsr181-api-1.0-M1.jar");
75 jarFilesName.add(repodir + "/org/codehaus/xfire/xfire-jaxb2/" +
76 xFireVersion + "/xfire-jaxb2-" + xFireVersion + ".jar");
77 jarFilesName.add(repodir + "/org/codehaus/xfire/xfire-java5/" +
78 xFireVersion + "/xfire-java5-" + xFireVersion + ".jar");
79 jarFilesName.add(repodir + "/org/codehaus/xfire/xfire-core/" +
80 xFireVersion + "/xfire-core-" + xFireVersion + ".jar");
81 jarFilesName.add(repodir + "/org/codehaus/xfire/xfire-aegis/" +
82 xFireVersion + "/xfire-aegis-" + xFireVersion + ".jar");
83 jarFilesName.add(repodir + "/org/codehaus/xfire/xfire-annotations/" +
84 xFireVersion + "/xfire-annotations-" + xFireVersion + ".jar");
85
86
87 String apacheCommonsVersion = "2.1";
88 jarFilesName.add(repodir + "/commons-lang/commons-lang/" +
89 apacheCommonsVersion + "/commons-lang-" + apacheCommonsVersion +
90 ".jar");
91
92
93 jarFilesName.add(repodir + "/javax/xml/jaxb-api/2.0/jaxb-api-2.0.jar");
94
95 return jarFilesName;
96 }
97
98
99 public static Properties getOrbProperties(String asType) {
100
101 Properties props = new Properties();
102
103 if (WEBSPHERE_6.equals(asType)) {
104 LOG.debug("Setting Websphere6 ORB properties");
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 } else if (GLASSFISH_v2.equals(asType)) {
122
123 props.setProperty("org.omg.CORBA.ORBClass", "com.sun.corba.ee.impl.orb.ORBImpl");
124 } else if (JACORB.equals(asType)) {
125 props.setProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
126 props.setProperty("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
127
128
129
130 } else if (JBOSS_V4.endsWith(asType)) {
131 props.setProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
132 props.setProperty("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
133 }
134 return props;
135 }
136
137 public static Properties getJndiProperties(String asType) {
138
139 Properties props = new Properties();
140
141 if (WEBSPHERE_6.equals(asType)) {
142 LOG.debug("Setting Websphere6 JNDI properties");
143
144 props.setProperty("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
145 props.setProperty("java.naming.provider.url", "corbaname:iiop:127.0.0.1:2809/NameServiceServerRoot");
146
147 } else if (GLASSFISH_v2.equals(asType)) {
148
149 props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
150 props.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
151 props.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
152
153
154 }
155 return props;
156 }
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 public static Properties getClassesIdFromJar(String remoteInterfaceName, String ejbJarPath) throws IOException, EJBWSDLGenerationException{
173 File tempDir = File.createTempFile("EJBCLASSES_", null);
174 tempDir.delete();
175 tempDir.mkdir();
176 JarUtil.unjar(new File(ejbJarPath), tempDir);
177 Properties classesId = WSDLGenerator.getClassesID(remoteInterfaceName, tempDir);
178 tempDir.delete();
179 return classesId;
180 }
181
182
183
184
185
186 public static File createTempDir() {
187
188 File tempDir = null;
189 try {
190 tempDir = EJBUtils.createTempDir();
191 } catch (IOException e) {
192
193 LOG.error(e.getMessage());
194 e.printStackTrace();
195 }
196 return tempDir;
197 }
198
199
200
201
202
203 public static File getTestClassesDir() {
204 return new File("." + File.separatorChar +"target" + File.separatorChar + "test-classes");
205 }
206
207
208
209
210
211
212
213
214
215 public static String getWSDLStringFromDefinition(Definition wsdl) throws WSDLException {
216
217 StringWriter strWriter = new StringWriter();
218 getExtendedWSDLWriter().writeWSDL(wsdl, strWriter);
219 return strWriter.toString();
220 }
221
222
223
224
225
226
227
228
229 public static WSDLReader getExtendedWSDLReader() throws WSDLException {
230 WSDLFactory factory = WSDLFactory.newInstance();
231 WSDLReader reader = factory.newWSDLReader();
232 ExtensionRegistry registry = factory.newPopulatedExtensionRegistry();
233 Jbi4EjbExtension.register(registry);
234 reader.setExtensionRegistry(registry);
235 return reader;
236 }
237
238
239
240
241
242
243
244
245 public static WSDLWriter getExtendedWSDLWriter() throws WSDLException {
246 WSDLFactory factory = WSDLFactory.newInstance();
247 WSDLWriter writer = factory.newWSDLWriter();
248 ExtensionRegistry registry = factory.newPopulatedExtensionRegistry();
249 Jbi4EjbExtension.register(registry);
250 return writer;
251 }
252
253
254
255
256
257
258 public static boolean deleteDir(File dir) {
259 if (dir.isDirectory()) {
260 String[] children = dir.list();
261 for (int i=0; i<children.length; i++) {
262 boolean success = deleteDir(new File(dir, children[i]));
263 if (!success) {
264 return false;
265 }
266 }
267 }
268
269 return dir.delete();
270 }
271
272
273
274
275
276
277
278
279
280 public static void copyDirectory(File sourceLocation , File targetLocation)
281 throws IOException {
282
283 if (sourceLocation.isDirectory()) {
284 if (!targetLocation.exists()) {
285 targetLocation.mkdir();
286 }
287
288 String[] children = sourceLocation.list();
289 for (int i=0; i<children.length; i++) {
290 copyDirectory(new File(sourceLocation, children[i]),
291 new File(targetLocation, children[i]));
292 }
293 } else {
294
295 InputStream in = new FileInputStream(sourceLocation);
296 OutputStream out = new FileOutputStream(targetLocation);
297
298
299 byte[] buf = new byte[1024];
300 int len;
301 while ((len = in.read(buf)) > 0) {
302 out.write(buf, 0, len);
303 }
304 in.close();
305 out.close();
306 }
307 }
308
309 }
310