geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r705489 - in /geronimo/gshell/trunk/gshell-support/gshell-spring/src: main/java/org/apache/geronimo/gshell/spring/ test/java/org/apache/geronimo/gshell/spring/
Date Fri, 17 Oct 2008 06:24:54 GMT
Author: jdillon
Date: Thu Oct 16 23:24:54 2008
New Revision: 705489

URL: http://svn.apache.org/viewvc?rev=705489&view=rev
Log:
Adding TestSupport, taken from the server tree

Added:
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
  (contents, props changed)
      - copied, changed from r705178, geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
Modified:
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java

Modified: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java?rev=705489&r1=705488&r2=705489&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
Thu Oct 16 23:24:54 2008
@@ -136,6 +136,12 @@
         return new BeanContainerImpl(childRealm, this);
     }
 
+    public BeanContainer createChild(final String id) {
+        assert id != null;
+
+        return createChild(id, null);
+    }
+    
     public <T> T getBean(final Class<T> type) {
         assert type != null;
 
@@ -186,12 +192,6 @@
         return getContext().getBeanNamesForType(type);
     }
 
-    public BeanContainer createChild(final String id) {
-        assert id != null;
-
-        return createChild(id, null);
-    }
-
     private static ClassRealm createClassRealm(final ClassLoader cl) {
         assert cl != null;
 

Modified: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java?rev=705489&r1=705488&r2=705489&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
Thu Oct 16 23:24:54 2008
@@ -19,20 +19,14 @@
 
 package org.apache.geronimo.gshell.spring;
 
-import junit.framework.TestCase;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
- * Suport for Spring-based tests.
+ * Support for Spring-based tests.
  *
  * @version $Rev$ $Date$
  */
 public abstract class SpringTestSupport
-    extends TestCase
+    extends TestSupport
 {
-    protected final Logger log = LoggerFactory.getLogger(getClass());
-
     private BeanContainerImpl container;
 
     protected void setUp() throws Exception {

Copied: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
(from r705178, geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java?p2=geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java&p1=geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java&r1=705178&r2=705489&rev=705489&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
Thu Oct 16 23:24:54 2008
@@ -23,57 +23,127 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
+
 /**
- * Suport for Spring-based tests.
+ * Support for tests.
  *
  * @version $Rev$ $Date$
  */
-public abstract class SpringTestSupport
+public abstract class TestSupport
     extends TestCase
 {
+    /**
+     * The base-directory which tests should be run from.
+     *
+     * @see #getBaseDir()   This field is initialized from the return of this method on instance
construction.
+     */
+    protected final File BASEDIR = getBaseDir();
+
+    //
+    // NOTE: Logging must be initialized after BASEDIR has been discovered, as it is used
+    //       by the log4j logging-config properties to set the target/test.log file.
+    //
+
+    /**
+     * Instance logger which tests should use to produce tracing information.
+     *
+     * <p>
+     * Unless you have a really good reason to, do not change this field from your sub-class.
+     * And if you do, please document why you have done so.
+     */
     protected final Logger log = LoggerFactory.getLogger(getClass());
 
-    private BeanContainerImpl container;
+    /**
+     * Constructor for tests that specify a specific test name.
+     *
+     * @see #TestSupport()  This is the prefered constructor for sub-classes to use.
+     */
+    protected TestSupport(final String name) {
+        super(name);
+
+        log.info("Initialized");
+    }
+
+    /**
+     * Default constructor.
+     */
+    protected TestSupport() {
+        super();
+
+        log.info("Initialized");
+    }
+
+    /**
+     * Determine the value of <tt>${basedir}</tt>, which should be the base directory
of
+     * the module which the concreate test class is defined in.
+     *
+     * <p>
+     * If The system property <tt>basedir</tt> is already set, then that value
is used,
+     * otherwise we determine the value from the codesource of the containing concrete class
+     * and set the <tt>basedir</tt> system property to that value.
+     *
+     * @see #BASEDIR    This field is always initialized to the value which this method returns.
+     *
+     * @return  The base directory of the module which contains the concreate test class.
+     */
+    protected final File getBaseDir() {
+        File dir;
+
+        // If ${basedir} is set, then honor it
+        String tmp = System.getProperty("basedir");
+        if (tmp != null) {
+            dir = new File(tmp);
+        }
+        else {
+            // Find the directory which this class (or really the sub-class of TestSupport)
is defined in.
+            String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
 
-    protected void setUp() throws Exception {
-        container = new BeanContainerImpl(getClass().getClassLoader());
-        configure(container);
-    }
-    
-    protected void tearDown() throws Exception {
-        container = null;
-    }
+            // We expect the file to be in target/test-classes, so go up 2 dirs
+            dir = new File(path).getParentFile().getParentFile();
 
-    protected void configure(final BeanContainerImpl container) throws Exception {
-        container.loadBeans(getConfigLocations());
-    }
+            // Set ${basedir} which is needed by logging to initialize
+            System.setProperty("basedir", dir.getPath());
+        }
 
-    protected String getDefaultConfigLocation() {
-        return "classpath:" + getClass().getName().replace('.', '/') + "-context.xml";
-    }
+        // System.err.println("Base Directory: " + dir);
 
-    protected String getDefaultComponentsConfigLocation() {
-        return "classpath*:META-INF/spring/components.xml";
-    }
-    
-    protected String[] getConfigLocations() {
-        return new String[] {
-            getDefaultConfigLocation()
-        };
+        return dir;
     }
 
-    protected BeanContainerImpl getBeanContainer() {
-        if (container == null) {
-            throw new IllegalStateException();
+    /**
+     * Resolve the given path to a file rooted to {@link #BASEDIR}.
+     *
+     * @param path  The path to resolve.
+     * @return      The resolved file for the given path.
+     */
+    protected final File resolveFile(final String path) {
+        assert path != null;
+
+        File file = new File(path);
+
+        // Complain if the file is already absolute... probably an error
+        if (file.isAbsolute()) {
+            log.warn("Given path is already absolute; nothing to resolve: {}", file);
+        }
+        else {
+            file = new File(BASEDIR, path);
         }
-        return container;
-    }
 
-    protected <T> T getBean(final Class<T> type) {
-        return getBeanContainer().getBean(type);
+        return file;
     }
 
-    protected <T> T getBean(final String name, final Class<T> requiredType) {
-        return getBeanContainer().getBean(name, requiredType);    
+    /**
+     * Resolve the given path to a path rooted to {@link #BASEDIR}.
+     *
+     * @param path  The path to resolve.
+     * @return      The resolved path for the given path.
+     *
+     * @see #resolveFile(String)
+     */
+    protected final String resolvePath(final String path) {
+        assert path != null;
+
+        return resolveFile(path).getPath();
     }
 }
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/TestSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message