KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > ws > JBossWSTestHelper


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.ws;
23
24 import java.io.File JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.URL JavaDoc;
27
28 import javax.management.MBeanServerConnection JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 /**
33  * A JBossWS test helper that deals with test deployment/undeployment, etc.
34  *
35  * @author Thomas.Diesler@jboss.org
36  * @since 14-Oct-2004
37  */

38 public class JBossWSTestHelper
39 {
40    /** Deploy the given archive
41     */

42    public void deploy(String JavaDoc archive) throws Exception JavaDoc
43    {
44       URL JavaDoc url = getArchiveURL(archive);
45       getDeployer().deploy(url);
46    }
47
48    /** Undeploy the given archive
49     */

50    public void undeploy(String JavaDoc archive) throws Exception JavaDoc
51    {
52       URL JavaDoc url = getArchiveURL(archive);
53       getDeployer().undeploy(url);
54    }
55
56    /** True, if -Djbossws.target.server=jboss */
57    public boolean isTargetServerJBoss()
58    {
59       String JavaDoc targetServer = System.getProperty("jbossws.target.server");
60       if( targetServer == null )
61          return ! isTargetServerTomcat();
62       return "jboss".equals(targetServer);
63    }
64
65    /** True, if -Djbossws.target.server=tomcat */
66    public boolean isTargetServerTomcat()
67    {
68       String JavaDoc targetServer = System.getProperty("jbossws.target.server");
69       return "tomcat".equals(targetServer);
70    }
71
72    public MBeanServerConnection JavaDoc getServer() throws NamingException JavaDoc
73    {
74       InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
75       MBeanServerConnection JavaDoc server = (MBeanServerConnection JavaDoc)iniCtx.lookup("jmx/invoker/RMIAdaptor");
76       return server;
77    }
78
79    private JBossWSTestDeployer getDeployer()
80    {
81       return new JBossTestDeployer();
82    }
83
84    /** Try to discover the URL for the deployment archive */
85    public URL JavaDoc getArchiveURL(String JavaDoc archive) throws MalformedURLException JavaDoc
86    {
87       URL JavaDoc url = null;
88       try
89       {
90          url = new URL JavaDoc(archive);
91       }
92       catch (MalformedURLException JavaDoc ignore)
93       {
94          // ignore
95
}
96
97       if (url == null)
98       {
99          File JavaDoc file = new File JavaDoc(archive);
100          if (file.exists())
101             url = file.toURL();
102       }
103
104       if (url == null)
105       {
106          File JavaDoc file = new File JavaDoc("output/lib/" + archive);
107          if (file.exists())
108             url = file.toURL();
109       }
110
111       if (url == null)
112          throw new IllegalArgumentException JavaDoc("Cannot obtain URL for: " + archive+", cwd="+new File JavaDoc(".").getAbsolutePath());
113
114       return url;
115    }
116 }
117
Popular Tags