Project Report: fawkez

Packagesummary org.jcoderz.commons

org.jcoderz.commons.ServerTestCase

LineHitsNoteSource
1  /*
2   * $Id: ServerTestCase.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons;
34   
35  import java.io.File;
36  import java.rmi.RemoteException;
37  import javax.ejb.CreateException;
38  import javax.naming.NamingException;
39   
40   
41  /**
42   * <p>Test cases which subclasses this class will be run inside
43   * an ejb server vm, without transaction. Just implement subclasses
44   * as any other tests.
45   *
46   * @author Michael Griffel
47   */
48  public class ServerTestCase
49        extends TestCase
50  {
51     private static final String DEFAULT_WL_DOMAINDIR = "../";
52     private static final String WL_DOMAINDIR = "wl.domaindir";
53   
54     /**
55      * Returns the path to the web logic domains directory.
56      * @return the path to the web logic domains directory.
57      */
58     public static File getWeblogicDomainDir ()
59     {
60        return new File(System.getProperty(WL_DOMAINDIR, DEFAULT_WL_DOMAINDIR));
61     }
62   
63     /**
64      * Overrides runbare to run this test in the ejb server.
65      *
66      * @throws Throwable if any exception is thrown
67      */
68     public void runBare ()
69           throws Throwable
70     {
71        try
72        {
73           createTestSession().runTest(this.getClass().getName(), getName());
74        }
75        catch (CommonsTestRunnerException e)
76        {
77           throw e.getCause();
78        }
79        catch (java.rmi.RemoteException e)
80        {
81           if (e.detail != null)
82           {
83              throw e.detail;
84           }
85           throw e;
86        }
87     }
88   
89     /**
90      * Runs this test case at the server by calling TestCase's run.
91      *
92      * @throws Throwable if any exception is thrown
93      */
94     public void runBareAtServer ()
95           throws Throwable
96     {
97        super.runBare();
98     }
99   
100 (1)   (1)public static String getTestServletUrl (String path, String optionalParams)
101           throws Exception
102     {
103         /*
104        final String localServer = System.getProperty("weblogic.Name");
105        final Context ctx = new InitialContext();
106        final MBeanHome mbeanHome
107              = (MBeanHome) ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
108        final Set serverConfigSet = mbeanHome.getMBeansByType("ServerConfig");
109        ServerMBean serverConfig = null;
110        for (final Iterator it = serverConfigSet.iterator(); it.hasNext(); )
111        {
112           serverConfig = (ServerMBean) it.next();
113           if (serverConfig.getName().equals(localServer))
114           {
115              break;
116           }
117        }
118        if (serverConfig == null)
119        {
120           throw new Exception("Failed to determine listen port of local server");
121        }
122        final int serverListenPort = serverConfig.getListenPort();
123        final StringBuffer urlStr = new StringBuffer();
124        urlStr.append("http://localhost:").append(serverListenPort);
125        urlStr.append("/fawkez-test").append(path);
126        if (optionalParams != null)
127        {
128           urlStr.append(optionalParams);
129        }
130        return urlStr;
131        */
132         return null;
133     }
134   
135     /**
136      * Returns a connection to the test runner session bean.
137      *
138      * @return a connection to the test runner session bean.
139      *
140      * @throws NamingException when the lookup to the
141      *       CommonsTestRunnerSession bean fails.
142      * @throws CreateException when the creation of the bean fail.s
143      * @throws RemoteException when a remote connection problem occurs.
144      */
145     protected CommonsTestRunnerSessionInterface createTestSession ()
146 (2)         throws NamingException, (2)CreateException, RemoteException
147     {
148        return CommonsTestRunnerSessionJNDIUtil.getHome().create();
149     }
150   
151  }
152   

Findings in this File

f (3) A method/constructor shouldn't explicitly throw java.lang.ExceptionNot required for testcode.
c (1) 100 : 4 Missing a Javadoc comment.
c (2) 146 : 34 Unable to get class information for CreateException.