KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > wsdlimport > SimpleFileImportTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.webservice.wsdlimport;
8
9 // $Id: SimpleFileImportTestCase.java,v 1.1.2.2 2005/06/18 00:26:22 adrian Exp $
10

11 import java.io.File JavaDoc;
12 import java.net.URL JavaDoc;
13
14 import javax.wsdl.Definition;
15 import javax.xml.namespace.QName JavaDoc;
16 import javax.xml.rpc.Service JavaDoc;
17 import javax.xml.rpc.ServiceFactory JavaDoc;
18
19 import junit.framework.TestCase;
20
21 import org.jboss.net.protocol.URLStreamHandlerFactory;
22 import org.jboss.webservice.metadata.wsdl.WSDL11DefinitionFactory;
23
24 /**
25  * Test a wsdl import functionality.
26  *
27  * @author Thomas.Diesler@jboss.org
28  * @since 11-May-2004
29  */

30 public class SimpleFileImportTestCase extends TestCase
31 {
32    public static final String JavaDoc WSDL_LOCATION = "resources/webservice/wsdlimport/simplefile/SimpleFile.wsdl";
33
34    public SimpleFileImportTestCase(String JavaDoc name)
35    {
36       super(name);
37    }
38
39    public void testFileURL() throws Exception JavaDoc
40    {
41       File JavaDoc wsdlFile = new File JavaDoc(WSDL_LOCATION);
42       assertTrue("File does not exist: " + wsdlFile.getCanonicalPath(), wsdlFile.exists());
43
44       // Setting the URLStreamHandlerFactory simulates the behaviour in JBoss
45
internalInitURLHandlers();
46
47       URL JavaDoc wsdlURL = wsdlFile.toURL();
48       Definition wsdlDefinition = WSDL11DefinitionFactory.newInstance().parse(wsdlURL);
49       assertNotNull(wsdlDefinition);
50
51       QName JavaDoc serviceName = (QName JavaDoc)wsdlDefinition.getServices().keySet().iterator().next();
52
53       // test construction of the client service
54
ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
55       Service JavaDoc service = serviceFactory.createService(wsdlURL, serviceName);
56       assertNotNull(service);
57    }
58
59    /**
60     * Set up our only URLStreamHandlerFactory.
61     * This is needed to ensure Sun's version is not used (as it leaves files
62     * locked on Win2K/WinXP platforms.
63     */

64    private void internalInitURLHandlers()
65    {
66       // Install a URLStreamHandlerFactory that uses the TCL
67
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
68
69       // Preload JBoss URL handlers
70
URLStreamHandlerFactory.preload();
71
72       // Include the default JBoss protocol handler package
73
String JavaDoc handlerPkgs = System.getProperty("java.protocol.handler.pkgs");
74       if (handlerPkgs != null)
75       {
76          handlerPkgs += "|org.jboss.net.protocol";
77       }
78       else
79       {
80          handlerPkgs = "org.jboss.net.protocol";
81       }
82       System.setProperty("java.protocol.handler.pkgs", handlerPkgs);
83    }
84 }
85
Popular Tags